Get monthly power use and cost



Published: 2022-01-31 09:10:47 +0000
Categories: Flux,

Language

Flux

Description

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.

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}))

Keywords

flux, power usage, influxdb, query,

Latest Posts


Copyright © 2022 Ben Tasker | Sitemap | Privacy Policy
Available at snippets.bentasker.co.uk and http://phecoopwm6x7azx26ctuqcp6673bbqkrqfeoiz2wwk36sady5tqbdpqd.onion