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

**URL:** <https://discourse.nodered.org/t/how-to-both-reset-set-delay-in-delay-node/14999>\
**Category:** General\
**Created:** [1 September 2019 12:43 UTC](https://discourse.nodered.org/t/how-to-both-reset-set-delay-in-delay-node/14999 "2019-09-01T12:43:17Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![qqgg231](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/qqgg231/32/38629_2.png) [@qqgg231](https://discourse.nodered.org/u/qqgg231)\
**Post date:** [1 September 2019 12:43 UTC](https://discourse.nodered.org/t/how-to-both-reset-set-delay-in-delay-node/14999/1 "2019-09-01T12:43:17Z")

</div>

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)](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/c/cc905e78803dfac58a69f2d7038e513b669c539f.png)

 ![2019-09-01](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/6757de88c31638c6de9c09a6c10ddea9764e798e.png)

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [1 September 2019 13:21 UTC](https://discourse.nodered.org/t/how-to-both-reset-set-delay-in-delay-node/14999/2 "2019-09-01T13:21:23Z")

</div>

> 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:

 ![28%20AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/6fa3a8913d6451a550907ec8231e850c4ba96536.png)

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [1 September 2019 13:53 UTC](https://discourse.nodered.org/t/how-to-both-reset-set-delay-in-delay-node/14999/3 "2019-09-01T13:53:12Z")

</div>

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

eg

```auto
msg.delay = 5000;
var m1 = {reset:true};
return [[m1,msg]];

```

```auto
[{"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":[]}]

```

---

<div class="post-metadata">

**Author:** ![qqgg231](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/qqgg231/32/38629_2.png) [@qqgg231](https://discourse.nodered.org/u/qqgg231)\
**Post date:** [1 September 2019 15:24 UTC](https://discourse.nodered.org/t/how-to-both-reset-set-delay-in-delay-node/14999/4 "2019-09-01T15:24:08Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/f/f3a7605b871cf6d66830cd2c410e635db59b62e1.png)

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [1 September 2019 17:02 UTC](https://discourse.nodered.org/t/how-to-both-reset-set-delay-in-delay-node/14999/5 "2019-09-01T17:02:56Z")

</div>

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

 ![41%20PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/1/1cfb4f9ef6acc8a7b8763c92154e4c22507886cf.png)  
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...

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [1 September 2019 17:31 UTC](https://discourse.nodered.org/t/how-to-both-reset-set-delay-in-delay-node/14999/6 "2019-09-01T17:31:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [1 September 2019 17:37 UTC](https://discourse.nodered.org/t/how-to-both-reset-set-delay-in-delay-node/14999/7 "2019-09-01T17:37:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![qqgg231](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/qqgg231/32/38629_2.png) [@qqgg231](https://discourse.nodered.org/u/qqgg231)\
**Post date:** [2 September 2019 09:19 UTC](https://discourse.nodered.org/t/how-to-both-reset-set-delay-in-delay-node/14999/8 "2019-09-02T09:19:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [2 September 2019 10:10 UTC](https://discourse.nodered.org/t/how-to-both-reset-set-delay-in-delay-node/14999/9 "2019-09-02T10:10:07Z")

</div>

... which is why my function node sends the reset first 🙂

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [2 September 2019 10:24 UTC](https://discourse.nodered.org/t/how-to-both-reset-set-delay-in-delay-node/14999/10 "2019-09-02T10:24:56Z")

</div>

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

 ![22%20AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/5/55c45b4a5a2a40873420b81c2c553f61a8fc1eb7.png)  
The second change node deletes msg.reset  
 ![32%20AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/0/0eb9db472878d70dae036c7683ad53ba75d15274.png)

---

<div class="post-metadata">

**Author:** ![qqgg231](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/qqgg231/32/38629_2.png) [@qqgg231](https://discourse.nodered.org/u/qqgg231)\
**Post date:** [2 September 2019 11:08 UTC](https://discourse.nodered.org/t/how-to-both-reset-set-delay-in-delay-node/14999/11 "2019-09-02T11:08:56Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![qqgg231](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/qqgg231/32/38629_2.png) [@qqgg231](https://discourse.nodered.org/u/qqgg231)\
**Post date:** [2 September 2019 11:12 UTC](https://discourse.nodered.org/t/how-to-both-reset-set-delay-in-delay-node/14999/12 "2019-09-02T11:12:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [2 September 2019 11:16 UTC](https://discourse.nodered.org/t/how-to-both-reset-set-delay-in-delay-node/14999/13 "2019-09-02T11:16:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jens\_rossbach](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jens_rossbach/32/98717_2.png) [@jens\_rossbach](https://discourse.nodered.org/u/jens_rossbach)\
**Post date:** [9 November 2019 15:09 UTC](https://discourse.nodered.org/t/how-to-both-reset-set-delay-in-delay-node/14999/14 "2019-11-09T15:09:17Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![ryan780](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ryan780/32/22974_2.png) [@ryan780](https://discourse.nodered.org/u/ryan780)\
**Post date:** [25 September 2020 13:04 UTC](https://discourse.nodered.org/t/how-to-both-reset-set-delay-in-delay-node/14999/15 "2020-09-25T13:04:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [25 September 2020 13:39 UTC](https://discourse.nodered.org/t/how-to-both-reset-set-delay-in-delay-node/14999/16 "2020-09-25T13:39:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [25 September 2020 13:39 UTC](https://discourse.nodered.org/t/how-to-both-reset-set-delay-in-delay-node/14999/17 "2020-09-25T13:39:25Z")

</div>


