How to both reset & set delay in "delay node"

Hello, I am trying to send correctly two messages to "delay node"
"reset" and "set delay"

When I send only one it works ok, but when I send two only reset is executed

How to both "reset" and "set" delay node?

I need to have one timer, because it make my design much simpler than multiple timers (I need to be sure that max one timer is active anyway)

I will use 6 different timer values, currently 5s and 10s for testing

Maybe it can be done with different node types?

2019-09-01%20(1)

reset

If the received message has this property set to any value, all outstanding messages held by the node are cleared without being sent.

so the current msg is cleared along with everyt hing else. no message continues on.

What you can do is have two change nodes, one sets the reset, the other the delay after a delay. Like this:

1 Like

Actually a simple function node can return two messages...

eg

msg.delay = 5000;
var m1 = {reset:true};
return [[m1,msg]];
[{"id":"f8275102.af47b","type":"inject","z":"a68cca8a.e5ba98","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":1560,"wires":[["193bbb8c.ee43a4"]]},{"id":"193bbb8c.ee43a4","type":"function","z":"a68cca8a.e5ba98","name":"","func":"msg.delay = 5000;\nvar m1 = {reset:true};\nreturn [[m1,msg]];","outputs":1,"noerr":0,"x":320,"y":1560,"wires":[["941932e.e9abcd"]]},{"id":"941932e.e9abcd","type":"delay","z":"a68cca8a.e5ba98","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":480,"y":1560,"wires":[["d02fef04.15e29"]]},{"id":"d02fef04.15e29","type":"debug","z":"a68cca8a.e5ba98","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":650,"y":1560,"wires":[]}]
1 Like

Thank you, it works , but I needed to increase delay, 8ms was not reliable enough,

Well I'm glad to have pointed you in the right direction.
@dceejay When you use the function node you are returning two seperate messages but if you do this


Am I correct in saying the reason this doesn't work because both change nodes in the 'hello' leg are referencing the same msg and the reset resets everything...

It may work ( I didn’t check) mine was just an alternative

The dual leg that I showed DOES NOT work but the dual leg with a delay DOES work and I was trying to reason the reason why

It depends which message will come first, so I guess it is 50%-50% ?

... which is why my function node sends the reset first :slight_smile:

3 Likes

Ah here is a way to get it to work with two change nodes:


The second change node deletes msg.reset
32%20AM

I think behavior of timer node is anyway unintuitive and should be changed.

When both msg.delay and msg.reset are sent it should reset and start counting

What do you think?

Btw it is my first automation in nodered and I already love it <3

It works just as the readme states. I personally don’t find this unintuitive.

Changing the behaviour would break existing flows which is something to be avoided.

Maybe a new attribute (e.g. resetAndQueue) could be added which provides the above requested behavior (i.e. clear all pending timers and enqueuing the current message).

2 Likes

I would like to bump this topic. Having another option like "restart" or something similar would be very useful. It would not change any existing functionality and would be alone the same thinking of the current option of reset. Seems like a pretty easy feature that would get a lot of bang for your buck, IMHO.

Since this thread is a year old, please start a new thread about your issue. And please explain why reset will not work for you.

I'm closing this thread.