# Drop messages if not consecutive false

**URL:** <https://discourse.nodered.org/t/drop-messages-if-not-consecutive-false/79904>\
**Category:** General\
**Created:** [18 July 2023 13:22 UTC](https://discourse.nodered.org/t/drop-messages-if-not-consecutive-false/79904 "2023-07-18T13:22:02Z")\
**Posts on this page:** 7\
**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:** [18 July 2023 13:22 UTC](https://discourse.nodered.org/t/drop-messages-if-not-consecutive-false/79904/1 "2023-07-18T13:22:02Z")

</div>

Hi,

I have a source which is sending `false` or `true` each 120 seconds. What I need to do is to validate the "`false`" message only if there are 2 consecutive "`false`", the first one should be dropped. It looks trivial, but I can't get it done.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [18 July 2023 13:54 UTC](https://discourse.nodered.org/t/drop-messages-if-not-consecutive-false/79904/2 "2023-07-18T13:54:12Z")

</div>

Here is one way, saving the payload in a context variable.  
True payloads pass directly to the output. A False payload only passes if the previous payload was False.

 ![Untitled 1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/9/f98f6e76664be55a13579b49ac5eae76ab019a28.jpeg)

```auto
[{"id":"a465183f434436a6","type":"inject","z":"03d21a528957832c","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":110,"y":400,"wires":[["6f07492c9b9853c3","67e5bd8a80ce596b"]]},{"id":"3fdf19f46b61f0dd","type":"inject","z":"03d21a528957832c","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":110,"y":500,"wires":[["b4037c59b6221cb1","4913370de576ca86"]]},{"id":"b4037c59b6221cb1","type":"change","z":"03d21a528957832c","name":"","rules":[{"t":"set","p":"lastpayload","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":460,"wires":[[]]},{"id":"6f07492c9b9853c3","type":"switch","z":"03d21a528957832c","name":"flow.lastpayload == false?","property":"lastpayload","propertyType":"flow","rules":[{"t":"false"}],"checkall":"true","repair":false,"outputs":1,"x":490,"y":400,"wires":[["4913370de576ca86"]]},{"id":"4913370de576ca86","type":"debug","z":"03d21a528957832c","name":"debug 392","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":690,"y":500,"wires":[]},{"id":"67e5bd8a80ce596b","type":"delay","z":"03d21a528957832c","name":"","pauseType":"delay","timeout":"50","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":270,"y":440,"wires":[["b4037c59b6221cb1"]]}]

```

The delay node is unwieldy, I can't think of a good way to eliminate it.

---

<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:** [18 July 2023 14:02 UTC](https://discourse.nodered.org/t/drop-messages-if-not-consecutive-false/79904/3 "2023-07-18T14:02:00Z")

</div>

This does not do exactly what you asked, but instead passes on the false message if 122 seconds pass without a `true` coming in.

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

```auto
[{"id":"a1b1c942e1699b7e","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":90,"y":2360,"wires":[["4dd73bae6357f3f4"]]},{"id":"7d608c2ab008b810","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":90,"y":2420,"wires":[["4dd73bae6357f3f4"]]},{"id":"f61ebdd8830f9fa5","type":"trigger","z":"bdd7be38.d3b55","name":"","op1":"","op2":"false","op1type":"nul","op2type":"bool","duration":"122","extend":false,"overrideDelay":false,"units":"s","reset":"true","bytopic":"all","topic":"topic","outputs":1,"x":410,"y":2420,"wires":[["c769f3649cf7fd81"]]},{"id":"c769f3649cf7fd81","type":"debug","z":"bdd7be38.d3b55","name":"debug 99","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":580,"y":2380,"wires":[]},{"id":"4967cab51829b4cb","type":"switch","z":"bdd7be38.d3b55","name":"true?","property":"payload","propertyType":"msg","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":390,"y":2360,"wires":[["c769f3649cf7fd81"]]},{"id":"4dd73bae6357f3f4","type":"junction","z":"bdd7be38.d3b55","x":240,"y":2400,"wires":[["f61ebdd8830f9fa5","4967cab51829b4cb"]]}]

```

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [18 July 2023 14:14 UTC](https://discourse.nodered.org/t/drop-messages-if-not-consecutive-false/79904/4 "2023-07-18T14:14:01Z")

</div>

Ohh that's neat.  
The trigger node does not pass on a true payload because it's the reset value.

---

<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:** [18 July 2023 14:37 UTC](https://discourse.nodered.org/t/drop-messages-if-not-consecutive-false/79904/5 "2023-07-18T14:37:08Z")

</div>

In the real world case, do not the true and false come down the same wire?

---

<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:** [18 July 2023 14:50 UTC](https://discourse.nodered.org/t/drop-messages-if-not-consecutive-false/79904/6 "2023-07-18T14:50:36Z")

</div>

Yes, they do. Indeed, I have added the switch node.

---

<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:** [1 August 2023 14:51 UTC](https://discourse.nodered.org/t/drop-messages-if-not-consecutive-false/79904/7 "2023-08-01T14:51:15Z")

</div>

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