Drop messages if not consecutive false

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.

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.

[{"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.

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

[{"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"]]}]
2 Likes

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

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

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

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