Function node - simple addition of two values

Hi all,
I'm struggeling with an easy addtition of two valueas in a function node. I'm able to handover flow-variables and send it to a debug node but I'm too stupid to add this two values and hand it over to a dashboard text node. can someone please help me out?

[{"id":"84614ad9.405f98","type":"function","z":"79a8ef90.aeb6f","name":"","func":"var f_pv = flow.get('f_pv');\n\nmsg.pv = f_pv;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":280,"y":600,"wires":[["864775b5.916fa8"]]},{"id":"13f3836a.accb4d","type":"function","z":"79a8ef90.aeb6f","name":"","func":"var f_stromzaehler = flow.get('f_stromzaehler');\n\nmsg.zaehler = f_stromzaehler;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":280,"y":660,"wires":[["36174598.6cb99a"]]},{"id":"864775b5.916fa8","type":"debug","z":"79a8ef90.aeb6f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"pv","targetType":"msg","statusVal":"payload","statusType":"auto","x":480,"y":600,"wires":[]},{"id":"36174598.6cb99a","type":"debug","z":"79a8ef90.aeb6f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"zaehler","targetType":"msg","statusVal":"payload","statusType":"auto","x":490,"y":660,"wires":[]},{"id":"ca0ddf76.42082","type":"inject","z":"79a8ef90.aeb6f","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":620,"wires":[["84614ad9.405f98","13f3836a.accb4d"]]}]

Hi, because you get the flow vars in separate functions you cannot add them together without re-joining them (a join node would do this)

HOWEVER, why bother doing the flow.get twice in two functions - just do it all in one function...

var f_pv = flow.get('f_pv'); 
var f_stromzaehler = flow.get('f_stromzaehler');
msg.pv = f_pv;
msg.zaehler = f_stromzaehler;
msg.payload = f_pv + f_stromzaehler;
return msg;

demo...
image

[{"id":"84614ad9.405f98","type":"function","z":"dd03fa8d.2f4be8","name":"","func":"var f_pv = flow.get('f_pv'); \nvar f_stromzaehler = flow.get('f_stromzaehler');\nmsg.pv = f_pv;\nmsg.zaehler = f_stromzaehler;\nmsg.payload = f_pv + f_stromzaehler;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1220,"y":780,"wires":[["864775b5.916fa8","9851a4ff.e91c18","95da2f8e.6a351"]]},{"id":"864775b5.916fa8","type":"debug","z":"dd03fa8d.2f4be8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"pv","targetType":"msg","statusVal":"payload","statusType":"auto","x":1420,"y":720,"wires":[]},{"id":"ca0ddf76.42082","type":"inject","z":"dd03fa8d.2f4be8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1040,"y":780,"wires":[["84614ad9.405f98"]]},{"id":"9851a4ff.e91c18","type":"debug","z":"dd03fa8d.2f4be8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"zaehler","targetType":"msg","statusVal":"payload","statusType":"auto","x":1430,"y":780,"wires":[]},{"id":"95da2f8e.6a351","type":"debug","z":"dd03fa8d.2f4be8","name":"to Dashboard","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1440,"y":840,"wires":[]}]

Hi Steve,

many thanks for your input, I've tried it but I'm getting this one:
msg.payload : string[30]
"[object Object][object Object]"

show me what you have stored in the flow context for those values....
image

it looks like you have stored the FULL msg instead of just the payload.

flow

so yes, you are storing the full msg object in flow variables.
This is not really desirable for your requirements.

If you save just msg.payload in the flow variable, it will hold the actual value (not the msg) & the function I wrote will work.

aaaaaawesome, thats it.
thanks a lot your glory, have a nice day.

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