Best option for a STATE STAYS function?

I’m wondering what the general best practice is out there for Node-Red for doing something only when a state stays a certain way for a while. I could check the state, set a timer, cancel the timer if it changes before the timer elapses, and so forth - but that sounds unnecessarily involved.

Other platforms I’ve used have had a trigger, or whatever, that only happened when a state had been a certain way for longer than a set time.

I use this for locking a door only after it’s closed and stayed closed for more than 5 minutes. Or shutting a light off after a motion detector is off and stayed off for 10 minutes. And so forth.

Ideas?

You’ve answered your own question, the Trigger node does it :grinning:

This one does nothing when the 1st message comes in (except start the timer), if there’s movement the motion detector will send “On” and cancel the timer. If that doesn’t happen in 10 minutes the message goes to the nodes to turn off the devices.

There’s also a Wait Until node which can do a similar thing.

Thanks. I’m actually using the wait-until node now, but have some edge cases it seems to not quite fit. I’ll play with Trigger a little and see if I can make it suit. I appreciate the tip!

I’m curious why you’d prefer to use Trigger instead of Stoptimer. They seem so similar, at least in my cases. I kick off a timer, and watch for state changes. If they change away I cancel the timer, and if not I let it run out.

Maybe I’m too fixated on an imaginary benefit of using fewer nodes, leading me to look for something that duplicates functionality I’ve used elsewhere.

Trigger is “built-in” whereas stoptimer isn’t. I imagine I worked it out with the nodes I had before I went looking for more to install.

1 Like