I've got a sense hat for my Pi 3b+ and want to add a simple minus operation to the temperature sensor on the hat as kind of a correction factor. Basically (temperature - 5) = CorrectedTemp.
Not sure how to put the code into the function node.
This is how the function node looks like now:
var o = msg.payload
msg.payload = o.temperature
return msg;
Function nodes are JavaScript running in a Node.JS VM. See the Mozilla Development Network website for more help on JavaScript than you could ever imagine!
Node-RED is a great way to get into JavaScript as you can let various nodes take care of the difficult, complex bits leaving you to think about specific bits of logic.
It works fine with the gauge node as it allows me to set Value format and specify the number of decimals. Unfortunately the chart node does not have the option to specify the precision and when hover over into the chart, it displays all decimals. Not a big deal, but doesn't look nice.
Any other suggestions to get rid of the decimals at the output/display level for a chart node?
I don't know much about the chart node. It may be that you have to format it in a function node or similar first. Possibly a bit of a deficiency in the chart node.
Your payload is not a decimal number 16.25 but is the string "16.25". When you add something to a string it uses string concatenation so it adds a 2 to the end. Try replacing the first line with var x = Number(msg.payload)
Actually in a situation like this you should be using const x = rather than var which tells the interpretor that x will not be modified after initial setup which may allow the interpretor to generate more efficient code.