0

I am sure it is very easy but I am struggling.

I am trying to use a button as an indicator on the Node-Red Dashboard from a Modbus TCP connection as the picture shows:

enter image description here

The formula in the function is as follows:

if (msg.payload === 28){
    msg.colour = "green";
    msg.background ="red";
    return msg;}
else{msg.colour ="white";
return msg;}

However the button on my dashboard does not change colour.

Can anyone here help please?

I am open to other suggestions to make an indicator in Node-Red's dashboard.

EDIT I have edited the typo.

Infernez
  • 73
  • 7

1 Answers1

3
  1. Make sure you have configured the ui_button node's Colour field to be {{msg.colour}} and Background to be {{msg.background}}. That tells the node what msg properties to look for to set those fields.

  2. Fix the typo in your function - you are setting msg.backgroud not msg.background

knolleary
  • 9,777
  • 2
  • 28
  • 35
  • With regards to 1. I made the amendments and still no colour change... while also amending the typo as you spotted - thank you. Either of these haven't yet solved the problem for me, is the rest of the code correct? – Infernez Jun 22 '18 at 09:25
  • 1
    Are you certain that the incoming msg.payload is a number not a string? Using '===' for the check means the type has to be right as well as the value. Use a debug node to confirm the type of the payload you are receiving. – knolleary Jun 22 '18 at 10:06
  • 1
    Add a Debug node after the Function to confirm you are actually passing a message to the button node. Set the node to show the complete message so you can also confirm the values are as you expect. If that is the case, then please add a screenshot of your button's edit dialog so we can see how exactly it is configured. – knolleary Jun 22 '18 at 12:16
  • @Knollery - I solved the problem, after further inspection I believe it was a string, thus chanign the three '===' to one '=' has solved my problem, thank you for the help. – Infernez Jun 25 '18 at 08:04
  • @Infernez a single `=` is an assignment not a test, so you are not comparing, you are setting. To test it needs to be `==` – hardillb Jun 25 '18 at 14:52