Node-Red Boolean Logic


Introduction to Node-Red Boolean Logic

Node-Red Boolean Logic is very simple to use. Regardless of your knowledge level, it’s usually simpler to state our logic goals in plain English. Undoubtedly, we might be able to accomplish some logic tasks with a function node. However, the Boolean Logic nodes allows us to have multiple inputs to determine what our output will be. The Boolean Logic node supports 3 operations, AND, OR, and XOR (Exclusive OR). In this example, I’m just using 2 input topics, but you can change that in the node’s configuration to reflect the number of inputs that you need for each operation.

AND Operation

While it may be intuitive to some people what the purpose of the AND gate is, others struggle when using it with logic. For example, let’s say we have 2 inputs. When using an AND gate, both inputs must be high. In other words, lets say we have the Garage Door Up Limit Switch and a Night Mode bit. Because I don’t want my garage door to be up at night, I might send a true state to the garage door opener to shut the door. To rephrase it as an if… then… statement: If the Garage Door is up AND it’s Night time, then turn on the output.

Here is an example of utilizing 2 inputs from a ControlLogix using the Eth-IP node. We’ll use a debug node to display the output.

The configuration of the Boolean Logic node is as follows:

Coupled with our node layout, we can see the result.

If one of those conditions are false, then the result will be false.

OR Operation

Conversely, the OR node sends a TRUE output when any of the inputs are true. For example: We have two (or more) motion detectors. When ANY of the motion detectors are tripped, we want the output to go true. Again, it’s usually easier to put this into plain English before writing the logic. In this case, we would say: If North Motion Detector OR South motion detector is true, then energize the output. Let’s look at the flow. Obviously, I’ve changed the operation of the node to OR.

As you can see, if any one of the motion sensors are tripped (or both) then our output goes true.

XOR (Exclusive OR) Operation

Although you don’t use the XOR much in home automation projects, there are some uses for it. With an XOR, the output is true only if ONE and ONLY one of the inputs are true. A real life example of this might be to limit a function if we have a stuck push button. For example: We have 2 push buttons on both sides of the room to turn a light on. Only one should go true at any time. Needless to say, it might take some other logic to get this example to work the way you want, here is an example of the XOR.

If the North OR South pushbuttons are made, we get a true output. Conversely, if both switches are made (or no switches), then our output is false.

Summary of Node-Red Boolean Logic

To summarize, with the AND gate, all inputs must be true for the output to be true. When using an OR gate, only ONE or more conditions must be true for the output to be on. With the Exclusive OR (XOR), One and ONLY one condition must be true to get a true output.

For more information about Node-Red, visit the Node-Red Category Page!

— Ricky Bryce

For Customized automation training, visit my employer's website at http://atifortraining.com!

Leave a comment

Your email address will not be published. Required fields are marked *

five × one =