Add two payloads, enforcing both values arriving before summing them - help needed

I am injecting two separate values into a SUM node, but it sums each time a value arrives.

Can I somehow enforce that the values are summed only after BOTH values have arrived ?

I don't use the sum node, as this is simple using standard nodes.

You could just join the messages with a count of 2 and sum the output.
e.g.

[{"id":"0cc20c51c1ace4cc","type":"inject","z":"b9860b4b9de8c8da","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":250,"y":3240,"wires":[["6b9889410da54e8a"]]},{"id":"6b9889410da54e8a","type":"join","z":"b9860b4b9de8c8da","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":410,"y":3280,"wires":[["fdf5a6f8604ae63a"]]},{"id":"dd315fd99c28b588","type":"inject","z":"b9860b4b9de8c8da","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"2","payloadType":"num","x":250,"y":3300,"wires":[["6b9889410da54e8a"]]},{"id":"fdf5a6f8604ae63a","type":"change","z":"b9860b4b9de8c8da","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$sum($.payload)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":3280,"wires":[["66f3a8506ea55dae"]]},{"id":"66f3a8506ea55dae","type":"debug","z":"b9860b4b9de8c8da","name":"debug 323","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":610,"y":3360,"wires":[]},{"id":"6cae1f885c77843c","type":"inject","z":"b9860b4b9de8c8da","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"one","payload":"1","payloadType":"num","x":270,"y":3400,"wires":[["1e9887e8adb81ad0"]]},{"id":"2939305b63cc607e","type":"inject","z":"b9860b4b9de8c8da","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"two","payload":"2","payloadType":"num","x":270,"y":3460,"wires":[["1e9887e8adb81ad0"]]},{"id":"1e9887e8adb81ad0","type":"join","z":"b9860b4b9de8c8da","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":430,"y":3440,"wires":[["eb9ef62a851a3979"]]},{"id":"eb9ef62a851a3979","type":"change","z":"b9860b4b9de8c8da","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$sum($$.payload.*)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":3440,"wires":[["58eccebb1445e16e"]]},{"id":"58eccebb1445e16e","type":"debug","z":"b9860b4b9de8c8da","name":"debug 324","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":630,"y":3520,"wires":[]}]

Absolutely perfect and a great learning example

Thank you for that, hugely appreciated

1 Like

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