Adding 2 Msg.payloads numbers

Hi there,

I am currently having trouble with adding 2 numbers in the dashboard. Is there a explained way to do this?

Essentially I am just trying to add 2 msg.payloads values together, to give 1 msg.payload

Ex. 120 First msg 121 second msg = 241 total.

These numbers are being updated every 5 seconds.

The only thing Ive seen similar to what Im trying to do is below:

// store pid/temperature in flow context
if (msg.hasOwnProperty("pid")) {
flow.set('pid', msg.pid);
} else if (msg.hasOwnProperty("temperature")) {
flow.set('temperature', msg.temperature);
}

// get the latest values of pid/temperature from context - default to 0 if not yet set
var pid = flow.get('pid') || 0;
var temperature = flow.get('temperature') || 0;
msg.payload = pid+temperature;
return msg

Can anyone assist me? When I tried to change the variables in the above, it did not work for me.

If you need more of an explanation, I'll try my best to explain it in more detail.

Thanks

Why have you started a new thread for basically the same question? [1]
As was explained there you can use a Join node.

[1] 2 msg.topic in calculation function node

I don't understand why it is not working for you, here's a flow with exactly your function and 2 inputs: 1 where msg.pid = 5 and the other where msg.temperature = 10 and the output is 15
Maybe one of your inputs is a string instead of a number? Put some debug nodes

