Best practice on handling two states

I have two states (person 1 home/away, person 2 home/away). I would like to create a function or something similar that can take the two states in concideration.

Something like:

if (person 1 = home or person 2 = home ) {
//do something
} else {
// do something else

I was thinking the join function might do the work but I do not know how to create the logic if this is the right choice.

Any help is appriciated

Have you considered the "switch" node ?

The swich node can only take one input right?, I have two inputs

Found a solution, using join node and then after using the switch node, creating 4 scenarios. Works fine, but maybe there is a smarter way?

If the 2 states or not stored in the message (payload) then

  1. I would store them in a flow context variable.
  2. Each time one of the 2 states should be updated, you update the respective flow context variable (e.g. in a change node) and then you route that to the switch node (that is doings the switch based on the values of the 2 context variables).

Not sure what you mean by that, you should be able to do it with a Join and two Switches, though I would probably use a Join and a Function.

There's two people each with two states so that gives 4 scenarios

There are four input scenarios but only two out.

Actually this can be done in one node using the OR gate from node-red-contrib-bool-gate. That node will do the Join and the OR test for you.

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