An OR latch for your Node-RED projects

Have you ever encountered the need to do a thing when one of your inputs “goes high”, and then do something else when all of your inputs have “gone low”?

If so, here is a generic solution for Node-RED:

image

The subflow has one input and two outputs. The input expects messages that will be classified according a to a key (default topic), and which will be evaluated according to a value (default payload). The logic is fairly simple:

  • The first time a message is received whose value evaluates to true, the associated value is classified according to the classifier key, and the first output gets the message.
  • Then, all messages are blocked, until every message seen has been classified to evaluate to false. At this point, the message is sent through the second output.

Get the code to import here:

1 Like