Change colour of button

Hello

I have the following function which is supposed to set a msg.colour payload to a specific colour for a button that the function feeds in the flow.

` var switch_colour = "";
var secondpayload = "";
var thirdpayload = "";

if (msg.payload.solar_systems[0].mode === 0) {
switch_colour = "#1db954";
msg.colour = switch_colour;

} else if ((msg.payload.solar_systems[0].mode === 1)) {
switch_colour = "#1db954";
secondpayload = { colour:{switch_colour}};

} else {
switch_colour = "#ff0000";
thirdpayload = { colour: { switch_colour }};
}

return [msg, secondpayload, thirdpayload];
`
But I am getting the following error: Node tried to send a message of type string

Any idea what I am doing wrong?

Does it make a difference if you declare them as objects?

let secondpayload = {}
let thirdpayload = {}

I don't like the idea of calling them blahpayload since a message != it's payload

let msg3 = {}
msg3.colour = switch_colour

No that didn't do it, now I get an "undefined" in the payload.

Where do you get an undefined payload?
I thought you wanted to set msg.colour? msg.colour is one property, msg.payload is another.

All we know about your flow is

As @jbudd says just change your function to this and it works. I take it that you have set the function node to 3 outputs?

Shouldn't this ...

... be this...

secondpayload = { colour: switch_colour };

... given that you defined ...

let secondpayload = {}

... before (as @jbudd proposed)?

Yes you are correct, I also worked that out a few hours ago :slight_smile: thanks for the reply!

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