Function not working after update

Good afternoon

I have a function tat takes the msg.payload with 2 different topics and returns me the diference ont he value.

Previously was working fine but after updating node red now returns me "NAN".

Function is:

if (msg.topic == "/ESP-6/DHT sala/Temperature") {
context.state = msg.payload;

}
if (msg.topic == "/ESP-7/BME280/Temperature") {
context.state2 = msg.payload;

}

temp = (context.state2-context.state);

//msg.payload = parseFloat(temp).toFixed(1);
msg.payload = temp;

return msg;

Do you have some clue what is wrong or why now does not works while previously it was fine?

Thanks in advance

NAN = not a number so check what the values actually are with some logging messages
https://nodered.org/docs/writing-functions#logging-events

Whilst you are on that page you could carry on reading the part about how to store data which changed a while ago. Given you are editing the function node it you might as well edit that as well :slight_smile:
https://nodered.org/docs/writing-functions#storing-data

And also please read this post on sharing code/flows in the forum. It takes just a second to format your code on the forum and it makes it a lot easier for use to read.

I will remake my question.... Do you have any example on a function to make the addition of 2 values received with different topics?

Thanks in advance

image

[{"id":"88596265.43ade8","type":"inject","z":"514a90a5.c7bae8","name":"","topic":"topicA","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":104.5,"y":149,"wires":[["276ef579.9944d2"]]},{"id":"276ef579.9944d2","type":"join","z":"514a90a5.c7bae8","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":281.5,"y":199,"wires":[["6e3d3527.774c9c"]]},{"id":"6d0e421e.c691ac","type":"inject","z":"514a90a5.c7bae8","name":"","topic":"topicB","payload":"2","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":108,"y":252,"wires":[["276ef579.9944d2"]]},{"id":"6e3d3527.774c9c","type":"change","z":"514a90a5.c7bae8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.topicA + payload.topicB","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":454.5,"y":201,"wires":[["b5e86695.593dd8"]]},{"id":"b5e86695.593dd8","type":"debug","z":"514a90a5.c7bae8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":519.5,"y":270,"wires":[]}]
1 Like

Thanks a lot Colin