I have a function which extracts a value from a msg.status.text. The msg.status.text consists of for example Warm White Level 76. The same for red, green, and blue. The function then sends the value (76 in this case to output 4) to 4 different outputs, depending on colour. That all works. But, when the colour is set to 0, the inputting device sends a msg.status.text "Off". With the function as is, the output then is undefined. I need the output of the function msg.status.text to be "Off" in this case.
So a example of a complete incoming debug:
This is in my function node
var stairsred = flow.get('stairsred') || 0;
var stairsgreen = flow.get('stairsgreen') || 0;
var stairsblue = flow.get('stairsblue') || 0;
var stairswhite = flow.get('stairswhite') || 0;
var name;
name = msg.status.source.name;
let match = msg.status.text.match(/([\d]+)/);
if (match && match.length > 1) {
msg.payload = Number(match[1])
}
if (name == "Red Channel") {
stairsred = msg.payload;
flow.set('stairsred', stairsred);
var msg1 = { payload: msg.payload };
} else if (name == "Green Channel") {
stairsgreen = msg.payload;
flow.set('stairsgreen', stairsgreen);
var msg2 = { payload: msg.payload };
} else if (name == "Blue Channel") {
stairsblue = msg.payload;
flow.set('stairsblue', stairsblue);
var msg3 = { payload: msg.payload };
} else if (name == "White Channel") {
stairswhite = msg.payload;
flow.set('stairswhite', stairswhite);
var msg4 = { payload: msg.payload };
}
return [msg1, msg2, msg3, msg4];
I am trying to a learn and b simplyfy a working solution, with a switch node and 4 function nodes (one for each colour) containing
let match = msg.status.text.match(/([\d]+)/)
if (match && match.length > 1) {
msg.payload = Number(match[1])
return msg;
}
this does return msg.status.text "Off". I am not sure I understand why my new function doesnt..