# Check event happening before a certain timeout

**URL:** <https://discourse.nodered.org/t/check-event-happening-before-a-certain-timeout/40501>\
**Category:** General\
**Created:** [6 February 2021 16:22 UTC](https://discourse.nodered.org/t/check-event-happening-before-a-certain-timeout/40501 "2021-02-06T16:22:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![fmarzocca](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fmarzocca/32/35901_2.png) [@fmarzocca](https://discourse.nodered.org/u/fmarzocca)\
**Post date:** [6 February 2021 16:22 UTC](https://discourse.nodered.org/t/check-event-happening-before-a-certain-timeout/40501/1 "2021-02-06T16:22:45Z")

</div>

I have a trivial issue, but I got lost.  
I need a timer to start in a certain flow position when "ON" message is received. Then, if an "OFF" message is received within 3 seconds, another branch of the flow will take part.  
I tried the "countdown" module but it doesn't fit with my needs.

---

<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:** [6 February 2021 16:50 UTC](https://discourse.nodered.org/t/check-event-happening-before-a-certain-timeout/40501/2 "2021-02-06T16:50:28Z")

</div>

You could do it with a Trigger and a node-red-contrib-simple-gate  
Depending on what you want to happen if another ON or OFF comes in during the timeout you might have to feed the output back to close the gate and reset the trigger.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/b/9b4766f193957fe0a201718592ddc3f9f1f4c7f3.png)

```auto
[{"id":"1cff539d.ca4f0c","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"ON","payloadType":"str","x":90,"y":4760,"wires":[["7fd9e863.35aa4"]]},{"id":"2186e261.65693e","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"OFF","payloadType":"str","x":90,"y":4820,"wires":[["7fd9e863.35aa4"]]},{"id":"7fd9e863.35aa4","type":"switch","z":"bdd7be38.d3b55","name":"ON/OFF","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"ON","vt":"str"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":220,"y":4800,"wires":[["bd9ed63e.05d258"],["9bdecbe2.deb46"]]},{"id":"bd9ed63e.05d258","type":"trigger","z":"bdd7be38.d3b55","name":"Open/close gate","op1":"open","op2":"close","op1type":"str","op2type":"str","duration":"3","extend":true,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":380,"y":4740,"wires":[["e3b302c7.607e18"]]},{"id":"9bdecbe2.deb46","type":"gate","z":"bdd7be38.d3b55","name":"","controlTopic":"control","defaultState":"closed","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","statusCmd":"status","persist":false,"x":610,"y":4800,"wires":[["5e80548b.7280ec"]]},{"id":"e3b302c7.607e18","type":"change","z":"bdd7be38.d3b55","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":550,"y":4740,"wires":[["9bdecbe2.deb46"]]},{"id":"5e80548b.7280ec","type":"debug","z":"bdd7be38.d3b55","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":670,"y":4900,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![fmarzocca](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fmarzocca/32/35901_2.png) [@fmarzocca](https://discourse.nodered.org/u/fmarzocca)\
**Post date:** [6 February 2021 19:14 UTC](https://discourse.nodered.org/t/check-event-happening-before-a-certain-timeout/40501/3 "2021-02-06T19:14:31Z")

</div>

Thanks, but how to check "within 3 seconds from ON"?

---

<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:** [6 February 2021 19:48 UTC](https://discourse.nodered.org/t/check-event-happening-before-a-certain-timeout/40501/4 "2021-02-06T19:48:42Z")

</div>

Did you import my suggestion and try it?

---

<div class="post-metadata">

**Author:** ![fmarzocca](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fmarzocca/32/35901_2.png) [@fmarzocca](https://discourse.nodered.org/u/fmarzocca)\
**Post date:** [6 February 2021 21:04 UTC](https://discourse.nodered.org/t/check-event-happening-before-a-certain-timeout/40501/5 "2021-02-06T21:04:38Z")

</div>

Yes, and I have seen how you are suggesting to use the trigger node, 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:** [20 February 2021 21:04 UTC](https://discourse.nodered.org/t/check-event-happening-before-a-certain-timeout/40501/6 "2021-02-20T21:04:40Z")

</div>

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