# Time bounded Condition on Node-Red

**URL:** <https://discourse.nodered.org/t/time-bounded-condition-on-node-red/17475>\
**Category:** General\
**Created:** [4 November 2019 09:17 UTC](https://discourse.nodered.org/t/time-bounded-condition-on-node-red/17475 "2019-11-04T09:17:08Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![primat11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/primat11/32/12185_2.png) [@primat11](https://discourse.nodered.org/u/primat11)\
**Post date:** [4 November 2019 09:17 UTC](https://discourse.nodered.org/t/time-bounded-condition-on-node-red/17475/1 "2019-11-04T09:17:08Z")

</div>

Hello everyone, I want to create a time bounded 'if' condition for my RFID system that I created on Node-Red. My task is to provide a condition:  
"If detected RFID TAG is not read once again in 30 seconds, give a message"

So, basically I want the timer to start once the rfid tag is detected, then if it is not read once again in 30 seconds, the output is a message"  
I am following some JS tutorials on time bounded 'if else' condition. Is there any simpler way or a much better way for this approach on Node-RED. Thanks 🙂

Best Regards

---

<div class="post-metadata">

**Author:** ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)\
**Post date:** [4 November 2019 09:25 UTC](https://discourse.nodered.org/t/time-bounded-condition-on-node-red/17475/2 "2019-11-04T09:25:45Z")

</div>

The `trigger` node is your friend here. 😀

Have a look at the example in the cookbook, it might cover your need as-is.

[https://cookbook.nodered.org/basic/trigger-timeout](https://cookbook.nodered.org/basic/trigger-timeout)

---

<div class="post-metadata">

**Author:** ![primat11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/primat11/32/12185_2.png) [@primat11](https://discourse.nodered.org/u/primat11)\
**Post date:** [4 November 2019 09:29 UTC](https://discourse.nodered.org/t/time-bounded-condition-on-node-red/17475/3 "2019-11-04T09:29:57Z")

</div>

Thanks a lot @kuema, I am trying with trigger node. 🙂

---

<div class="post-metadata">

**Author:** ![primat11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/primat11/32/12185_2.png) [@primat11](https://discourse.nodered.org/u/primat11)\
**Post date:** [5 November 2019 09:52 UTC](https://discourse.nodered.org/t/time-bounded-condition-on-node-red/17475/4 "2019-11-05T09:52:37Z")

</div>

Now, my flow looks a bit like this and I am able to get the desired output when the particular tag is not read again in 30s.

 ![Newflow_screenshot](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/8/82b754904ddcfe952361c83f20fa8ee87f66617b.png)

Is there a possibility to display the msg.payload for the failed detected tag(debug 2) to just display the output for a time specified duration(10s)?

---

<div class="post-metadata">

**Author:** ![primat11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/primat11/32/12185_2.png) [@primat11](https://discourse.nodered.org/u/primat11)\
**Post date:** [5 November 2019 09:56 UTC](https://discourse.nodered.org/t/time-bounded-condition-on-node-red/17475/5 "2019-11-05T09:56:49Z")

</div>

Can the "mytimeout" node be useful?

---

<div class="post-metadata">

**Author:** ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)\
**Post date:** [5 November 2019 10:58 UTC](https://discourse.nodered.org/t/time-bounded-condition-on-node-red/17475/6 "2019-11-05T10:58:52Z")

</div>

Display where? Do you have a dashboard attached? I don't quite follow. 😅

At the moment your output goes to the debug node and MQTT.

If you want to "clear" the message on the debug node, you could use a `delay` node in parallel that sends and empty payload after the delay of 10s or so.

---

<div class="post-metadata">

**Author:** ![primat11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/primat11/32/12185_2.png) [@primat11](https://discourse.nodered.org/u/primat11)\
**Post date:** [5 November 2019 11:06 UTC](https://discourse.nodered.org/t/time-bounded-condition-on-node-red/17475/7 "2019-11-05T11:06:07Z")

</div>

The MQTT output goes to a SCADA system, it looks like this

 ![SCADA](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/3/3b529da17f3c1c047500ff0f35d5a8f2d615013d.png)

I want to clear the message after it is displayed on SCADA system, I will try with delay node

---

<div class="post-metadata">

**Author:** ![primat11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/primat11/32/12185_2.png) [@primat11](https://discourse.nodered.org/u/primat11)\
**Post date:** [5 November 2019 11:19 UTC](https://discourse.nodered.org/t/time-bounded-condition-on-node-red/17475/8 "2019-11-05T11:19:34Z")

</div>

With delay node, I do not think I can erase the msg.payload after a specific duration, it just delays the output as far as I know. I tried to experiment with delay node but it does not suit the purpose.

Would you like to show the particular way in which I can use it to ERASE THE MSG.PAYLOAD AFTER 10s? Thanks a lot in advance.

Best regards

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [5 November 2019 11:39 UTC](https://discourse.nodered.org/t/time-bounded-condition-on-node-red/17475/9 "2019-11-05T11:39:27Z")

</div>

> [@primat11](#):
>
> Would you like to show the particular way in which I can use it to ERASE THE MSG.PAYLOAD AFTER 10s? Thanks a lot in advance.

Will this do what you want?

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

---

<div class="post-metadata">

**Author:** ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)\
**Post date:** [5 November 2019 11:41 UTC](https://discourse.nodered.org/t/time-bounded-condition-on-node-red/17475/10 "2019-11-05T11:41:19Z")

</div>

It does exactly that, if you use it in parallel 😉

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

```auto
[{"id":"4bbd6019.c26b","type":"inject","z":"71d50c24.c428a4","name":"","topic":"","payload":"my value","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":340,"y":380,"wires":[["fff77905.4b00f8","714a858a.90428c"]]},{"id":"fff77905.4b00f8","type":"debug","z":"71d50c24.c428a4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":930,"y":380,"wires":[]},{"id":"714a858a.90428c","type":"delay","z":"71d50c24.c428a4","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":540,"y":440,"wires":[["63b2dfd0.2c33e"]]},{"id":"63b2dfd0.2c33e","type":"change","z":"71d50c24.c428a4","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"clear","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":440,"wires":[["fff77905.4b00f8"]]}]

```

---

<div class="post-metadata">

**Author:** ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)\
**Post date:** [5 November 2019 11:42 UTC](https://discourse.nodered.org/t/time-bounded-condition-on-node-red/17475/11 "2019-11-05T11:42:33Z")

</div>

Haha, good timing Simon. 😁

---

<div class="post-metadata">

**Author:** ![primat11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/primat11/32/12185_2.png) [@primat11](https://discourse.nodered.org/u/primat11)\
**Post date:** [5 November 2019 11:58 UTC](https://discourse.nodered.org/t/time-bounded-condition-on-node-red/17475/12 "2019-11-05T11:58:13Z")

</div>

I just added one more function node after the 'change' node as I had some MQTT topics to be sent to SCADA. Anyway thanks a lot, it solves my purpose and I have learnt some extra functionality.

Schönen Tag noch. Vielen Dank 🙂

SG

---

<div class="post-metadata">

**Author:** ![primat11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/primat11/32/12185_2.png) [@primat11](https://discourse.nodered.org/u/primat11)\
**Post date:** [5 November 2019 11:58 UTC](https://discourse.nodered.org/t/time-bounded-condition-on-node-red/17475/13 "2019-11-05T11:58:50Z")

</div>

Thanks a lot Simon for your comment. It solved the purpose.  
Thanks and have a nice day. 🙂

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [5 November 2019 12:22 UTC](https://discourse.nodered.org/t/time-bounded-condition-on-node-red/17475/14 "2019-11-05T12:22:35Z")

</div>

it was @kuema idea 🙂

---

<div class="post-metadata">

**Author:** ![primat11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/primat11/32/12185_2.png) [@primat11](https://discourse.nodered.org/u/primat11)\
**Post date:** [6 November 2019 13:57 UTC](https://discourse.nodered.org/t/time-bounded-condition-on-node-red/17475/15 "2019-11-06T13:57:24Z")

</div>

@kuema The screenshot of my flow which I have sent below, I am facing a situation, where my trigger node sends msg.payload to the 'switch' node in the time duration of '10s'.

 ![Newflow_screenshot](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/8/82b754904ddcfe952361c83f20fa8ee87f66617b.png)

My aim is to fulfil the condition: "If in this particular time duration, the same tagID is read again, then send it as a normal condition, 'else' if the tag is not read in this duration, give a message"

Presently, in the 'switch' node:

1. == previous value (normal condition)
2. != previous value (alert condition)

But the previous condition for this switch node appears to be the msg.payload it received in the previous event, as the trigger node sends the data in every 10s and not in between this duration what it has read.

I have tried:

1. In parallel, a delay node(5s) attaching direct to the RFID(MQTT IN) node and output goes to the switch node, so that it compares this msg.payload value received from this node to the msg.payload value received from the trigger node in 10s, which ever comes first becomes the 'previous value'.

But it is not functioning exactly as the condition I am expecting. Can you or anyone has a better possible solution?

Thanks and regards
