One comment for energy, it seems to work best if you create a separate bucket for kWh values via a task. I run one every hour, and then have a second task that is similar to re-do the integration weekly in case the system is offline for one interval. I’ve also had to manually re-integrate windows occassionally with a task; it doesn’t add data since it is the same timestamp and value.
option task = {name: "IotaIntegral-Hourly", cron: "0 * * * *", offset: 1m}
data = from(bucket: "Iotabucket2")
|> range(start: -1h)
|> filter(fn: (r) =>
(r["_field"] == "Watts"))
|> aggregateWindow(every: 1h, fn: (tables=<-, column) =>
(tables
|> integral(unit: 1h)
|> map(fn: (r) =>
({r with _value: r._value / 1000.0, _field: "kWh", units: "kWh"}))))
data
|> to(bucket: "IotaHourly")