Cancel sending if msg not received in timeout

I feel that I have read how to do this but I can't seem to figure it out now.
What I want to do is delay sending a message for a timeout and if another message is received throw it away and reset the timer continuing to do so until the timeout is reached. So, if the timeout is 2 seconds, if I send 4 messages each one second apart, only the 4th messages would be passed on.

I tried to do this by resetting the delay node but when i do that, the message with the reset is also dropped so NO message is passed on.

The only think I've been able to come up with is this:

[{"id":"15268b279146c574","type":"inject","z":"e43bbb21.21ef58","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":360,"y":620,"wires":[["189a977a9dda3078","a0db697532fd70a0"]]},{"id":"f462d9985406c0ef","type":"debug","z":"e43bbb21.21ef58","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":900,"y":660,"wires":[]},{"id":"972dd8419b4901fb","type":"delay","z":"e43bbb21.21ef58","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"x":700,"y":620,"wires":[["f462d9985406c0ef"]]},{"id":"a0db697532fd70a0","type":"delay","z":"e43bbb21.21ef58","name":"","pauseType":"delay","timeout":"100","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"x":530,"y":640,"wires":[["972dd8419b4901fb"]]},{"id":"189a977a9dda3078","type":"change","z":"e43bbb21.21ef58","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":600,"wires":[["972dd8419b4901fb"]]}]

image

That does what I want but is a little cumbersome to have to implement everywhere.

This is pretty much what the cook book demo does: Trigger a flow if a message isn’t received after a defined time : Node-RED

Here it is adapted to send the last message...

chrome_8RPHxMvaxi

[{"id":"6ea53ad8.2362a4","type":"debug","z":"a0a5ddea2fa4216f","name":"Debug msg","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":554,"y":192,"wires":[]},{"id":"3da6946e.184a5c","type":"inject","z":"a0a5ddea2fa4216f","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":132,"y":192,"wires":[["38caaff4.03f6d","6ea53ad8.2362a4"]]},{"id":"38caaff4.03f6d","type":"trigger","z":"a0a5ddea2fa4216f","name":"Send last after 2 sec","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"2","extend":true,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":340,"y":240,"wires":[["ae477709.016088"]]},{"id":"ae477709.016088","type":"debug","z":"a0a5ddea2fa4216f","name":"Released message","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":574,"y":240,"wires":[]}]
1 Like

See, I looked at the Trigger Node! I guess I didn't scroll down far enough in the drop-down to see the "send last message" option. Thank you!!!

1 Like

It is working like a charm! Thank you again @Steve-Mcl !!!!

1 Like

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