Energy Production total per day


Iam very new to influxdb with flux lang so i have trouble to get the right syntax and hope somebody can help.

So, what i want to do is to calculate the total energy production over a day from my PV, the start of producing energy is in the morning (see attached raw data) after sunrise and end at sunset.
(starts with a 0 value (no sun) and grows up over the day, and than in the afternoon it goes down to zero at sunset), and at the end i will build it up in a bar chart for a month so that i can see what i have produced per day over a month

the problem is that the data stored in the database at every change is the total produced at this moment, so i cannot sum up all values. (see raw data)

I think what i need is to calculate the difference over the day or cumulative sum (i don’t know)

so here are the raw data from a simple query

from(bucket: “openHAB”)

|> range(start: v.timeRangeStart, stop: v.timeRangeStop)

|> filter(fn: (r) => r["_measurement"] == “SenecEnergyProduction”)

|> filter(fn: (r) => r["_field"] == “value”)

|> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)

|> yield(name: “mean”)

and the raw data output

i hope you understand what i want to do, and somebody can helb me


I’m not very expert, but maybe you are tring to do some similar to me.

Probably do you miss the difference() section? See my other post, you will find the task.

I hope I can give you also a small help :wink:

i have reorganized my data collection to make it easierer to query and with this query i get the result that i want:

import “date”

today = date.truncate(t: now(), unit: 1d)

from(bucket: “openHAB”)
|> range(start: -14d)
|> filter(fn: (r) => r["_measurement"] == “SenecLivePowerGenerator”)
|> filter(fn: (r) => r["_field"] == “value”)
|> toFloat()
|> aggregateWindow(every: 1d, fn: spread, createEmpty: true)