Hi,
I have a series of temp measurements and would like get 1 average value from a time period like a week. I tried to create a query but don’t manage to get only 1 value as a result.
Could you help me?
Hi,
I have a series of temp measurements and would like get 1 average value from a time period like a week. I tried to create a query but don’t manage to get only 1 value as a result.
Could you help me?
Hi @stony
Can you post your query here?
Hi grant,
I’ve no clue, but this query is giving me all recorded values as a result:
from(bucket: "iobroker")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "hm-rpc.1.BME280THP1.1.TEMPERATURE")
|> filter(fn: (r) => r["_field"] == "value")
|> aggregateWindow(every: v.windowPeriod, fn: median, createEmpty: false)
|> yield(name: "median")
|> group(columns: ["host", "_measurement"], mode:"by")
I’ve read the docs but I am very new to the Flux query language. I think maybe the function reduce can do the trick. But I need help how to use this function and reduce the given results to 1 average value.
Maybe try this?
from(bucket: "iobroker")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "hm-rpc.1.BME280THP1.1.TEMPERATURE")
|> filter(fn: (r) => r["_field"] == "value")
|> group(columns: ["host", "_measurement"], mode:"by")
|> mean()
|> yield(name: "single_avg")
Wow so simple, that did the trick. I never figured this out by myself, thank you!
Awesome! I am still learning myself, so glad I could help you out.