I know it's stupid, but I have found allready different 'methods' to control 2 outputs, and for me, none of them work.
What is the idea?
I have 1 input & 2 outputs.
If the input is 'True', I want a '1' on output 1,
if thhe output is 'false', I want a '1' on output 2.
That's all...
I've tried this, but nothing passes the function
var x = msg.payload;
if (x =="TRUE"){
var msg_o = {payload : 1}
return [msg_o, null]}
else if (x =="FALSE"){
var msg_o = {payload : 1}
return [null, msg_o]}
I think my returns, are good, this is what I've found on the node-red functions page
Good tip, I need lower case letters like true and false, but still no result at the end.
var x = msg.payload;
if (x =="true"){
var msg_o = {payload : 1}
return [msg_o, null]}
else if (x =="false"){
var msg_o = {payload : 1}
return [null, msg_o]}
Those are not the string values "true" and "false" - they are boolean values true and false.
So the test you want is
if (x == true) {
which is equivalent to:
if (x) {
All told, you can simplify your function to:
var x = msg.payload;
msg.payload = 1;
if (x) {
return [msg, null]
} else {
return [null, msg]
}
Note how it reuses the msg passed into the function - it is generally a best practise to pass on the message you receive rather than create a new message object as there may be other message properties on it that you want to keep ahold of.