# Delay node where reset only affects certain events?

**URL:** <https://discourse.nodered.org/t/delay-node-where-reset-only-affects-certain-events/75076>\
**Category:** General\
**Created:** [12 February 2023 16:42 UTC](https://discourse.nodered.org/t/delay-node-where-reset-only-affects-certain-events/75076 "2023-02-12T16:42:05Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![reibuehl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/reibuehl/32/74933_2.png) [@reibuehl](https://discourse.nodered.org/u/reibuehl)\
**Post date:** [12 February 2023 16:42 UTC](https://discourse.nodered.org/t/delay-node-where-reset-only-affects-certain-events/75076/1 "2023-02-12T16:42:05Z")

</div>

I have a message flow from a bunch of window sensors where I get open/close events. I would like to use them to give a message if a window is open for too long. For this I currently use a delay node that gets the open events and the close events are used as reset. This works if only one window is open but fails if I get open events from more than one source during the delay period as the first close event will also reset the other event.  
I already have a msg.device attribute in the event that could be used to correlate the open and close events for each device but how could I implement such a correlation?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [12 February 2023 17:02 UTC](https://discourse.nodered.org/t/delay-node-where-reset-only-affects-certain-events/75076/2 "2023-02-12T17:02:54Z")

</div>

Exactly what do you want to happen if multiple windows are being opened and closed? Under what circumstance _exactly_ to you want to generate a message?

---

<div class="post-metadata">

**Author:** ![reibuehl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/reibuehl/32/74933_2.png) [@reibuehl](https://discourse.nodered.org/u/reibuehl)\
**Post date:** [12 February 2023 17:30 UTC](https://discourse.nodered.org/t/delay-node-where-reset-only-affects-certain-events/75076/3 "2023-02-12T17:30:21Z")

</div>

I want to create a message for a window if there is no close message for that window within 30 minutes after the open message. Independent from other windows. Eg. if there is a window 1 open, then a few minutes later window 2 open, then window 2 close, then there should still be a message for window 1 after 30 minute. Currently the open message for window 1 gets purged by the reset message for window 2.  
I would like to avoid having to duplicate the same flow 20 times to treat every window individually just because the reset in the delay is treating messages from all devices as if they where from one source.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [12 February 2023 18:00 UTC](https://discourse.nodered.org/t/delay-node-where-reset-only-affects-certain-events/75076/4 "2023-02-12T18:00:31Z")

</div>

Try this example it will respond to separate windows. It uses a trigger node and applies the trigger to each msg.topic. You do not say what your incoming message structure is, so you will have to apply my example to your message and adjust.

```auto
[{"id":"16dd4fc968ec509a","type":"inject","z":"da8a6ef0b3c9a5c8","name":"s1 open","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"event\": \"open\",\"sensor\":\"one\"}","payloadType":"json","x":90,"y":4560,"wires":[["d673297c3c6f2a0a"]]},{"id":"d673297c3c6f2a0a","type":"change","z":"da8a6ef0b3c9a5c8","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"payload.sensor","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"payload.event","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":4680,"wires":[["7789949f1849da48","a1759bdfe00d7bf9"]]},{"id":"153f41b6e63e3a39","type":"inject","z":"da8a6ef0b3c9a5c8","name":"s1 close","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"event\": \"close\",\"sensor\":\"one\"}","payloadType":"json","x":100,"y":4600,"wires":[["d673297c3c6f2a0a"]]},{"id":"4afc9175da23264c","type":"inject","z":"da8a6ef0b3c9a5c8","name":"s2 open","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"event\": \"open\",\"sensor\":\"two\"}","payloadType":"json","x":90,"y":4640,"wires":[["d673297c3c6f2a0a"]]},{"id":"8e7c6a1c44f4b9e8","type":"inject","z":"da8a6ef0b3c9a5c8","name":"s2 close","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"event\": \"close\",\"sensor\":\"two\"}","payloadType":"json","x":100,"y":4680,"wires":[["d673297c3c6f2a0a"]]},{"id":"a532635dec9c02cc","type":"inject","z":"da8a6ef0b3c9a5c8","name":"s3 open","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"event\": \"open\",\"sensor\":\"three\"}","payloadType":"json","x":90,"y":4720,"wires":[["d673297c3c6f2a0a"]]},{"id":"c5417056345c91ee","type":"inject","z":"da8a6ef0b3c9a5c8","name":"s3 close","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"event\": \"close\",\"sensor\":\"three\"}","payloadType":"json","x":100,"y":4760,"wires":[["d673297c3c6f2a0a"]]},{"id":"7789949f1849da48","type":"trigger","z":"da8a6ef0b3c9a5c8","name":"","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"10","extend":true,"overrideDelay":false,"units":"s","reset":"close","bytopic":"topic","topic":"topic","outputs":1,"x":490,"y":4680,"wires":[["a9f0bb355e75b6d0"]]},{"id":"a1759bdfe00d7bf9","type":"debug","z":"da8a6ef0b3c9a5c8","name":"open/close","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":610,"y":4600,"wires":[]},{"id":"a9f0bb355e75b6d0","type":"template","z":"da8a6ef0b3c9a5c8","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"window {{topic}} still {{payload}} !","output":"str","x":660,"y":4680,"wires":[["499a07b9f423a89f"]]},{"id":"499a07b9f423a89f","type":"debug","z":"da8a6ef0b3c9a5c8","name":"open longer than trigger delay","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":630,"y":4740,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [12 February 2023 21:14 UTC](https://discourse.nodered.org/t/delay-node-where-reset-only-affects-certain-events/75076/5 "2023-02-12T21:14:09Z")

</div>

> [@E1cid](#):
>
> uses a trigger node and applies the trigger to each msg.topic

This is the key. Each topic is handled separately, **including** the reset. You have a lot of flexibility in how you set up topics and payloads from each of the sensors.

---

<div class="post-metadata">

**Author:** ![reibuehl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/reibuehl/32/74933_2.png) [@reibuehl](https://discourse.nodered.org/u/reibuehl)\
**Post date:** [14 February 2023 12:07 UTC](https://discourse.nodered.org/t/delay-node-where-reset-only-affects-certain-events/75076/6 "2023-02-14T12:07:09Z")

</div>

I was able to adjust my flow to use the trigger node as you suggested but I struggle with the reset. I have adjusted the trigger to work on the msg.device attribute which in my case contains the name of the device but the events with "close" payload seem to do nothing, the window open reminder message is sent after the interval regardless if the window is still open or if it was closed in the meantime.

 ![Unbenannt](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/d/4dcf50da595ce7e74723b0bf0ac822cf73261d5f.jpeg)

Do I need to set msg.reset on the close events? Your example did not do that as far as I can see:

 ![Unbenannt2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/9/49643b9dbc42682e624549cb45e853d3d20c917e.jpeg)

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [14 February 2023 12:10 UTC](https://discourse.nodered.org/t/delay-node-where-reset-only-affects-certain-events/75076/7 "2023-02-14T12:10:45Z")

</div>

Again i do not know your incoming messages, please provide example flow with example incoming messages in several inject nodes, as i did. Then we can maybe see your issue.

---

<div class="post-metadata">

**Author:** ![reibuehl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/reibuehl/32/74933_2.png) [@reibuehl](https://discourse.nodered.org/u/reibuehl)\
**Post date:** [21 February 2023 16:49 UTC](https://discourse.nodered.org/t/delay-node-where-reset-only-affects-certain-events/75076/8 "2023-02-21T16:49:19Z")

</div>

My problem seems to come from MQTT input messages with persistence flag that mess up the rest of the logic. The part from your example works fine. Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [7 March 2023 16:49 UTC](https://discourse.nodered.org/t/delay-node-where-reset-only-affects-certain-events/75076/9 "2023-03-07T16:49:55Z")

</div>

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