# Only send msg when some input data has had value for amount of time

**URL:** <https://discourse.nodered.org/t/only-send-msg-when-some-input-data-has-had-value-for-amount-of-time/43727>\
**Category:** General\
**Created:** [5 April 2021 21:02 UTC](https://discourse.nodered.org/t/only-send-msg-when-some-input-data-has-had-value-for-amount-of-time/43727 "2021-04-05T21:02:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![menloperk](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@menloperk](https://discourse.nodered.org/u/menloperk)\
**Post date:** [5 April 2021 21:02 UTC](https://discourse.nodered.org/t/only-send-msg-when-some-input-data-has-had-value-for-amount-of-time/43727/1 "2021-04-05T21:02:00Z")

</div>

I am quite a newbie to Node-Red but until now have extremely enjoyed working with it. So my apologies if I am not using the right terminology...

My flow is involving reading/writing Modbus registers but the question is more generic.  
Anyway, I am reading some Modbus registers as input and need to write some other Modbus registers as output. Now I am looking for a way to send a certain Modbus register only after a certain input register has had a certain value for a configurable amount of time. This to prevent the output register from going on and off continuously.  
Another application of this is letting screens go down only after lux value outside has been greater than e.g. 10,000 lux for 5 minutes. This to prevent screens going up and down when it is cloudy and lux values are flickering around 10,000 lux. Many other applications can be though of.  
I bet there is a generic node or pattern that can be applied here.

Thanks for your help!

---

<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:** [5 April 2021 21:29 UTC](https://discourse.nodered.org/t/only-send-msg-when-some-input-data-has-had-value-for-amount-of-time/43727/2 "2021-04-05T21:29:25Z")

</div>

Take a look at the trigger node. and switch node. Here is an example.

```auto
[{"id":"7d2819b0.323798","type":"inject","z":"5a245aa1.510164","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"12000","payloadType":"num","x":80,"y":4120,"wires":[["4fde099.51c9878"]]},{"id":"4fde099.51c9878","type":"switch","z":"5a245aa1.510164","name":"","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"10000","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":260,"y":4140,"wires":[["d69c1ead.fe77b8"],["e948945f.d48328"]]},{"id":"9a987a64.59ba38","type":"inject","z":"5a245aa1.510164","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"8000","payloadType":"num","x":70,"y":4160,"wires":[["4fde099.51c9878"]]},{"id":"d69c1ead.fe77b8","type":"trigger","z":"5a245aa1.510164","name":"","op1":"","op2":"","op1type":"nul","op2type":"pay","duration":"5","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":470,"y":4120,"wires":[["af74e4d3.4aaa78"]]},{"id":"e948945f.d48328","type":"change","z":"5a245aa1.510164","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":4200,"wires":[["d69c1ead.fe77b8","af74e4d3.4aaa78"]]},{"id":"af74e4d3.4aaa78","type":"debug","z":"5a245aa1.510164","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":670,"y":4140,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [5 April 2021 21:33 UTC](https://discourse.nodered.org/t/only-send-msg-when-some-input-data-has-had-value-for-amount-of-time/43727/3 "2021-04-05T21:33:32Z")

</div>

![nIP94EMpyA](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/4/945771f4c8ffaab006a014631dd38eabfaa85579.gif)

```auto
[{"id":"1fd089dc.ad6506","type":"inject","z":"942b70c6.58cc6","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"lux","payload":"9999","payloadType":"num","x":908,"y":608,"wires":[["5bec8c36.863ac4"]]},{"id":"8d81fc99.7e288","type":"inject","z":"942b70c6.58cc6","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"lux","payload":"10001","payloadType":"num","x":908,"y":656,"wires":[["5bec8c36.863ac4"]]},{"id":"e1239785.6f8388","type":"inject","z":"942b70c6.58cc6","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"lux","payload":"12000","payloadType":"num","x":908,"y":704,"wires":[["5bec8c36.863ac4"]]},{"id":"19274e27.97e3b2","type":"inject","z":"942b70c6.58cc6","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"lux","payload":"8000","payloadType":"num","x":908,"y":560,"wires":[["5bec8c36.863ac4"]]},{"id":"5bec8c36.863ac4","type":"switch","z":"942b70c6.58cc6","name":">= 10000 ? ","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"10000","vt":"num"},{"t":"lt","v":"10000","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":1108,"y":624,"wires":[["7884ed7d.9262d4"],["a46590d4.c19c3"]]},{"id":"7884ed7d.9262d4","type":"change","z":"942b70c6.58cc6","name":"Send true","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":1276,"y":592,"wires":[["882c1b98.5958f8"]]},{"id":"a46590d4.c19c3","type":"change","z":"942b70c6.58cc6","name":"Send reset","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"},{"t":"set","p":"topic","pt":"msg","to":"reset","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1286,"y":656,"wires":[["882c1b98.5958f8"]]},{"id":"882c1b98.5958f8","type":"trigger","z":"942b70c6.58cc6","name":"","op1":"","op2":"open sesame","op1type":"nul","op2type":"str","duration":"5","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":1482,"y":624,"wires":[["e84f4530.96a458"]]},{"id":"e84f4530.96a458","type":"debug","z":"942b70c6.58cc6","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1648,"y":624,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![menloperk](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@menloperk](https://discourse.nodered.org/u/menloperk)\
**Post date:** [5 April 2021 21:34 UTC](https://discourse.nodered.org/t/only-send-msg-when-some-input-data-has-had-value-for-amount-of-time/43727/4 "2021-04-05T21:34:51Z")

</div>

Thanks guys! Wonderful!!

---

<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:** [4 June 2021 21:35 UTC](https://discourse.nodered.org/t/only-send-msg-when-some-input-data-has-had-value-for-amount-of-time/43727/5 "2021-06-04T21:35:48Z")

</div>

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