#Create a sensor from an influxdb energy script

1 messages · Page 1 of 1 (latest)

fringe vault
#

I have a script in my influxdb that I just made. I'd need this to become a sensor inside HA so I can use it in my ApexCharts. It's keeping track of energy usage per hour. I can't really wrap my head around how to make this into a sensor for the configuration file. All the examples online of creating a sensor look nothing like this, and I'm really horrible at changing this into something more legible.

from(bucket: "homeassistant/autogen")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "kWh")
|> filter(fn: (r) => r["_field"] == "value")
|> filter(fn: (r) => r["entity_id"] == "energy_per_hour")
|> filter(fn: (r) => r["domain"] == "sensor")
|> aggregateWindow(every: v.windowPeriod, fn: last, createEmpty: false)
|> yield(name: "last")

#

I understand I can just use Grafana for this, but I need these to be in cards

low seal
#

to create a sensor in HA, you need to set up a custom sensor in the config.yaml file.

fringe vault
#

this is what I have, but it did nothing