IF AND/OR node

Hi,
Basic question : How to do an AND node ? for exemple how to check that my wife AND I are at home ? I’ve seen some example where node are put in serial, ok this should work but the payload msg will be the last checked node, right ?
Is there a node with 2 input and 1 output where we can set the payload output based on the 2 input status.

You can take a look at: NR Palette manager for the following node node-red-contrib-bool-gate. This node(s) have both AND and OR logic functionality.

If you would like to check that you and your wife are not home, you can put the two nodes in series and then use the option in each node “if state” to prevent the message being passed on if the state is not home. (you don’t need the switch node)

Another tip you may find useful is that if you would like the payload output to propagate through nodes you can save it somewhere else using the “state location” option. For example you could change it from msg.payload to msg.mehome and msg.herhome. Then it will be available later in the flow (assuming you don’t overwrite it).

The current state of all HA entities is stored as a global object. In the info panel on the right side you can see all that data by going to context data and refreshing the global section.

For me I usually solve this with just a simple switch node. For sake of argument, based on your picture I’m going to assume you’re checking something like person.me is not equal to home and person.her is not equal to home. You can do that with this JSONata expression:

$globalContext("homeassistant.homeAssistant.states['person.me'].state") != 'home' and 
$globalContext("homeassistant.homeAssistant.states['person.her'].state") != 'home'

Then you can plug that into a switch node like this:

That’s what I usually do. I tend to avoid the Get Entity node just because it creates a lot of extra steps in my flows. If I want a bunch of fields then I’ll probably do it but usually I just want one field so I find a JSONata expression does the job easier.

1 Like

Just use the palette node-red-contrib-boolean-logic, so its easy to set a logical function.

and-function: if all entries are equal to “true”, then the result is “true”. if any entry is “false” the result will be “false”.

Thanks for this, I was not aware of this JSONdata, I 'll dig into it.

Hi,
how do i integrate this AND OR functions into Homeassistants Node-red. I’m a newbi and still learning some how-to’s…

In NodeRed, hit settings (three lines in top right corner), go to “Manage Palette” → Install → type in node-red-contrib-boolean-logic → Install on the palette you want, and confirm choice in the popup.

1 Like

There is actually a better one that is maintained and very responsive to issues

Node red contrib boolean ultimate - it has the added benefit of being able to operate on HAs boolean outputs which vary between on/off 1/0 and Yes/no

Craig

3 Likes

Thanks for this. Looks more complex than it is but when I tried it, it worked wonders for me.