Join two messages with the same topic

Hello Guys,

9 devices get at the same time the command to tell the IP adress, than they get another Command to tell the Devie name.
I get 9 answers, all with the own device topic, nice. But now i would like to join them in a single output.

The clue: The same toppic should merge. At the moment i get a joint output only on differant topics.

I was thinking thame topic and join the right massage to the right topic is easy... nope not for me :slight_smile:
Please give me a hint.

here is my flow:

Summary

[{"id":"e5180013.13f2d","type":"inject","z":"9bfe4864.e10be8","name":"Wirldcard Tasmotas","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"str","x":130,"y":540,"wires":[["d10c98ad.49aad8","72fe515caf7b0d91"]]},{"id":"4d9defb2.722a","type":"debug","z":"9bfe4864.e10be8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":910,"y":680,"wires":[]},{"id":"7d26f7a8.87b978","type":"mqtt in","z":"9bfe4864.e10be8","name":"","topic":"stat/+/RESULT","qos":"2","datatype":"json","broker":"ceba0b4b.cd64b8","nl":false,"rap":true,"rh":0,"x":120,"y":680,"wires":[["21fcada9.b53fa2","572541bf4fe4e87d"]]},{"id":"d10c98ad.49aad8","type":"mqtt out","z":"9bfe4864.e10be8","name":"","topic":"cmnd/tasmotas/ipaddress1","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"ceba0b4b.cd64b8","x":400,"y":540,"wires":[]},{"id":"97381e1.589b5e","type":"join","z":"9bfe4864.e10be8","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"2","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":570,"y":660,"wires":[["98d906b107a48a06"]]},{"id":"21fcada9.b53fa2","type":"switch","z":"9bfe4864.e10be8","name":"","property":"payload.IPAddress1","propertyType":"jsonata","rules":[{"t":"nempty"}],"checkall":"true","repair":false,"outputs":1,"x":270,"y":680,"wires":[["97381e1.589b5e"]]},{"id":"72fe515caf7b0d91","type":"mqtt out","z":"9bfe4864.e10be8","name":"","topic":"cmnd/tasmotas/Devicename","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"ceba0b4b.cd64b8","x":400,"y":600,"wires":[]},{"id":"572541bf4fe4e87d","type":"switch","z":"9bfe4864.e10be8","name":"","property":"payload.DeviceName","propertyType":"jsonata","rules":[{"t":"nempty"}],"checkall":"true","repair":false,"outputs":1,"x":270,"y":720,"wires":[["78bb2f56a80ec410"]]},{"id":"78bb2f56a80ec410","type":"join","z":"9bfe4864.e10be8","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"2","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":570,"y":720,"wires":[["98d906b107a48a06"]]},{"id":"98d906b107a48a06","type":"join","z":"9bfe4864.e10be8","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"2","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":730,"y":680,"wires":[["4d9defb2.722a"]]},{"id":"ceba0b4b.cd64b8","type":"mqtt-broker","name":"local broker","broker":"localhost","port":"1883","clientid":"","usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""}]

that is the output:

Summary

[{"stat/tasmota_FA2EA2/RESULT":{"IPAddress1":"192.168.178.62 192.168.178.62"},"stat/tasmota_14B9AD/RESULT":{"IPAddress1":"192.168.178.71 (192.168.178.71)"},"stat/tasmota_116C9B/RESULT":{"IPAddress1":"192.168.178.67 (192.168.178.67)"},"stat/tasmota_FACD72/RESULT":{"IPAddress1":"192.168.178.64 (192.168.178.64)"},"stat/tasmota_106257/RESULT":{"IPAddress1":"192.168.178.65 (192.168.178.65)"},"stat/tasmota_D41743/RESULT":{"IPAddress1":"0.0.0.0 (192.168.178.23)"},"stat/tasmota_150017/RESULT":{"IPAddress1":"192.168.178.72 (192.168.178.72)"},"stat/tasmota_663943/RESULT":{"IPAddress1":"192.168.178.75 (192.168.178.75)"},"stat/tasmota_107217/RESULT":{"IPAddress1":"192.168.178.66 (192.168.178.66)"}},{"stat/tasmota_FA2EA2/RESULT":{"DeviceName":"Christopher Stehleuchte"},"stat/tasmota_14B9AD/RESULT":{"DeviceName":"Steckdose Christopher"},"stat/tasmota_116C9B/RESULT":{"DeviceName":"Küche Licht"},"stat/tasmota_FACD72/RESULT":{"DeviceName":"Stube Ecklampe"},"stat/tasmota_106257/RESULT":{"DeviceName":"Stube Esstisch"},"stat/tasmota_D41743/RESULT":{"DeviceName":"Stube Temp"},"stat/tasmota_150017/RESULT":{"DeviceName":"Steckdose Stube"},"stat/tasmota_663943/RESULT":{"DeviceName":"PC LED"},"stat/tasmota_107217/RESULT":{"DeviceName":"Draußen Licht"}}]

how can i join the same topic massage?

Here are a couple of JSONata expressions that should merge the results one is an object the other an array.

[{"id":"fdc5e3ff.7cc3d8","type":"inject","z":"c791cbc0.84f648","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"stat/tasmota_FA2EA2/RESULT\":{\"DeviceName\":\"Christopher Stehleuchte\"},\"stat/tasmota_14B9AD/RESULT\":{\"DeviceName\":\"Steckdose Christopher\"},\"stat/tasmota_116C9B/RESULT\":{\"DeviceName\":\"Küche Licht\"},\"stat/tasmota_FACD72/RESULT\":{\"DeviceName\":\"Stube Ecklampe\"},\"stat/tasmota_106257/RESULT\":{\"DeviceName\":\"Stube Esstisch\"},\"stat/tasmota_D41743/RESULT\":{\"DeviceName\":\"Stube Temp\"},\"stat/tasmota_150017/RESULT\":{\"DeviceName\":\"Steckdose Stube\"},\"stat/tasmota_663943/RESULT\":{\"DeviceName\":\"PC LED\"},\"stat/tasmota_107217/RESULT\":{\"DeviceName\":\"Draußen Licht\"}},{\"stat/tasmota_FA2EA2/RESULT\":{\"IPAddress1\":\"192.168.178.62 192.168.178.62\"},\"stat/tasmota_14B9AD/RESULT\":{\"IPAddress1\":\"192.168.178.71 (192.168.178.71)\"},\"stat/tasmota_116C9B/RESULT\":{\"IPAddress1\":\"192.168.178.67 (192.168.178.67)\"},\"stat/tasmota_FACD72/RESULT\":{\"IPAddress1\":\"192.168.178.64 (192.168.178.64)\"},\"stat/tasmota_106257/RESULT\":{\"IPAddress1\":\"192.168.178.65 (192.168.178.65)\"},\"stat/tasmota_D41743/RESULT\":{\"IPAddress1\":\"0.0.0.0 (192.168.178.23)\"},\"stat/tasmota_150017/RESULT\":{\"IPAddress1\":\"192.168.178.72 (192.168.178.72)\"},\"stat/tasmota_663943/RESULT\":{\"IPAddress1\":\"192.168.178.75 (192.168.178.75)\"},\"stat/tasmota_107217/RESULT\":{\"IPAddress1\":\"192.168.178.66 (192.168.178.66)\"}}]","payloadType":"json","x":810,"y":1360,"wires":[["30e90356.21549c","ec7c72b1.fbe668"]]},{"id":"30e90356.21549c","type":"change","z":"c791cbc0.84f648","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$merge(\t   $each(\t       $$.payload[0],\t       function ($v, $k) {\t           {$k: $merge([ $v, $$.payload[1][$k].* ])}\t}\t   )\t)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1020,"y":1360,"wires":[["4d9defb2.722a"]]},{"id":"ec7c72b1.fbe668","type":"change","z":"c791cbc0.84f648","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$each(\t   $$.payload[0],\t   function ($v, $k) {\t       $merge(\t           [\t               $v,\t               $$.payload[1][$k].*,\t               {\"topic\": $k} \t           ]\t       )\t}\t)\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":980,"y":1420,"wires":[["4d9defb2.722a"]]},{"id":"4d9defb2.722a","type":"debug","z":"c791cbc0.84f648","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1130,"y":1280,"wires":[]}]

[edit]
Or alter payload to contain the topic and payload. Then join as array. then merge the joined array into what ever format you need.

[{"id":"fdc5e3ff.7cc3d8","type":"inject","z":"c791cbc0.84f648","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"stat/tasmota_FA2EA2/RESULT\":{\"DeviceName\":\"Christopher Stehleuchte\"},\"stat/tasmota_14B9AD/RESULT\":{\"DeviceName\":\"Steckdose Christopher\"},\"stat/tasmota_116C9B/RESULT\":{\"DeviceName\":\"Küche Licht\"},\"stat/tasmota_FACD72/RESULT\":{\"DeviceName\":\"Stube Ecklampe\"},\"stat/tasmota_106257/RESULT\":{\"DeviceName\":\"Stube Esstisch\"},\"stat/tasmota_D41743/RESULT\":{\"DeviceName\":\"Stube Temp\"},\"stat/tasmota_150017/RESULT\":{\"DeviceName\":\"Steckdose Stube\"},\"stat/tasmota_663943/RESULT\":{\"DeviceName\":\"PC LED\"},\"stat/tasmota_107217/RESULT\":{\"DeviceName\":\"Draußen Licht\"}},{\"stat/tasmota_FA2EA2/RESULT\":{\"IPAddress1\":\"192.168.178.62 192.168.178.62\"},\"stat/tasmota_14B9AD/RESULT\":{\"IPAddress1\":\"192.168.178.71 (192.168.178.71)\"},\"stat/tasmota_116C9B/RESULT\":{\"IPAddress1\":\"192.168.178.67 (192.168.178.67)\"},\"stat/tasmota_FACD72/RESULT\":{\"IPAddress1\":\"192.168.178.64 (192.168.178.64)\"},\"stat/tasmota_106257/RESULT\":{\"IPAddress1\":\"192.168.178.65 (192.168.178.65)\"},\"stat/tasmota_D41743/RESULT\":{\"IPAddress1\":\"0.0.0.0 (192.168.178.23)\"},\"stat/tasmota_150017/RESULT\":{\"IPAddress1\":\"192.168.178.72 (192.168.178.72)\"},\"stat/tasmota_663943/RESULT\":{\"IPAddress1\":\"192.168.178.75 (192.168.178.75)\"},\"stat/tasmota_107217/RESULT\":{\"IPAddress1\":\"192.168.178.66 (192.168.178.66)\"}}]","payloadType":"json","x":90,"y":1160,"wires":[["ce240ff2.fd24c8"]]},{"id":"ce240ff2.fd24c8","type":"function","z":"c791cbc0.84f648","name":"simulate mqtt input","func":"for(const obj of msg.payload){\n    for(const arr of Object.entries(obj)){\n        node.send({topic: arr[0], payload: arr[1]})\n    }\n}\nreturn null;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":270,"y":1160,"wires":[["217900f0.15a238"]]},{"id":"217900f0.15a238","type":"change","z":"c791cbc0.84f648","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"topic\": $$.topic,\t\"message\": $$.payload}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":240,"y":1220,"wires":[["1a6dba90.3fd2ed"]]},{"id":"1a6dba90.3fd2ed","type":"join","z":"c791cbc0.84f648","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"2","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":430,"y":1220,"wires":[["4f610270.73d114"]]},{"id":"4f610270.73d114","type":"function","z":"c791cbc0.84f648","name":"","func":"let output = {};\nfor(const obj of msg.payload){\n    output[obj.topic] = Object.assign(output[obj.topic] || {}, obj.message);\n}\nmsg.payload = output;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":570,"y":1220,"wires":[["4d9defb2.722a"]]},{"id":"4d9defb2.722a","type":"debug","z":"c791cbc0.84f648","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":750,"y":1220,"wires":[]}]

Still not sure what the final output you require would be, as you have not shown an example.

I tried to join them, if you have a better way, please tell. That was the closest what I get and it is near what I need...

Thanks for that!, that is exact what i expect.

The secound flow is what i need :slight_smile:

i send my unfilterd input to your function and it exact i would like to have.

What was the way? I do not understand the function node that good.

here is my output now:

Summary

{"stat/tasmota_106257/RESULT":{"IPAddress1":"192.168.178.65 (192.168.178.65)","DeviceName":"Stube Esstisch"},"stat/tasmota_116C9B/RESULT":{"IPAddress1":"192.168.178.67 (192.168.178.67)","DeviceName":"Küche Licht"},"stat/tasmota_FACD72/RESULT":{"IPAddress1":"192.168.178.64 (192.168.178.64)","DeviceName":"Stube Ecklampe"},"stat/tasmota_FA2EA2/RESULT":{"IPAddress1":"192.168.178.62 192.168.178.62","DeviceName":"Christopher Stehleuchte"},"stat/tasmota_150017/RESULT":{"IPAddress1":"192.168.178.72 (192.168.178.72)","DeviceName":"Steckdose Stube"},"stat/tasmota_D41743/RESULT":{"IPAddress1":"0.0.0.0 (192.168.178.23)","DeviceName":"Stube Temp"},"stat/tasmota_14B9AD/RESULT":{"IPAddress1":"192.168.178.71 (192.168.178.71)","DeviceName":"Steckdose Christopher"},"stat/tasmota_107217/RESULT":{"IPAddress1":"192.168.178.66 (192.168.178.66)","DeviceName":"Draußen Licht"},"stat/tasmota_663943/RESULT":{"IPAddress1":"192.168.178.75 (192.168.178.75)","DeviceName":"PC LED"}}

That is exact what i would like to have THANKS!!!

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