[
    {
        "id": "86a79d62.a1836",
        "type": "inject",
        "z": "143ac8d4.56de37",
        "name": "",
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 380,
        "y": 540,
        "wires": [
            [
                "e8c36fa1.33cef"
            ]
        ]
    },
    {
        "id": "e8c36fa1.33cef",
        "type": "change",
        "z": "143ac8d4.56de37",
        "name": "msg.pid = 5",
        "rules": [
            {
                "t": "set",
                "p": "pid",
                "pt": "msg",
                "to": "5",
                "tot": "num"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 550,
        "y": 540,
        "wires": [
            [
                "e2c5d677.1a3458"
            ]
        ]
    },
    {
        "id": "e2c5d677.1a3458",
        "type": "function",
        "z": "143ac8d4.56de37",
        "name": "",
        "func": "// store pid/temperature in flow context\nif (msg.hasOwnProperty(\"pid\")) {\nflow.set('pid', msg.pid);\n} else if (msg.hasOwnProperty(\"temperature\")) {\nflow.set('temperature', msg.temperature);\n}\n\n// get the latest values of pid/temperature from context - default to 0 if not yet set\nvar pid = flow.get('pid') || 0;\nvar temperature = flow.get('temperature') || 0;\nmsg.payload = pid+temperature;\nreturn msg",
        "outputs": 1,
        "noerr": 0,
        "x": 730,
        "y": 540,
        "wires": [
            [
                "24c397f9.dd1158"
            ]
        ]
    },
    {
        "id": "1da64086.58464f",
        "type": "inject",
        "z": "143ac8d4.56de37",
        "name": "",
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 380,
        "y": 580,
        "wires": [
            [
                "9e418ce.9689b7"
            ]
        ]
    },
    {
        "id": "9e418ce.9689b7",
        "type": "change",
        "z": "143ac8d4.56de37",
        "name": "msg.temperature = 10",
        "rules": [
            {
                "t": "set",
                "p": "temperature",
                "pt": "msg",
                "to": "10",
                "tot": "num"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 580,
        "y": 580,
        "wires": [
            [
                "e2c5d677.1a3458"
            ]
        ]
    },
    {
        "id": "24c397f9.dd1158",
        "type": "debug",
        "z": "143ac8d4.56de37",
        "name": "5 + 10 = 15",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "x": 870,
        "y": 540,
        "wires": []
    }
]

Hello ,

I'm also facing similar issue when adding 2 numbers published (1 OR 0 ) via MQTT with different topics but related.

When I search I found the answer given and yes it did work for me. Thanks for this.

But in my case it is a little bit different and my flow is as below. What I expect is the answer to be "2" after the function node "add". Seems like I have missed something or I'm wondering what it is since there are no errors even in the debug panel.

[{"id":"9dfc02ab.6293b","type":"tab","label":"test - adding 2 msgs","disabled":false,"info":""},{"id":"ce0c975e.9668d8","type":"mqtt in","z":"9dfc02ab.6293b","name":"","topic":"dist/#","qos":"0","broker":"3c3fb13.ddcbc4e","x":130,"y":300,"wires":[["5f07dc1a.8fb864","aa9be2c6.1d971"]]},{"id":"5f07dc1a.8fb864","type":"debug","z":"9dfc02ab.6293b","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":330,"y":240,"wires":[]},{"id":"af0f6bb7.b8ceb8","type":"comment","z":"9dfc02ab.6293b","name":"Subscriber","info":"","x":120,"y":220,"wires":[]},{"id":"ba43bb4b.021c68","type":"function","z":"9dfc02ab.6293b","name":"add","func":"var v1value;\nvar v2value;\nvar total;\n\nif (msg.topic == \"dist/v1/SS1\") {\n    v1value = msg.payload;\n}else if (msg.topic == \"dist/v2/SS1\"){\n    v2value = msg.payload;\n}\n\ntotal = v1value + v2value;\n\nreturn total;","outputs":1,"noerr":0,"x":450,"y":360,"wires":[["9d6af808.bcaa28"]]},{"id":"7628b403.974e0c","type":"debug","z":"9dfc02ab.6293b","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":710,"y":400,"wires":[]},{"id":"5f4fe45.69ace1c","type":"debug","z":"9dfc02ab.6293b","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":470,"y":60,"wires":[]},{"id":"e6f78031.4a8e3","type":"mqtt out","z":"9dfc02ab.6293b","name":"","topic":"","qos":"0","retain":"","broker":"6d77e5a8.188d4c","x":450,"y":100,"wires":[]},{"id":"fd35ac4c.8d649","type":"inject","z":"9dfc02ab.6293b","name":"","topic":"dist/v1/SS1","payload":"1","payloadType":"num","repeat":"1","crontab":"","once":true,"onceDelay":0.1,"x":140,"y":60,"wires":[["e6f78031.4a8e3","5f4fe45.69ace1c"]]},{"id":"9d6af808.bcaa28","type":"debug","z":"9dfc02ab.6293b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":710,"y":280,"wires":[]},{"id":"9075e313.88196","type":"debug","z":"9dfc02ab.6293b","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":470,"y":480,"wires":[]},{"id":"a506a492.02a508","type":"mqtt out","z":"9dfc02ab.6293b","name":"","topic":"","qos":"0","retain":"","broker":"6d77e5a8.188d4c","x":930,"y":80,"wires":[]},{"id":"8d9c5971.7c5058","type":"inject","z":"9dfc02ab.6293b","name":"","topic":"dist/v2/SS1","payload":"1","payloadType":"num","repeat":"1","crontab":"","once":true,"onceDelay":"0.2","x":680,"y":80,"wires":[["a506a492.02a508","6252b100.3f9a4"]]},{"id":"6252b100.3f9a4","type":"debug","z":"9dfc02ab.6293b","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":950,"y":140,"wires":[]},{"id":"c965e710.e01b98","type":"switch","z":"9dfc02ab.6293b","name":"","property":"topic","propertyType":"msg","rules":[{"t":"cont","v":"SS1","vt":"str"},{"t":"cont","v":"SS2","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":450,"y":420,"wires":[["7628b403.974e0c"],["b262a4f4.43b5b8"]]},{"id":"49ab8784.00b558","type":"inject","z":"9dfc02ab.6293b","name":"","topic":"dist/v1/SS2","payload":"1","payloadType":"num","repeat":"1","crontab":"","once":true,"onceDelay":0.1,"x":140,"y":100,"wires":[["e6f78031.4a8e3"]]},{"id":"b6a7ff23.61caf","type":"inject","z":"9dfc02ab.6293b","name":"","topic":"dist/v2/SS2","payload":"1","payloadType":"num","repeat":"1","crontab":"","once":true,"onceDelay":"0.2","x":680,"y":120,"wires":[["a506a492.02a508"]]},{"id":"b262a4f4.43b5b8","type":"debug","z":"9dfc02ab.6293b","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":710,"y":440,"wires":[]},{"id":"aa9be2c6.1d971","type":"change","z":"9dfc02ab.6293b","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"1","fromt":"str","to":"1","tot":"num"},{"t":"change","p":"payload","pt":"msg","from":"0","fromt":"str","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":260,"y":400,"wires":[["9075e313.88196","c965e710.e01b98","ba43bb4b.021c68"]]},{"id":"3c3fb13.ddcbc4e","type":"mqtt-broker","z":"","name":"","broker":"test.mosquitto.org","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"6d77e5a8.188d4c","type":"mqtt-broker","z":"","name":"","broker":"test.mosquitto.org","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}] 

Simply I wanna separate message-topic pairs together and I made the function node add with below. Though I'm expecting function node output to be (1+1 =2) there is nothing in the output.

var v1value;
var v2value;
var total;

if (msg.topic == "dist/v1/SS1") {
    v1value = msg.payload;
}else if (msg.topic == "dist/v2/SS1"){
    v2value = msg.payload;
}

total = v1value + v2value;

return total;

I would be much thankful for any suggestion or guidance.
Thank you !

@emspe the key thing to remember is that each message arrives at the Function node as a separate event. Any variables you declare inside the function are reset every time the Function is called. So with your current code, whenever a message arrives, v1value and v2value will both be undefined - regardless of what previous messages have arrived.

One way of dealing with this is to use flow context to store the values between calls to the Function.

var v1value = flow.get("v1value");
var v2value = flow.get("v2value");
var total;

if (msg.topic == "dist/v1/SS1") {
    v1value = msg.payload;
    flow.set("v1value",msg.payload);
}else if (msg.topic == "dist/v2/SS1"){
    v2value = msg.payload;
    flow.set("v2value",msg.payload);
}
if (v1value !== undefined && v2value !== undefined) {
   total = v1value + v2value;
   msg.payload = total;
   return msg;
}
  1. it gets the values from flow context at the start.
  2. depending on the topic, it stores the new value of the appropriate variable in context
  3. if it has values for both of the variables, it adds them, then sets msg.payload and returns msg
  4. otherwise it returns nothing

Note step 3 - your current code is returning the total value. That is not correct as your Function must return a message object.

Also note this will not send anything on until it has received both values. But it will then send on the sum of the values whenever either one updates. If you want it to wait for one message from each topic before sending a new total, you can add the following line just before the return statement.

    flow.set(["v1value", "v2value"],[undefined,undefined]);
2 Likes

Thank you very much @knolleary for the explanation with the example. This helps a lot. :relieved:
I understood it now clearly. Thanks again! :smiley:


I expanded this and trying to visualize the total in dashboard.
But what I experienced was blinking addition ( 1 or 0 / 2 or 1). I added a "topic" to filter and output the total only value. Then I scrutinized and found that there is an unnecessary message arriving under the same topic. I'm thinking of a way of how to get rid of that. :thinking:

tired with different scenarios but the output is confussing.

(received 1or 0 blinking > expected answer 1 ) :

[{"id":"212f7614.f6ee8a","type":"tab","label":"Flow 6","disabled":false,"info":""},{"id":"52f228c.2fd28d8","type":"mqtt in","z":"212f7614.f6ee8a","name":"","topic":"dist2/SS1/#","qos":"0","broker":"3c3fb13.ddcbc4e","x":130,"y":380,"wires":[["64fe8a82.9899a4","47034320.2bcc6c"]]},{"id":"64fe8a82.9899a4","type":"debug","z":"212f7614.f6ee8a","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":310,"y":280,"wires":[]},{"id":"b3897ba4.fe3d38","type":"comment","z":"212f7614.f6ee8a","name":"Subscriber","info":"","x":120,"y":320,"wires":[]},{"id":"d87f761e.3959d8","type":"debug","z":"212f7614.f6ee8a","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":530,"y":280,"wires":[]},{"id":"3c45c4b0.2bb3ec","type":"debug","z":"212f7614.f6ee8a","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":310,"y":240,"wires":[]},{"id":"a5f44083.f70c","type":"debug","z":"212f7614.f6ee8a","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":530,"y":320,"wires":[]},{"id":"2f660b6e.802154","type":"ui_text","z":"212f7614.f6ee8a","group":"255b40a9.5bd09","order":3,"width":0,"height":0,"name":"","label":"SS2","format":"{{msg.payload}}","layout":"row-spread","x":750,"y":420,"wires":[]},{"id":"f725e7cf.c16188","type":"ui_text","z":"212f7614.f6ee8a","group":"255b40a9.5bd09","order":2,"width":0,"height":0,"name":"","label":"SS1","format":"{{msg.payload}}","layout":"row-spread","x":750,"y":380,"wires":[]},{"id":"47034320.2bcc6c","type":"function","z":"212f7614.f6ee8a","name":"add","func":"var v1value = flow.get(\"v1value\");\nvar v2value = flow.get(\"v2value\");\nvar total;\n\nif (msg.topic == \"dist2/SS1/v1\") {\n    v1value = msg.payload;\n    flow.set(\"v1value\",msg.payload);\n}else if (msg.topic == \"dist2/SS1/v2\"){\n    v2value = msg.payload;\n    flow.set(\"v2value\",msg.payload);\n}\nif (v1value !== undefined && v2value !== undefined) {\n   total = parseInt(v1value) + parseInt(v2value);\n   msg.payload = parseInt(total);\n   msg.topic = \"tot\"; \n   flow.set([\"v1value\", \"v2value\"],[undefined,undefined]);\n   return msg;\n}","outputs":1,"noerr":0,"x":310,"y":380,"wires":[["d87f761e.3959d8","1866f3e2.5c167c"]]},{"id":"eadb9876.7f1448","type":"function","z":"212f7614.f6ee8a","name":"add","func":"var v1value = flow.get(\"v1value\");\nvar v2value = flow.get(\"v2value\");\nvar total;\n\nif (msg.topic == \"dist2/SS2/v1\") {\n    v1value = msg.payload;\n    flow.set(\"v1value\",msg.payload);\n}else if (msg.topic == \"dist2/SS2/v2\"){\n    v2value = msg.payload;\n    flow.set(\"v2value\",msg.payload);\n}\nif (v1value !== undefined && v2value !== undefined) {\n   total = parseInt(v1value) + parseInt(v2value);\n   msg.payload = parseInt(total);\n   msg.topic = \"tot\";\n   flow.set([\"v1value\", \"v2value\"],[undefined,undefined]);\n   return msg;\n}","outputs":1,"noerr":0,"x":310,"y":420,"wires":[["a5f44083.f70c","8d8c5134.cd399"]]},{"id":"d139fed6.5d1f2","type":"mqtt in","z":"212f7614.f6ee8a","name":"","topic":"dist2/SS2/#","qos":"0","broker":"3c3fb13.ddcbc4e","x":130,"y":420,"wires":[["eadb9876.7f1448"]]},{"id":"e55a74bf.3cba38","type":"debug","z":"212f7614.f6ee8a","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":410,"y":80,"wires":[]},{"id":"f54b711d.45e48","type":"mqtt out","z":"212f7614.f6ee8a","name":"","topic":"","qos":"0","retain":"","broker":"6d77e5a8.188d4c","x":390,"y":140,"wires":[]},{"id":"e36a1be7.12c2c8","type":"inject","z":"212f7614.f6ee8a","name":"","topic":"dist2/SS1/v1","payload":"1","payloadType":"num","repeat":"1","crontab":"","once":true,"onceDelay":0.1,"x":140,"y":80,"wires":[["f54b711d.45e48","e55a74bf.3cba38"]]},{"id":"4b4f9d72.7ff194","type":"inject","z":"212f7614.f6ee8a","name":"","topic":"dist2/SS2/v1","payload":"0","payloadType":"num","repeat":"1","crontab":"","once":true,"onceDelay":0.1,"x":140,"y":140,"wires":[["f54b711d.45e48"]]},{"id":"2cd70559.96bd6a","type":"debug","z":"212f7614.f6ee8a","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":830,"y":80,"wires":[]},{"id":"d6700a62.b24b58","type":"mqtt out","z":"212f7614.f6ee8a","name":"","topic":"","qos":"0","retain":"","broker":"6d77e5a8.188d4c","x":810,"y":140,"wires":[]},{"id":"38ccb385.9eb6fc","type":"inject","z":"212f7614.f6ee8a","name":"","topic":"dist2/SS1/v2","payload":"0","payloadType":"num","repeat":"2","crontab":"","once":true,"onceDelay":"0.5","x":620,"y":80,"wires":[["d6700a62.b24b58","2cd70559.96bd6a"]]},{"id":"7886a92c.fc4888","type":"inject","z":"212f7614.f6ee8a","name":"","topic":"dist2/SS2/v2","payload":"0","payloadType":"num","repeat":"2","crontab":"","once":true,"onceDelay":"0.5","x":620,"y":140,"wires":[["d6700a62.b24b58"]]},{"id":"8d8c5134.cd399","type":"switch","z":"212f7614.f6ee8a","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"tot","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":530,"y":420,"wires":[["2f660b6e.802154"]]},{"id":"1866f3e2.5c167c","type":"switch","z":"212f7614.f6ee8a","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"tot","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":530,"y":380,"wires":[["f725e7cf.c16188"]]},{"id":"3c3fb13.ddcbc4e","type":"mqtt-broker","z":"","name":"","broker":"test.mosquitto.org","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"255b40a9.5bd09","type":"ui_group","name":"Group 1","tab":"77e810ca.af734","order":1,"disp":true,"width":6},{"id":"6d77e5a8.188d4c","type":"mqtt-broker","z":"","name":"","broker":"test.mosquitto.org","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"77e810ca.af734","type":"ui_tab","name":"Tab 2","icon":"dashboard","order":2}]


(received SS1 = 2 or 1 blinking > expected answer SS1 = 2 | SS2 = 1 ) :

[{"id":"212f7614.f6ee8a","type":"tab","label":"Flow 6","disabled":false,"info":""},{"id":"52f228c.2fd28d8","type":"mqtt in","z":"212f7614.f6ee8a","name":"","topic":"dist2/SS1/#","qos":"0","broker":"3c3fb13.ddcbc4e","x":130,"y":380,"wires":[["64fe8a82.9899a4","47034320.2bcc6c"]]},{"id":"64fe8a82.9899a4","type":"debug","z":"212f7614.f6ee8a","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":310,"y":280,"wires":[]},{"id":"b3897ba4.fe3d38","type":"comment","z":"212f7614.f6ee8a","name":"Subscriber","info":"","x":120,"y":320,"wires":[]},{"id":"d87f761e.3959d8","type":"debug","z":"212f7614.f6ee8a","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":530,"y":280,"wires":[]},{"id":"3c45c4b0.2bb3ec","type":"debug","z":"212f7614.f6ee8a","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":310,"y":240,"wires":[]},{"id":"a5f44083.f70c","type":"debug","z":"212f7614.f6ee8a","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":530,"y":320,"wires":[]},{"id":"2f660b6e.802154","type":"ui_text","z":"212f7614.f6ee8a","group":"255b40a9.5bd09","order":3,"width":0,"height":0,"name":"","label":"SS2","format":"{{msg.payload}}","layout":"row-spread","x":750,"y":420,"wires":[]},{"id":"f725e7cf.c16188","type":"ui_text","z":"212f7614.f6ee8a","group":"255b40a9.5bd09","order":2,"width":0,"height":0,"name":"","label":"SS1","format":"{{msg.payload}}","layout":"row-spread","x":750,"y":380,"wires":[]},{"id":"47034320.2bcc6c","type":"function","z":"212f7614.f6ee8a","name":"add","func":"var v1value = flow.get(\"v1value\");\nvar v2value = flow.get(\"v2value\");\nvar total;\n\nif (msg.topic == \"dist2/SS1/v1\") {\n    v1value = msg.payload;\n    flow.set(\"v1value\",msg.payload);\n}else if (msg.topic == \"dist2/SS1/v2\"){\n    v2value = msg.payload;\n    flow.set(\"v2value\",msg.payload);\n}\nif (v1value !== undefined && v2value !== undefined) {\n   total = parseInt(v1value) + parseInt(v2value);\n   msg.payload = parseInt(total);\n   msg.topic = \"tot\"; \n   flow.set([\"v1value\", \"v2value\"],[undefined,undefined]);\n   return msg;\n}","outputs":1,"noerr":0,"x":310,"y":380,"wires":[["d87f761e.3959d8","1866f3e2.5c167c"]]},{"id":"eadb9876.7f1448","type":"function","z":"212f7614.f6ee8a","name":"add","func":"var v1value = flow.get(\"v1value\");\nvar v2value = flow.get(\"v2value\");\nvar total;\n\nif (msg.topic == \"dist2/SS2/v1\") {\n    v1value = msg.payload;\n    flow.set(\"v1value\",msg.payload);\n}else if (msg.topic == \"dist2/SS2/v2\"){\n    v2value = msg.payload;\n    flow.set(\"v2value\",msg.payload);\n}\nif (v1value !== undefined && v2value !== undefined) {\n   total = parseInt(v1value) + parseInt(v2value);\n   msg.payload = parseInt(total);\n   msg.topic = \"tot\";\n   flow.set([\"v1value\", \"v2value\"],[undefined,undefined]);\n   return msg;\n}","outputs":1,"noerr":0,"x":310,"y":420,"wires":[["a5f44083.f70c","8d8c5134.cd399"]]},{"id":"d139fed6.5d1f2","type":"mqtt in","z":"212f7614.f6ee8a","name":"","topic":"dist2/SS2/#","qos":"0","broker":"3c3fb13.ddcbc4e","x":130,"y":420,"wires":[["eadb9876.7f1448"]]},{"id":"e55a74bf.3cba38","type":"debug","z":"212f7614.f6ee8a","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":410,"y":80,"wires":[]},{"id":"f54b711d.45e48","type":"mqtt out","z":"212f7614.f6ee8a","name":"","topic":"","qos":"0","retain":"","broker":"6d77e5a8.188d4c","x":390,"y":140,"wires":[]},{"id":"e36a1be7.12c2c8","type":"inject","z":"212f7614.f6ee8a","name":"","topic":"dist2/SS1/v1","payload":"1","payloadType":"num","repeat":"1","crontab":"","once":true,"onceDelay":0.1,"x":140,"y":80,"wires":[["f54b711d.45e48","e55a74bf.3cba38"]]},{"id":"4b4f9d72.7ff194","type":"inject","z":"212f7614.f6ee8a","name":"","topic":"dist2/SS2/v1","payload":"1","payloadType":"num","repeat":"1","crontab":"","once":true,"onceDelay":0.1,"x":140,"y":140,"wires":[["f54b711d.45e48"]]},{"id":"2cd70559.96bd6a","type":"debug","z":"212f7614.f6ee8a","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":830,"y":80,"wires":[]},{"id":"d6700a62.b24b58","type":"mqtt out","z":"212f7614.f6ee8a","name":"","topic":"","qos":"0","retain":"","broker":"6d77e5a8.188d4c","x":810,"y":140,"wires":[]},{"id":"38ccb385.9eb6fc","type":"inject","z":"212f7614.f6ee8a","name":"","topic":"dist2/SS1/v2","payload":"1","payloadType":"num","repeat":"2","crontab":"","once":true,"onceDelay":"0.5","x":620,"y":80,"wires":[["d6700a62.b24b58","2cd70559.96bd6a"]]},{"id":"7886a92c.fc4888","type":"inject","z":"212f7614.f6ee8a","name":"","topic":"dist2/SS2/v2","payload":"0","payloadType":"num","repeat":"2","crontab":"","once":true,"onceDelay":"0.5","x":620,"y":140,"wires":[["d6700a62.b24b58"]]},{"id":"8d8c5134.cd399","type":"switch","z":"212f7614.f6ee8a","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"tot","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":530,"y":420,"wires":[["2f660b6e.802154"]]},{"id":"1866f3e2.5c167c","type":"switch","z":"212f7614.f6ee8a","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"tot","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":530,"y":380,"wires":[["f725e7cf.c16188"]]},{"id":"3c3fb13.ddcbc4e","type":"mqtt-broker","z":"","name":"","broker":"test.mosquitto.org","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"255b40a9.5bd09","type":"ui_group","name":"Group 1","tab":"77e810ca.af734","order":1,"disp":true,"width":6},{"id":"6d77e5a8.188d4c","type":"mqtt-broker","z":"","name":"","broker":"test.mosquitto.org","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"77e810ca.af734","type":"ui_tab","name":"Tab 2","icon":"dashboard","order":2}]


The issue was with using same variable names inside function nodes. After changing variable names (used different names) inside two function nodes this worked well !:smiley:

Thanks bro, it's truely helpfull!