Combine node outputs

This is really simple, but I haven’t touched node-RED for ages and I’m stuck:

Two nodes generate slightly different payloads (of objects containing key:value pairs) but they do have the key “Rain” in common. This can have a value of 1 or 0.

I want to get the value of Rain from each payload, sum them, and then feed the result to another node where: if Rain = 1 then do nothing, else turn on watering system.

I’ve tried a Join, followed by Change node with Jsonata $sum to modify the output but I’m getting tangled up. Any help would be much appreciated.

Here is an example

[{"id":"12cf7965.5ab35f","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"one","payload":"{\"one\":1,\"rain\":1}","payloadType":"json","x":170,"y":4720,"wires":[["18501f64.763a81"]]},{"id":"18501f64.763a81","type":"join","z":"c74669a0.6a34f8","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":380,"y":4740,"wires":[["24f8b497.851794"]]},{"id":"7d9e3470.082b1c","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"two","payload":"{\"two\":1,\"rain\":1}","payloadType":"json","x":170,"y":4760,"wires":[["18501f64.763a81"]]},{"id":"24f8b497.851794","type":"change","z":"c74669a0.6a34f8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$sum(payload.*.rain)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":570,"y":4740,"wires":[["df2cf978.75a28"]]},{"id":"df2cf978.75a28","type":"debug","z":"c74669a0.6a34f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":580,"y":4840,"wires":[]}]

Thank you. I should have asked earlier instead of going around in circles. I was almost there. I was just missing the asterisk in the Change: "payload.*."

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