How to time a door open and stop timer when door closed?

Hello,

I’m quit new over here and busy migrating from a Homey.
I did get the basic started and did write some que’s (much more efficient then Homey :slight_smile:)

Now I try to figure out when a door is open for 5 minutes say “door open” at TTS
When within the 5 minutes the door is closed the timer stops and reset until next time opening.
I do have TTS already up and running.
So I’m only looking for the smart timer part.

Any Idea how to make in node-RED?

From the top of my head, I think you’ll need to use something like global state variable to the time the door was open.
Have an inject node that is running every say 1min, effectively subtracting (using a function node) current time from the global state variable you set earlier and trigger the service when that reaches 5.

I’ve done similar, the key node in my attempt is a ‘wait until’. The 1st one (called initial timer) is triggered when the door is unlocked, and waits for 5 minutes, unless the door is locked again.

Then it sends a notification, and goes to a second timer which waits for 15 minutes before repeating the notification.

[{"id":"c4da78f2.382a58","type":"server-state-changed","z":"9c580098.19d8a","name":"lock state change","server":"cc436e5e.bbf7e","version":1,"entityidfilter":"binary_sensor.loungedoorlock","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":180,"y":620,"wires":[["a0a2690e.b46f58"],[]]},{"id":"a0a2690e.b46f58","type":"ha-wait-until","z":"9c580098.19d8a","name":"initial timer","server":"cc436e5e.bbf7e","outputs":2,"entityId":"binary_sensor.loungedoorlock","property":"state","comparator":"is","value":"off","valueType":"str","timeout":"5","timeoutUnits":"minutes","entityLocation":"data","entityLocationType":"msg","checkCurrentState":true,"x":420,"y":620,"wires":[[],["47635cf0.dc8574"]]},{"id":"34f09ea1.dc89f2","type":"api-call-service","z":"9c580098.19d8a","name":"notify unlocked","server":"cc436e5e.bbf7e","service_domain":"notify","service":"everyone","data":"{\"message\":\"The front door has been unlocked for {{minutes}} minutes\"}","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":890,"y":620,"wires":[["a0fb93d.aff9a7"]]},{"id":"a0fb93d.aff9a7","type":"ha-wait-until","z":"9c580098.19d8a","name":"loop timer","server":"cc436e5e.bbf7e","outputs":2,"entityId":"binary_sensor.loungedoorlock","property":"state","comparator":"is","value":"off","valueType":"str","timeout":"15","timeoutUnits":"minutes","entityLocation":"data","entityLocationType":"msg","checkCurrentState":true,"x":770,"y":500,"wires":[["357d0e17.cef0d2"],["47635cf0.dc8574"]]},{"id":"357d0e17.cef0d2","type":"api-call-service","z":"9c580098.19d8a","name":"notify locked","server":"cc436e5e.bbf7e","service_domain":"notify","service":"everyone","data":"{\"message\":\"The front door is now locked\"}","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1040,"y":500,"wires":[[]]},{"id":"47635cf0.dc8574","type":"change","z":"9c580098.19d8a","name":"","rules":[{"t":"set","p":"minutes","pt":"msg","to":"$round(data.timeSinceChangedMs / 60000,0)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":620,"wires":[["34f09ea1.dc89f2"]]},{"id":"cc436e5e.bbf7e","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":false}]

Here’s mine:

[{"id":"8c16912b.9c174","type":"server-state-changed","z":"43ff6cf5.198a24","name":"Jack's Door Open","server":"c8b3e58.9a76e18","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.jacksons_room_door_contact","entityidfiltertype":"substring","outputinitially":false,"state_type":"habool","haltifstate":"true","halt_if_type":"bool","halt_if_compare":"is","outputs":2,"output_only_on_state_change":false,"x":110,"y":720,"wires":[["8bdbf3ca.b2afd","86240504.4ca438"],["8bdbf3ca.b2afd"]]},{"id":"8bdbf3ca.b2afd","type":"stoptimer","z":"43ff6cf5.198a24","duration":"15","units":"Minute","payloadtype":"num","payloadval":"0","name":"","x":360,"y":780,"wires":[["45085492.aa40ac"],[]]},{"id":"86240504.4ca438","type":"api-current-state","z":"43ff6cf5.198a24","name":"Kids Bedtime?","server":"c8b3e58.9a76e18","version":1,"outputs":2,"halt_if":"true","halt_if_type":"bool","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.kidsbedtime","state_type":"habool","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":540,"y":720,"wires":[[],["7c0aff7e.d193d"]]},{"id":"45085492.aa40ac","type":"api-current-state","z":"43ff6cf5.198a24","name":"Door Open?","server":"c8b3e58.9a76e18","version":1,"outputs":2,"halt_if":"true","halt_if_type":"bool","halt_if_compare":"is","override_topic":false,"entity_id":"binary_sensor.jacksons_room_door_contact","state_type":"habool","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":570,"y":780,"wires":[[],["bfcd9f0d.de835"]]},{"id":"7c0aff7e.d193d","type":"api-call-service","z":"43ff6cf5.198a24","name":"On","server":"c8b3e58.9a76e18","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.jacksons_room_overhead_lights","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":730,"y":720,"wires":[[]]},{"id":"bfcd9f0d.de835","type":"api-call-service","z":"43ff6cf5.198a24","name":"Off","server":"c8b3e58.9a76e18","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.jacksons_room_overhead_lights","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":730,"y":780,"wires":[[]]},{"id":"c8b3e58.9a76e18","type":"server","z":"","name":"Home Assistant"}]

Thanks for thinking with me.
To be honest I do not understand how to programm the first two flows :pensive: :pensive:
So I tried the 3th one.
That is working.
The only minus is that timer keeps running when door is closed after an open situation.
Is a timer using a lot off CPU time? Because I like to check a lot of doors :thinking:

You only need two nodes in reality, the event: states node and a trigger node. When the door closes (i.e, the sensor reports “off”), then the trigger timer is reset. Otherwise, it’ll send the message after 5 minutes.

image

1 Like

That shouldn’t really matter unless you are in a VERY constrained environment. I have ~50-75 different timers running throughout my flows and it’s barely touching my CPU (running NodeRed standalone on a rPi4).

Wow thats the one.
Very nice to see all these options for the same questions.
I will ask another question in a new topic :thinking:
Thanks

1 Like

Thanks, good to know.
I also run on a RPI 4B, 4Gb.
So that must be strong enough

PS: Where to find this screen?

1 Like

In my house, the first message may get ignored. Hence the repeat loop, but other than that it’s 3 nodes. Wait until does a similar job to trigger.

Both options avoid the need to add additional nodes, I like to minimise what I install as each one is a potential source of bugs and vulnerability