How to stop a timer?

Trying to setup a notification if my front door is still unlocked after 10 minutes. I have a flow working to notify me but the only thing is the timer starts and counts down and sends the notify even if the door was locked in the time period. How can I reset or stop the timer from sending the message?

Use a “wait until” node, you wait for a set time or until the door is locked.

Sorry but can not seem to wrap my head around the “wait until” node. I must be looking at it all wrong.
This is what I setup for a test. If i inject “unlocked” the wait starts and then times out after 10 seconds and the msg.payload of “unlocked” on the debug. But if I inject “locked” during the wait or at any time it will count down the wait time and the msg.payload of “locked” on the debug.

image

image

image

Whatever you inject will start the node’s countdown (and goes in the message payload). The timer will countdown until the state of the entity changes. As you have it there it would timeout in 10 seconds if the entity state does not change to unlocked in that time. After which the message (with whatever payload you injected) pops out at the debug.

You’re looking for something like this -

My lock is a binary sensor - Off means locked, On is unlocked.

1 Like

I have a similar setup, a chime goes off when the door is open and resets when the door is closed, I’m using a combination of change node and loop timer. You can modify this to send an alert if kept open for 10 minutes.

[{"id":"cfa51f96.890ba","type":"change","z":"fc32e4e1.e1bf78","name":"From off to stop","rules":[{"t":"change","p":"payload","pt":"msg","from":"off","fromt":"str","to":"stop","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":80,"wires":[["fa1c38cc.8f4ef8","5509587a.aa3498","46928192.f64ce"]]},{"id":"7e6091b5.e3a35","type":"server-state-changed","z":"fc32e4e1.e1bf78","name":"Front Door Alert","server":"f0aa0465.fa7ce8","entityidfilter":"binary_sensor.front_door","entityidfiltertype":"substring","haltifstate":"","outputs":1,"x":120,"y":80,"wires":[["cfa51f96.890ba"]],"outputLabels":["stop"]},{"id":"fa1c38cc.8f4ef8","type":"looptimer","z":"fc32e4e1.e1bf78","duration":"30","units":"Second","maxloops":"100","maxtimeout":"30","maxtimeoutunits":"Minute","name":"Open loop","x":530,"y":80,"wires":[["fe0764ac.278dd8"],[]]},{"id":"5509587a.aa3498","type":"ui_button","z":"fc32e4e1.e1bf78","name":"","group":"c23cd849.951928","order":2,"width":0,"height":0,"passthru":false,"label":"Puerta principal","color":"","bgcolor":"{{msg.background}}","icon":"","payload":"stop","payloadType":"str","topic":"","x":540,"y":140,"wires":[["fa1c38cc.8f4ef8"]]},{"id":"46928192.f64ce","type":"function","z":"fc32e4e1.e1bf78","name":"Color Mapping","func":"switch (msg.payload) {\n\ncase \"on\" : \n msg.background = \"red\";\n break;\n \ndefault : \n msg.background = \" \";\n break;\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":320,"y":140,"wires":[["5509587a.aa3498"]]},{"id":"f0aa0465.fa7ce8","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open"},{"id":"c23cd849.951928","type":"ui_group","z":"","name":"Doors","tab":"c5e67c2b.eb40e","order":3,"disp":false,"width":"6","collapse":false},{"id":"c5e67c2b.eb40e","type":"ui_tab","z":"","name":"Dashboard","icon":"dashboard","order":2}]

Install the Stop Timer module (node-red-contrib-stoptimer).

You use it just like a timer, but you can also add in input that just says STOP to stop it. For the stop command, I use a change node with two steps:

  • Delete msg.payload
  • Set msg.payload to STOP

Then, if you detect the door is locked, the output goes to this change node and then into the Stop Timer, along with the initial flow. Hope that makes sense.

3 Likes

I have setup like yours but just have inject nodes for testing. I get the message “unlock” on the second output but if I inject “locked” I still get the “locked” message passing through to the second output also. Can’t be this hard. lol

image

image

[{"id":"edc886da.739848","type":"server-state-changed","z":"ffbd7f06.4a014","name":"front door","server":"2dad33ee.42bf5c","entityidfilter":"sensor.door","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"locked","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":188,"y":480,"wires":[["caa85de5.b4ee9"],["7505c1a6.e3e9"]]},{"id":"caa85de5.b4ee9","type":"trigger","z":"ffbd7f06.4a014","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"10","extend":true,"units":"min","reset":"","bytopic":"all","name":"","x":390,"y":480,"wires":[["4c14cc18.2f50e4"]]},{"id":"7505c1a6.e3e9","type":"change","z":"ffbd7f06.4a014","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":528,"wires":[["caa85de5.b4ee9"]]},{"id":"4c14cc18.2f50e4","type":"debug","z":"ffbd7f06.4a014","name":"Send Message","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":624,"y":480,"wires":[]}]
1 Like

Thanks guys. I did get it working with the “wait node”. The problem was that the “wait node” was still seeing the state of the door when I was injecting in the “locked” or “unlocked”. If that make sense.

@Kermit I really like your suggestion. Guess there’s so many ways to do a flow.

The wait until node is not waiting for a message, it’s checking the actual status of the entity in HA. So no amount of injecting is going to reset it. If you need the message changing for later in your flow, you may want to use one of the other messages. But if you just need to control the logic it’s very simple.

All the other methods will work as well, so really you’re spoiled for choice.

1 Like

Thanks. I walked away for a bit and that’s when it hit me that the “wait until” node was checking the state.

So much to learn about Node Red.

its powerful, with power comes complexity. stick with it, it’s worth it.

As I said, all the other methods will work, so go with what you’re comfortable with.