Skip to content

Instantly share code, notes, and snippets.

@wujku
Last active November 1, 2022 18:24
Show Gist options
  • Save wujku/50caef4bcf8b8024243690d4b1204fb5 to your computer and use it in GitHub Desktop.
Save wujku/50caef4bcf8b8024243690d4b1204fb5 to your computer and use it in GitHub Desktop.
InfluxDB – Power consumption
from(bucket: "home_assistant")
|> range(start: -30d)
|> filter(fn: (r) => r._measurement == "imp" and r._field == "value")
|> aggregateWindow(every: 1d, fn: spread, createEmpty: false)
|> map(fn: (r) => ({r with _value: r._value / 1000.0 }))
|> yield(name: "daily total")
from(bucket: "home_assistant")
|> range(start: -60d)
|> filter(fn: (r) => r._measurement == "imp" and r._field == "value")
|> aggregateWindow(every: 1w, fn: spread, createEmpty: false)
|> map(fn: (r) => ({r with _value: r._value / 1000.0 }))
|> yield(name: "weekly total")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment