Help with button node

I´m using the basic funktions of ui_button node.
Now, I would like to change the colours, depending on the payload (number)

I set {{msg.color}} for backround at node-settings and

if (msg.payload === "1")
msg.color = "red"
msg.color = "green"
return msg;

...but it doesen´t work, nothing happens ....

Who can help me ? Thank you :slight_smile:

You can use {{msg.payload === "1" ? "red" : "green"}} in the input field.

[{"id":"100cd33cf6549c9d","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"str","x":190,"y":4520,"wires":[["fe614182e7e4e3c5"]]},{"id":"6dc91614bdaefc3c","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"str","x":190,"y":4580,"wires":[["fe614182e7e4e3c5"]]},{"id":"fe614182e7e4e3c5","type":"ui_button","z":"d1395164b4eec73e","name":"","group":"4f791fdc1745d3d9","order":3,"width":0,"height":0,"passthru":false,"label":"button","tooltip":"","color":"","bgcolor":"{{msg.payload === \"1\" ? \"red\" : \"green\"}}","className":"","icon":"","payload":"","payloadType":"str","topic":"topic","topicType":"msg","x":350,"y":4540,"wires":[[]]},{"id":"4f791fdc1745d3d9","type":"ui_group","name":"micro","tab":"c954274bbed7292e","order":1,"disp":false,"width":"18","collapse":false,"className":""},{"id":"c954274bbed7292e","type":"ui_tab","name":"Solar","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

hi @ak68 , welcome to the forum.

I assume you are using node-red-dashboard, AKA Dashboard 1 rather than @flowfuse/node-red-dashboard AKA Dashboard 2?

Is the payload a number or a string?

Because this tests if it is the string "1" not the number 1

You can use a debug node to test which it is and maybe share the output with us.

Another debug node to show what value msg.color has coming out of your function node would be useful too.

According to the button node documentation, you can set the background colour with {{color}} not {{msg.color}}

Is this what you have?

Edit - I like @E1cid's little snippet, but you still need to be sure if the payload is a string or a number.

Unless you use == instead.
{{msg.payload == "1" ? "red" : "green"}}

Thank you very much,
it seems to be a number and works now on this way:

{{msg.payload === 1 ? "red" : "green"}}