Adding a payload to a varible

I am trying to take an input payload and add to it a varible that is stored and output a combined value using a function node with the following:

msg.payload = msg.payload + flow.delay
return msg;

But i get a debug output of "NaN"

One of those values must not be a number, maybe its a string that looks like a number ? We can't tell from the information given. You'll have to add debug to show us the values it is trying to add.

Here is what I have, the problemis the "add" function node, it can't seem to get the flow.delay varible to add that is set in the top flow, if you change both numeric inputs the you should get a new value that combine them in th edebug on the "add" function node:

[{"id":"4f215bbb.29d7f4","type":"function","z":"4f2cae6a.c5ec8","name":"add","func":"msg.payload = msg.payload + (flow.delay/1000)\nreturn msg;","outputs":1,"noerr":0,"x":750,"y":480,"wires":[["abbcbdc2.d3d13","9d49a70f.862808"]]},{"id":"eb8e781f.3f2548","type":"inject","z":"4f2cae6a.c5ec8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":"3","x":90,"y":440,"wires":[["fdff23af.dcc9","a1b34093.96a85"]]},{"id":"fdff23af.dcc9","type":"file in","z":"4f2cae6a.c5ec8","name":"load delay","filename":"water_delay","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":250,"y":440,"wires":[["cde19d5b.bf893"]]},{"id":"a1b34093.96a85","type":"file in","z":"4f2cae6a.c5ec8","name":"load interval","filename":"water_interval","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":250,"y":480,"wires":[["484e3ba1.aa4e54"]]},{"id":"cde19d5b.bf893","type":"ui_numeric","z":"4f2cae6a.c5ec8","name":"Water time","label":"Water time (mins)","tooltip":"","group":"a92077cf.7a28e8","order":5,"width":0,"height":0,"wrap":false,"passthru":true,"topic":"","format":"{{value}}","min":"1","max":"15","step":1,"x":410,"y":440,"wires":[["f59c944f.33db88"]]},{"id":"484e3ba1.aa4e54","type":"ui_numeric","z":"4f2cae6a.c5ec8","name":"","label":"Water interval","tooltip":"","group":"a92077cf.7a28e8","order":4,"width":0,"height":0,"wrap":false,"passthru":true,"topic":"","format":"{{value}}","min":"0","max":"720","step":"5","x":420,"y":480,"wires":[["68f823d7.50888c"]]},{"id":"f59c944f.33db88","type":"file","z":"4f2cae6a.c5ec8","name":"Save delay","filename":"water_delay","appendNewline":false,"createDir":false,"overwriteFile":"true","encoding":"none","x":570,"y":440,"wires":[["c75e159.7e557e8"]]},{"id":"68f823d7.50888c","type":"file","z":"4f2cae6a.c5ec8","name":"save interval","filename":"water_interval","appendNewline":false,"createDir":false,"overwriteFile":"true","encoding":"none","x":590,"y":480,"wires":[["4f215bbb.29d7f4"]]},{"id":"c75e159.7e557e8","type":"function","z":"4f2cae6a.c5ec8","name":"Multiplier","func":"msg.payload = msg.payload *1000\nreturn msg;","outputs":1,"noerr":0,"x":740,"y":440,"wires":[["6eadcd45.8a6574"]]},{"id":"abbcbdc2.d3d13","type":"debug","z":"4f2cae6a.c5ec8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":750,"y":380,"wires":[]},{"id":"6eadcd45.8a6574","type":"change","z":"4f2cae6a.c5ec8","name":"","rules":[{"t":"set","p":"delay","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":940,"y":440,"wires":[["6f96ee9e.484cd"]]},{"id":"9d49a70f.862808","type":"change","z":"4f2cae6a.c5ec8","name":"","rules":[{"t":"set","p":"delay1","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":940,"y":480,"wires":[["3b11b096.22ec5"]]},{"id":"6f96ee9e.484cd","type":"debug","z":"4f2cae6a.c5ec8","name":"","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":1170,"y":440,"wires":[]},{"id":"3b11b096.22ec5","type":"debug","z":"4f2cae6a.c5ec8","name":"","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":1170,"y":500,"wires":[]},{"id":"a92077cf.7a28e8","type":"ui_group","z":"","name":"#1","tab":"7dd97b74.960734","order":2,"disp":true,"width":"6","collapse":false},{"id":"7dd97b74.960734","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

That isn't how you retrieve flow context variables in a function - see the Storing data section of the docs https://nodered.org/docs/user-guide/writing-functions#Storing-data

hint flow.get("delay")

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.