How to set a specific topic to the output of a function node

Hi,
how can i set the function node to get a specific topic for the calculated output ? e.g.: "Wert"

or much better to get only the result of the calclation, and only if both topics are loaded?

if (msg.topic === "bezug") context.set("W1",msg.payload);
if (msg.topic === "pvplus") context.set("W2",msg.payload);

var W1 = context.get("W1") || 0;
var W2 = context.get("W2") || 0;

msg.payload = W2 - W1;
return msg;

[{"id":"f666d9b2662603c9","type":"inject","z":"6b7503f72b16f50f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"bezug","payload":"42","payloadType":"num","x":120,"y":100,"wires":[["823a77b9cbe585d3"]]},{"id":"690bf51451ad3433","type":"inject","z":"6b7503f72b16f50f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"pvplus","payload":"101","payloadType":"num","x":120,"y":180,"wires":[["823a77b9cbe585d3"]]},{"id":"823a77b9cbe585d3","type":"join","z":"6b7503f72b16f50f","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":270,"y":140,"wires":[["1f9983cdfb96e1a1"]]},{"id":"259678b0f2244ed8","type":"change","z":"6b7503f72b16f50f","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"Wert","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":630,"y":140,"wires":[["77c8ae21ad74b861"]]},{"id":"1f9983cdfb96e1a1","type":"change","z":"6b7503f72b16f50f","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.bezug - payload.pvplus","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":140,"wires":[["259678b0f2244ed8"]]},{"id":"77c8ae21ad74b861","type":"debug","z":"6b7503f72b16f50f","name":"debug 258","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":810,"y":140,"wires":[]}]

hey,
the first time i tried to work with a function node ... and it´s still easier to solve with standard nodes :crazy_face:

Yup, it;s often a mistake to just reach for a function node.
And you can combine the two change nodes into one for an even sleeker look.

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