Hi,
I used to display values (temperature) from a specific sensor. Now I bought a new sensor.
What I would like to achieve is that my Flux query returns the value from the old sensor before June 1, 2023 and the value from the second sensor from June 1, 2023 onwards.
The query for the first sensor looked like this:
from(bucket: "rtl_433")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "Nexus-T")
|> filter(fn: (r) => r["_field"] == "temperature_C")
|> filter(fn: (r) => r["channel"] == "2")
|> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
|> yield(name: "mean")
The new query for the new sensor looks like this:
from(bucket: "rtl_433")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "LaCrosse-TX141THBv2")
|> filter(fn: (r) => r["_field"] == "temperature_C")
|> filter(fn: (r) => r["channel"] == "1")
|> filter(fn: (r) => r["id"] == "203")
|> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
|> yield(name: "mean")
How can I combine these two queries to return values from the first sensor when v.timeRangeStop is < June 1, 2023 and from the second sensor when v.timeRangeStop is >= June 1, 2023?
Any help is appreciated.
Hi,
keep first query as t1 and second query as t2 and join these two queries
join(tables: {t1: t1, t2: t2}, on: [“_tag”,“temperature_C”])
Could you please provide more code? I don’t really get how this one line would help me.
Moreover, I don’t think, it will work. Both sensors are now running in parallel thus the join will have values for June 2023 onwards from both sensors which is not want I want for my display query.
Hi,
Please find the query below
t1=from(bucket: “rtl_433”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r[“_measurement”] == “Nexus-T”)
|> filter(fn: (r) => r[“_field”] == “temperature_C”)
|> filter(fn: (r) => r[“channel”] == “2”)
|> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
|> yield(name: “mean”)
t2=from(bucket: “rtl_433”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r[“_measurement”] == “LaCrosse-TX141THBv2”)
|> filter(fn: (r) => r[“_field”] == “temperature_C”)
|> filter(fn: (r) => r[“channel”] == “1”)
|> filter(fn: (r) => r[“id”] == “203”)
|> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
|> yield(name: “mean”)
join(tables: {t1: t1, t2: t2}, on: [“_tag”,“temperature_C”])
Thanks a lot. I will give it a try by limiting the v.timeRangeStart/Stop values according to my needs.
Produced “No results”. And I had to remove the yield() statements before.