"condition" with 3 input_selects

I have 3 input_select in my hassio that is being set from node red depending on 3 persons home/away state.
(https://bonani.tech/making-home-assistants-presence-detection-not-so-binary-node-red-version/)

Now i wounder how do i make a node that triggers something only when all 3 input_select is set to “away” and nothing else? Maybe i have to use the function node and have some code in it?

Yes, a function node would work another possible solution is to use a trigger-state node with a regex for the entity id, ^input_boolean\.(first_enitity_id|second_enitity_id|third_enitity_id)$ and then make three constraints based on entity_id to see if state equals away.

Not tested but should work as described

This is where a ‘boolean AND node’ would have been useful – if there’s a good one out there ('m using node-red-contrib-boolean-logic but I have to convert HA states to boolean using a function node).

I am working on this right now

1 Like

This is my old flow using a subflow which I called “Anyone Home?”. Each state node halts if ‘home’ or ‘on’. I then use an input_boolean to store if home is occupied.

Then on my main flow, I call the subflow for each events:state change of my device_tracker and input_boolean (for guests) entities.

Screenshot_120318_101128_AM

What i need is actually ability to react if the 3 input_select is in any possible combination of either “Away” or “Extended Away”

input1 - Away
input2 - Away
input3 - Away

input1 - Extended Away
input2 - Away
input3 - Away

input1 - Away
input2 - Extended Away
input3 - Away

input1 - Away
input2 - Away
input3 - Extended Away

input1 - Extended Away
input2 - Extended Away
input3 - Away

input1 - Extended Away
input2 - Away
input3 - Extended Away

input1 - Away
input2 - Extended Away
input3 - Extended Away

input1 - Extended Away
input2 - Extended Away
input3 - Extended Away

See my reply above regarding the subflow. Say the status of your inputs if not ‘Away’ or ‘Extended Away’ is ‘Not Away’, then, do a Halt on ‘Not Away’.

Trigger-node can still work for you just change the constraints to use Regex, .*, for Extended Away and Away

1 Like

This is what i ended up with, not the most streamlined, but it works.


Thanx to @rsuplido and @Kermit

Don’t think you need all the conditions. All you need is:

Then halt on ‘home’ for each:

Screenshot_120318_114316_AM

Then it will not halt on the states “Just Arrived” and Just Left"
(Im sorry but i guess i left those states out in previous posts)
But maybe it’s possible to put Home|Just Arrived|Just Left in the “Halt if” box?

Ah I see now.

Not trying to harp on the issue but it can be done with a single trigger state node

@Kermit, yes for sure. Hopefully as folks get the hang of NR, they get to use more advanced features like javascript on the function node, json, and regex on your case. Your inputs are great though – I learn a lot from them as well.

You can do this easily with the node-red-contrib-bool-gate node.

3 Likes

Wow, that node is super useful for making automations for home assistant, i hope someone clone that one and include it in the “node-red-contrib-home-assistant-websocket” package.

I had to add a “current state” so they all would be triggered when any of the input_select was changed, otherwise the “AND node” would only have the value from the input select that was changed at that moment, and no values from the other input selects.

I don’t think that’s needed. It works fine without the current state nodes.

Check example in Node-RED at “Import > Examples > boolean logic”

EDIT: It looks like it keeps the last state change of each node connected to its input.

If you have 2 persons on “away” and one on “home” and you restart or just press deploy in node red
the “AND node” wont go to TRUE when person nr 3 goes to “away” (not untill all 3 inputs have made a change to either away or extended away, if i dont use the “current state” to read the state from all 3 whenever any input select is triggered.

So as long as you dont press deploy or restart it might work without the “current state”.
But im always tinkering on my main system so i will most likely have it “out of sync” from restarts or deploys.

Try changing the Deploy option to “Modified Nodes”. :wink: