I have read this topic a number of times, it is unfortunate that it is not easy to combine wildcard topics/messages
Gave it some thought with a different approach: use context to store what has been received per topic, if all 3 exist, build new msg, send it and remove it from the context.
Input should be send per topic (no joining).
Example:
// if topics context does not exist, write it first before assigning to variable
if (context.get("topics") === undefined) { context.set("topics", {}) }
const topics = context.get("topics")
const base_topic = 'building1/event/type/fixture/id'
const topic_input = msg.topic
// add topic with payload to context, object reference is sometimes handy.
topics[topic_input] = msg.payload
// get serial number
const topic_serial = topic_input.split("/")[5]
// required topics
const name_topic = `${base_topic}/${topic_serial}/name`
const motion_topic = `${base_topic}/${topic_serial}/motion`
const temperature_topic = `${base_topic}/${topic_serial}/temperature`
// if all 3 elements exist, build new payload, send it and remove them from context
if(topics[name_topic] !== undefined && topics[motion_topic] !== undefined && topics[temperature_topic] !== undefined){
// new payload
const pl = {
serial: `${base_topic}/${topic_serial}`,
name: topics[name_topic],
temperature: topics[temperature_topic],
motion: topics[motion_topic],
}
node.send({ payload: pl })
// delete topics from context wait for new cycle
delete topics[name_topic]
delete topics[motion_topic]
delete topics[temperature_topic]
}
return null
example flow:
[{"id":"40d7453917e0f5cc","type":"debug","z":"54a4ccbc8858cca3","name":"debug 134","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":550,"y":220,"wires":[]},{"id":"b5da338512fec5c5","type":"function","z":"54a4ccbc8858cca3","name":"function 33","func":"\nconst names = [\"abc\",\"def\",\"vuw\"]\n\nnames.forEach(name => {\n node.send({ topic: `building1/event/type/fixture/id/${name}/motion`, payload: true })\n node.send({ topic: `building1/event/type/fixture/id/${name}/name`, payload: `name ${name}` })\n node.send({ topic: `building1/event/type/fixture/id/${name}/temperature`, payload: 21.2 })\n})\n\nreturn null ","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":255,"y":220,"wires":[["d2cd963e0357e18c"]],"l":false},{"id":"9a607ccad70c207a","type":"inject","z":"54a4ccbc8858cca3","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":220,"wires":[["b5da338512fec5c5"]]},{"id":"d2cd963e0357e18c","type":"function","z":"54a4ccbc8858cca3","name":"function 34","func":"// if context does not exist, write it first before assigning to variable\nif (context.get(\"topics\") === undefined) { context.set(\"topics\", {}) }\n\nconst topics = context.get(\"topics\") \nconst base_topic = 'building1/event/type/fixture/id'\n\nconst topic_input = msg.topic\n\n// add topic with payload to context, object reference is sometimes handy.\ntopics[topic_input] = msg.payload\n\n// get serial number\nconst topic_serial = topic_input.split(\"/\")[5]\n\n// required topics\nconst name_topic = `${base_topic}/${topic_serial}/name`\nconst motion_topic = `${base_topic}/${topic_serial}/motion`\nconst temperature_topic = `${base_topic}/${topic_serial}/temperature`\n\n// if all 3 elements exist, build new payload, send it and remove them from context\nif(topics[name_topic] !== undefined && topics[motion_topic] !== undefined && topics[temperature_topic] !== undefined){\n \n // new payload\n const pl = {\n serial: `${base_topic}/${topic_serial}`,\n name: topics[name_topic],\n temperature: topics[temperature_topic],\n motion: topics[motion_topic],\n }\n\n node.send({ payload: pl })\n\n // delete topics from context wait for new cycle\n delete topics[name_topic]\n delete topics[motion_topic]\n delete topics[temperature_topic]\n}\n\nreturn null","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":370,"y":220,"wires":[["40d7453917e0f5cc"]]}]