If the value is below a reference value for more than x hours, then do something "fail-safe"

if the value is below a reference value for more than x hours, then do something.
Hello
I have a question to the forum how you would approach it.
I have the measured value, which comes from mqtt, written into a flow.set and compare this every few seconds with the latest value, if this is below my threshold I aktualisate my flow.set and write a second flow.set the time. Then I compare the time with now and check if 2 hours have passed. If yes an action is triggered, if no then everything starts again from the beginning with the next measured value of mqtt.
But now I have set myself a trap, by restarting the PI or update IObroker..... .
How would you proceed. Write these values every time in a DB and write every 10 seconds a new value. Write the data in a file on the PI or is there another variant to make the measurements "fail-safe"?

I think this could all be done using a Trigger node. Think of the problem the other way round, feed only values above the threshold to the Trigger, set to send nothing then wait x hours, then send the error. With Extend selected it will restart the timer every time a good value is seen.

If you need it to survive a restart then use the persistent storage feature which retains context variables over a restart. Every time you get a good value update a persistent flow value with the current time. When you get a bad value check the time against that flow variable and if greater than two hours trigger the error.

Ahh!! THX
persistent storage feature
that's something new for me, I'll have to ask aunt google for more information.
I haven't worked with it yet. This seems to be exactly what I am looking for

1 Like