Edit: I found the solution by modifying a subquery from another thread:
SELECT SUM("power"::float)/60.0/1000.00
FROM (
SELECT mean("value") AS power FROM "infinite"."watts_minute" WHERE ("topic" = '/emon/reading/c3c0/power_active') AND $timeFilter GROUP BY time(1m) fill(none)
)
This is assuming 1 minute watt data. Pretty easy to modify the query by adding the cost per kWh to get energy cost too, let’s say $0.12 per kWh:
SELECT SUM("power"::float)/60.0/1000.00*0.12
FROM (
SELECT mean("value") AS power FROM "infinite"."watts_minute" WHERE ("topic" = '/emon/reading/c3c0/power_active') AND $timeFilter GROUP BY time(1m) fill(none)
)
----------- original question ------------------
I have a query that finds the mean of a time series that’s queried from influx. This is the query:
SELECT mean("value") FROM "infinite"."watts_minute" WHERE ("topic" = '/emon/reading/c3c0/power_active') AND $timeFilter GROUP BY time($__interval) fill(none)
The data is power (watts) that I get every minute, and I want to calculate the energy (kWh) for the power being displayed in the current chart. Basically, take average power, and multiply the number of hours being displayed.
How do I construct a new query that would multiply this mean value by the number of hours in the current time range, and divide by 1000 to get kWh?.
I thought I’d use something like ($_interval) somehow, but couldn’t figure it out. Maybe something like this subquery?
SELECT ("power")*(number of hours in chart)/1000
FROM (
SELECT mean("value") AS power FROM "infinite"."watts_minute" WHERE ("topic" = '/emon/reading/c3c0/power_active') AND $timeFilter GROUP BY time($__interval) fill(none)
)