Works like a charm
Is this even possible with standard queries?
This is a good starting point to learn a little bit more about Flux language.
Thanks in any way for you support!
OK to help others here comes the Flux-Expression in all its beautiy
from(bucket: "my_bucket")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "energie2")
|> filter(fn: (r) => r["_field"] == "value")
|> filter(fn: (r) => r["category"] == "Energie")
|> filter(fn: (r) => r["name"] == "Verbrauchszähler")
|> elapsed(unit: 1s)
|> map(fn: (r) => ({ r with elapsed: float(v: r.elapsed)}))
|> map(fn: (r) => ({ r with power_Ws: r._value * r.elapsed }))
|> map(fn: (r) => ({ r with power_kWh: r.power_Ws / 3600.0}))
|> aggregateWindow(every: 1d, fn: sum, column: "power_kWh")
|> drop(columns: ["_start", "_stop","category", "name", "room", "state", "type", "_field", "_measurement"])
Two things to mention:
- For unknown reason I had to remove the division by 1000 to get values in expected range.
- I still have to do a double check by hand to see whether it works really as expected.
e.g.: The elapse() function stores the values in a certain row. Question of double check is now wheter I use then really the correct values or if there is a missmatch of one line. This would result in multipling the wrong time duration with the power level… Since power usually behaves in a continuous way this should not be a great error …
In any case: Many thanks for you support. I hope this helps others.