Still learning Flux, so bear with me…
This is my query to display the Setpoint & Actual.
from(bucket: "bucket")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "measurement")
|> filter(fn: (r) => r["_field"] == "actualValue" or r["_field"] == "setpointValue")
|> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
|> yield(name: "mean")
The above is great, but what I would like to know now is if the absolute value of (setpointValue - actualValue) >= 7, and make it flexible by using a variable (instead of hard coding the ‘7’) defined at the start of the query.
For example (and this is totally wrong, but hopefully makes sense), to compare the absolute value of the difference between the Setpoint & Actual against a value of 7, how about something like this?
LIMIT = 7
if math.abs(setpointValue - actualValue) >= LIMIT then "true", else "false"
Once I work out syntax for the above conditional statement, do I just add the lines to my first query? Could it return “true” or “false” in a state timeline graph?