New so maybe this is simple but I can't seem to figure it out or find it anywhere.
I am reading temperature via MQTT the msg comes as 10th degree C. I want it displayed on my dashboard in F. So first I convert the 10th degree C to C then convert C to F. Issue I have is sometimes my dashboard will show many decimal places and I want it limited to 1 or 2 decimals places.
MQTTin linked to a function linked to a Dashboard Text
This works good to do the conversion but shows to many decimal places at times.
var o = msg.payload
msg.payload = msg.payload /10 * 9 / 5.0 + 32
return msg
This limits the decimal places but then never refreshes whatever temp it was when I deploy stays.
var o = msg.payload
msg.payload = (msg.payload /10 * 9 / 5.0 + 32).msg.toFixed(2);
return msg
This limits the decimal places but then never refreshes whatever temp it was when I deploy stays.
var o = msg.payload
msg.payload = Number((temp /10 * 9 / 5 + 32).toFixed(2));
return msg
I tried a few variations of the above in the formula node but could not get it error free. Probably since I am new I had some typo or missing this or that.
I was wondering what that field could be used for in the dashboard item. So putting the angular pipe there seems to have done the trick. So far it seems to be limited as it should and be updating as it should.
Thank you both as each time I learn a little more.
OK learning something new this is helpful but I have a question.
I added the debug node after the function but that is showing the converted data with all the decimals.
Reason is what worked to limit the decimal places was {{msg.payload|number:1}} in the dashboard test node. So the final transformation is taking place in the dashboard node. I can't seem to figure out how to see this final output in the debug window. I did try to put {{msg.payload|number:1}} in the debug node but did not work out.
You had said "If it isn't updating add a debug node showing what is going to the dashboard and check that update messages are arriving and look right."
So I was trying out what you said so I could learn this so that in the future I could use it to help me if I am having an issue.
But yes right now it seems to be displaying on the dashboard ok.
The reason for adding the debug node was to find out why it was not updating. I assumed that by 'not updating' you meant that the dashboard value was not changing when it should. Is it updating correctly?
Yes originally I was trying to do this rounding in the function node this way.
This limits the decimal places but then never refreshes whatever temp it was when I deploy stays.
var o = msg.payload
msg.payload = (msg.payload /10 * 9 / 5.0 + 32).msg.toFixed(2);
return msg
This limits the decimal places but then never refreshes whatever temp it was when I deploy stays.
var o = msg.payload
msg.payload = Number((temp /10 * 9 / 5 + 32).toFixed(2));
return msg
In this case it would update once and then not again.
I see so you are saying the debug node may have pointed to the issue in the function node of why it was not updating after the first time.
Just another trick, which might help you in the future. With the following function you can debug intermediate results within the function to see, if everything is working well:
node.warn(variable);
This helps me quite often to locate the error, where sth. is going wrong. Furthermore it makes sense to cut bigger coding lines/ transactions in more little pieces. Then it is also easier to locate, which part does not work and makes research easier. If everything is working you can shrink it to a more efficient code line. I tried to do it with your code (a little bit excessive, but to show what I mean):