Simple a way to check 6 input

I have 6 input to NR and I like to check if they all are "on" and the set the payload to "all on".
Isn't there a simple node that can do this?

See this article in the cookbook for an example of how to join messages into one object.

Hello funhall,

you could use some simple javascript in a Function node with the Logical Operator AND (&&) to compare all values.

For Example :

let a = "on";
let b = "on";

if ( a === "on" && b === "on" ) { 
msg.payload = "all on"
return msg;
}
else {
return null;   //  dont return anything
}

Yes thanks. But how can I check if they are all true statements?
Sorry for the newbee question

once all your inputs are in one object (after the join) use a function node...

if ( msg.payload.input1 === "on" && msg.payload.input2 === "on" && msg.payload.input3 === "on" /*  etc etc etc */) { 
  msg.payload = "all on";
} else {
  msg.payload = "not all on";
}
return msg;

thanks. but how do I get the payload in to the a and b??

Steve gave you a more straight forward example :wink:

Thanks so much for your help. But I cant get it to work.
Somethings wrong with the payload.
But maybe it is possible to check the Global. variable in the function node directly.

I found a solution. Thanks guys

if ( global.get("kisteexit") === "closed" && global.get("kistestate") === "closed" && global.get("doorroom2") === "closed" ) { 
  msg.payload = "all on";
} else {
  msg.payload = "not all on";
}
return msg;
2 Likes

Had you given even the slightest clue that the values were stored in the context then you would have received more helpful responses.

1 Like

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