Hi,
I have a live power reading which is coming in every so many seconds in Kw. Is there a way to calculate the total usage over a day? Not sure if SUM() would just add up all the data points ?
would the best way to be maybe limit the amount of data points to 60 seconds and then divide the SUM () by 86400 (24hrs) or os there already a way of doing such sum in influx?
Thanks
Sy
Hello @bceyresy,
Welcome!
I suggest using the aggregate window function:
from(bucket: "my bucket")
|> range(start: -10d)
|> filter(fn: (r) => r["_measurement"] == "my measurement")
|> filter(fn: (r) => r["_field"] == "kWh")
|> aggregateWindow(every: 1d, fn: sum, createEmpty: false)
|> yield(name: "daily sum or total")
Are you familiar with SQL perchance?
The following might be helpful if so:
The best way to do this is to integrate your power data into hourly energy data (or 15-minute intervals if your utility gives you a report in that format) as a task, and put that into a separate bucket. I keep two tasks, one that runs every hour and one that is done every week in case information came in late-- the integral is the same, just the window covered:
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")
Hi
Sorry about the thread necro.
@Patrick808 how would I “run” this and create a new “measurement” on my historical data before I start the task for the new data?
Thanks.
Hi,
a good way is to script something around the FLUX command, you mostly need to change the range to travel in your historical data. You can easily do that with a client or in bash using the API.