Get monthly power use and cost (Flux)
These Flux queries can be used to extract total monthly power usage (in kWh) and cost from the data written into InfluxDB by my electricity usage monitoring setup.
The owl intuition power meter reports total usage "today", so the the maximum daily value needs to be selected and then summed to get the monthly usage.
Details
- Language: Flux
Snippet
// Cost
from(bucket: "Systemstats/rp_720d")
|> range(start: -180d)
|> filter(fn: (r) => r._measurement == "power_watts")
|> filter(fn: (r) => r._field == "today_cost")
|> filter(fn: (r) => r.host == "power-meter")
|> aggregateWindow(every: 1d, fn: max)
|> aggregateWindow(every: 1mo, fn: sum)
|> map(fn: (r) => ({r with _value: r._value / 100.00}))
// Usage
from(bucket: "Systemstats/rp_720d")
|> range(start: -180d)
|> filter(fn: (r) => r._measurement == "power_watts")
|> filter(fn: (r) => r._field == "watts_today")
|> filter(fn: (r) => r.host == "power-meter")
|> aggregateWindow(every: 1d, fn: max)
|> aggregateWindow(every: 1mo, fn: sum)
|> map(fn: (r) => ({r with _value: r._value / 1000.00}))