Counter + Loop to check the door sensor

Hello everyone,
Can anyone give me a good solution to the following problem?
: I attached a sensor to a door. When opening the door, I get the payload: "open" or when closing comes "closed"
That works quite well so far.
My problem is that I would like to have a timer to which I can react if the door is open for longer than 5 minutes, for example.
I have already tried to solve this with a counter node. Unfortunately, I only manage to trigger the counter with both messages. It should of course be the case that the counter switches off within the time when the door is closed. And when the counter is reached, it should be checked again whether the door is still open. If so, I would like to send a message to alexa or if the whole thing has been sent to alexa 3 times and the door is still open, send an email.
It is not about the output of Alexa or sending an email, but only about the function that something should be checked again after a certain time and only then should a reaction be made. So actually a kind of "loop" that is executed until a condition is met. So either the door is closed or just a message.
Perhaps one of you has already realized something like this?
Thanks in advance

You need to show some code but You can send an 'on' to turn on a timer (mytimer - my module :slight_smile: ) and an off or cancel can turn it off otherwise it triggers. It sends and receives via MQTT.

Assuming that "I have not yet received 'Close'" is equivalent to "The door is still open" you can do it like this

[{"id":"5c35f879e30c4e86","type":"inject","z":"142f935612b6e391","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Open","payloadType":"str","x":90,"y":40,"wires":[["61a49049877c4a50"]]},{"id":"85f93cd0cc48fabb","type":"inject","z":"142f935612b6e391","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Close","payloadType":"str","x":90,"y":80,"wires":[["61a49049877c4a50"]]},{"id":"931a4abf9e94499b","type":"trigger","z":"142f935612b6e391","name":"","op1":"","op2":"Door has been open for 5 minutes","op1type":"nul","op2type":"str","duration":"5","extend":false,"overrideDelay":false,"units":"min","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":670,"y":60,"wires":[["77bb6810962c2ab1"]]},{"id":"c8ffa58679d37cda","type":"change","z":"142f935612b6e391","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":120,"wires":[["931a4abf9e94499b"]]},{"id":"77bb6810962c2ab1","type":"debug","z":"142f935612b6e391","name":"debug 395","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":710,"y":120,"wires":[]},{"id":"eaef9761993d57fc","type":"switch","z":"142f935612b6e391","name":"Open or Close?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"Open","vt":"str"},{"t":"eq","v":"Close","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":320,"y":60,"wires":[["931a4abf9e94499b"],["c8ffa58679d37cda"]]},{"id":"61a49049877c4a50","type":"junction","z":"142f935612b6e391","x":200,"y":60,"wires":[["eaef9761993d57fc"]]}]
1 Like

Hi! thank you! this one works fine ! i set 3 trigger. 1. for 2 minutes, 2. 3 minutes, and the last one to 5 minutes. so I can react differently in each case.

THX

Just for info, you can do this with one trigger and different topics and delay times
e.g.

[{"id":"5c35f879e30c4e86","type":"inject","z":"b9860b4b9de8c8da","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"open","payloadType":"str","x":570,"y":100,"wires":[["1a38a487735d5c28"]]},{"id":"1a38a487735d5c28","type":"junction","z":"b9860b4b9de8c8da","x":440,"y":240,"wires":[["07cb9683b646344c","92ec7fde4781279f","b97b7eafd2c29e36"]]},{"id":"85f93cd0cc48fabb","type":"inject","z":"b9860b4b9de8c8da","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"closed","payloadType":"str","x":570,"y":140,"wires":[["1a38a487735d5c28"]]},{"id":"07cb9683b646344c","type":"change","z":"b9860b4b9de8c8da","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"two","tot":"str"},{"t":"set","p":"delay","pt":"msg","to":"120000","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":200,"wires":[["931a4abf9e94499b"]]},{"id":"92ec7fde4781279f","type":"change","z":"b9860b4b9de8c8da","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"three","tot":"str"},{"t":"set","p":"delay","pt":"msg","to":"180000","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":240,"wires":[["931a4abf9e94499b"]]},{"id":"b97b7eafd2c29e36","type":"change","z":"b9860b4b9de8c8da","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"five","tot":"str"},{"t":"set","p":"delay","pt":"msg","to":"300000","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":280,"wires":[["931a4abf9e94499b"]]},{"id":"931a4abf9e94499b","type":"trigger","z":"b9860b4b9de8c8da","name":"","op1":"","op2":"open fo 5 mins","op1type":"nul","op2type":"str","duration":"5","extend":false,"overrideDelay":true,"units":"min","reset":"closed","bytopic":"topic","topic":"topic","outputs":1,"x":770,"y":120,"wires":[["63c8b4ab0d573b01"]]},{"id":"63c8b4ab0d573b01","type":"switch","z":"b9860b4b9de8c8da","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"two","vt":"str"},{"t":"eq","v":"three","vt":"str"},{"t":"eq","v":"five","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":910,"y":120,"wires":[["dba9ccb33364b1e3"],["dba9ccb33364b1e3"],["dba9ccb33364b1e3"]]},{"id":"dba9ccb33364b1e3","type":"template","z":"b9860b4b9de8c8da","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"Open for {{topic}} minutes","output":"str","x":820,"y":260,"wires":[["77bb6810962c2ab1"]]},{"id":"77bb6810962c2ab1","type":"debug","z":"b9860b4b9de8c8da","name":"debug 395","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":990,"y":260,"wires":[]}]

1 Like

thank you!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.