I have a message coming into a change node. The message consists of
payload.status "22.4 C" and payload.value "22"
the change node sets payload to payload.status
after the change node, I loose the value. I am trying to use the value in a switch value to split my flow into <21 and >=21
But after the switch node all I see in the debug node is payload "22.4 C", nothing else
Probably better if I explain what I am trying to do.
Temp hot water is sending payload.status "22.4 C" and payload.value "22"
For the dashboard, I need "22.4 C"
But I want to split it into <21 and >22.4, so I can assign different colours (with the 2 set colours change nodes)
I have found a way which works, but that is not very elegant ? It has identical set payload, it just splits before the set payload
or set the payload after the set colours - ie bring it back together then ....
but as the ui widget is just text can you not just specify msg.payload.status in the ui node ?
Since "22.4 C" is a string, you will have to get rid of " C" and convert the value to a floating point number so that you can have different processing according to the value.
Since you need "22.4 C" for your dashboard, probably best to use a new element msg.payload.numericStatus to store the converted value.
If your switch node sets msg.payload to "22.4 C" then it's surely no surprise if it subsequently contains "22.4 C"? You can always put msg.payload.value in a new element msg.value to protect it from your actions.
msg.value is not the same as msg.payload.value.
Yes, that worked ! Makes sense.
I thought of that, and tried but it did not work. I probably made a mistake when I tried.
I set payload to payload.status, then in the same node value to payload.value
But that did not work, the result was only payload showed in the debug
This was the result in debug
The rules in a change node are executed in order. Your first rule changes msg.payload to the value of msg.payload.status. So when you get to the second rule msg.payload.value does not exist as the first rule overwrites msg.payload. Try setting msg.value first then set msg.payload.
Yes that was the problem.
I was trying to convert 22.4 C back to a number with a funcion. I did not get that to work. The is a $number or number function, but when trying to deploy there was always a error. As I managed to solve my problem I dont need to do that any more but would be interesting of how to that for future reference
Number(var) would not work.
you would do
msg.payload.status = parseFloat(msg.payload.status);
to get a float or parseInt(var)
if you want an integer, in a function.
This is usually my go to method for this kind of thing too. It comes in very handy if you're using nodes that can only operate on msg.payload like the split node or some of the community encryption nodes out there.