I am seeing this error:
{"message":"TypeError: msg.payload.split is not a function","source":{"id":"3445206e.094b08","type":"function","name":"ADD values","count":1}}
Ok....
Just before this node is a change
node:
[{"id":"f901977f.2dbaa8","type":"change","z":"a1911aa3.c45be8","d":true,"name":"get `existing`","rules":[{"t":"set","p":"existing","pt":"msg","to":"LEDSTRIP","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":570,"y":760,"wires":[["3445206e.094b08"]]}]
(It is disabled because the next bit isn't working)
The idea is that I have some addressable RGB LEDs.
When a message comes through to change the colour, it is added to the existing colour.
So, say it is showing 30,0,0
A new message comes to show 0,20,0
The result would be the message becomes 30,20,0
and sent to the LED.
This is the code:
I know I don't like smart commands which compound several into one line.
I am not sure that I am falling into that here.
If so: I didn't mean to do it.
// Get LED number from `payload`
//let led = parseInt(msg.payload.split(",")[1]);
let payload = msg.payload
let blah = payload.split(","[1]);
let led = parseInt(blah);
if (led > 4)
{
// Get RGB values from `payload`
let n_red = parseInt(msg.payload.split(",")[2])
let n_green = parseInt(msg.payload.split(",")[3])
let n_blue = parseInt(msg.payload.split(",")[4])
let existing_value = msg.existing[led];
// Now get existing RGB values.
if (existing_value == undefined)
{
existing_value = "0,0,0";
}
let x_red = parseInt(existing_value.split(",")[0]);
let x_green = parseInt(existing_value.split(",")[1]);
let x_blue = parseInt(existing_value.split(",")[2]);
let red = n_red + x_red;
let green = n_green + x_green;
let blue = n_blue + x_blue;
// node.warn("Values " + n_red + " " + n_green + " " + n_blue);
// node.warn("Stored values " + x_red + " " + x_green + " " + x_blue);
// node.warn("Added values " + red + " " + green + " " + blue);
}
if (msg.payload.who == "All clear")
{
//
// Wipe the alarm LEDs
//
// work needed
}
return msg;