Trigger if the second message doesn't occour

Hi, I have this situation, I need to reset a variable after some time, in any case, even if the automation doesn't do it itself (something went wrong or on error).
If a second message incoming during delay the delay period the first message should be deleted, and only the second message will be outputed after the delay time.

Actually I need to use a function placed on the input note, which generates a property reset:1 ad any message input, and the main message is slightly delayed to allow reset occour safely.
I suppose there is a way to do this with one node only, thank you

Why does it need to be a function?
Why must it be only one node?

After the second message does the same timeout start again unless a third arrives?

On the face of it, a trigger node will do it. You may need to send a message with msg.reset but no msg.payload to stop the current timeout countdown.

I'm looking for something else than a function, like trigger node, but trigger doesn't support this, it resets only if you input a reset message and to input a reset I need an extra function, so it doesn't have sense.
More, if you reset and input the second message at the same time you may be not sure the second message will be stored, so I added an extra small delay for main message input, while the reset fnction will be triggered suddenly and reset.

If the 3rd come, is the same like the 2nd was on the 1st
May you send me an example with only one trigger node?
I suggst to implement this feature on trigger

[{"id":"3c9ae83e9385c3fe","type":"trigger","z":"b45544f267d46e64","name":"","op1":"This is a message","op2":"timeout","op1type":"str","op2type":"str","duration":"10","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":490,"y":340,"wires":[["1c537761ea65e5e3"]]},{"id":"1c537761ea65e5e3","type":"debug","z":"b45544f267d46e64","name":"debug 297","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":670,"y":340,"wires":[]},{"id":"75d6e16b89a2de29","type":"inject","z":"b45544f267d46e64","name":"","props":[{"p":"payload"},{"p":"reset","v":"","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":320,"wires":[["83fec65225aa019c"]]},{"id":"83fec65225aa019c","type":"change","z":"b45544f267d46e64","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":320,"wires":[["3c9ae83e9385c3fe","9d20e97df546974a"]]},{"id":"9d20e97df546974a","type":"change","z":"b45544f267d46e64","name":"","rules":[{"t":"delete","p":"reset","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":360,"wires":[["3c9ae83e9385c3fe"]]}]
1 Like

That is nice.

It may actually solve some of my problems which I have had to work around.

Ok, but it would be nice Trigger node supports also this function by option:
"in case of second message forget the first one", that would be lovely

How about this then?
Untitled 3

[{"id":"d9de94c58b4a30f2","type":"debug","z":"b45544f267d46e64","name":"debug 298","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":650,"y":440,"wires":[]},{"id":"622057b8a7457038","type":"inject","z":"b45544f267d46e64","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"A message","payloadType":"str","x":320,"y":440,"wires":[["b2892ed8a4b11896","d9de94c58b4a30f2"]]},{"id":"b2892ed8a4b11896","type":"trigger","z":"b45544f267d46e64","name":"","op1":"","op2":"timeout","op1type":"nul","op2type":"str","duration":"5","extend":true,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":480,"y":460,"wires":[["d9de94c58b4a30f2"]]}]

this will sent the first message anyway, I need to kill the first if a second occours, and keep the second only (if a third not occours within the delay)

Lets say your timeout period is 10 seconds.
Is this the behaviour you need?

0sec Message 1 arrives. Queue it.
10 sec No further message. Send message 1.

20sec Message 2 arrives. Queue it.
28sec Message 3 arrives. Replace message 2 in queue.
36sec Message 4 arrives. Replace message 3 in queue.
44sec Message 5 arrives. Replace message 4 in queue.
54sec Send message 5

Doesn't the trigger node do this on its own.
Send nothing
Then send latest object.
You can also un/check extend delay if new message.
e.g.

[{"id":"fe345875c8c2b9db","type":"inject","z":"65617ffeb779f51c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"$round($random()*1000)","payloadType":"jsonata","x":70,"y":2000,"wires":[["4f9f7aa6bf2caa96","4cb93daf4022da85"]]},{"id":"4f9f7aa6bf2caa96","type":"debug","z":"65617ffeb779f51c","name":"debug 243","active":false,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"msg","x":210,"y":1940,"wires":[]},{"id":"4cb93daf4022da85","type":"trigger","z":"65617ffeb779f51c","name":"","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"5000","extend":true,"overrideDelay":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":300,"y":2000,"wires":[["11e550b748db452d"]]},{"id":"11e550b748db452d","type":"debug","z":"65617ffeb779f51c","name":"debug 244","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":470,"y":1960,"wires":[]}]
1 Like

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