Grafana and kWh per day aggregation

I’m trying to figure out how to convert my power meter data into a bar graph that shows the total kWh consumed per day, and I’m struggling how to structure the Grafana InfluxDB query which contains entries in a varying frequency (depending on how often the power value changed) for each day. I can get a mean() and group by time(1d), but that just gives me the mean - multiplying that by 24 does not give me a correct kWh number.

Suggestions?

If it’s a utility meter with a daily cycle use the max() aggregator/selector and group by 1d.

Unfortunately it’s not, but after a bunch of googling, I found this (for future reference):

SELECT SUM(“power”::float) / 60.0 / 1000.0
FROM (
SELECT mean(“value”) AS power FROM “W” WHERE (“entity_id” = ‘power_car_charger’) AND $timeFilter GROUP BY time(1m) fill(previous)
)
GROUP BY time(24h) tz(‘America/New_York’)

Which seems to work great!

Hi
I used something similar with your code above, and lately it doesn’t work (no data). I am not sure if this is something wrong I have done or something changed in a Grafana update. So, the above still works for you?
Thanks

Yup, still works here and I’m on the latest version of Grafana.

1 Like