Thank you very much @knolleary for the explanation with the example. This helps a lot.
I understood it now clearly. Thanks again!
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.
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 !