Have a strange issue. Broke it down to a fairly basic example. Below.
Node red version Using v0.20.5.
Now when It comes out of first node I get 2 msgs as expected in the debug with the 2 topics. But when it goes through Template node the first topic is overritten and both messages that come out the end have the same topic.
Am I doing something wrong or missing something or is this a bug?
[
{
"id": "9d62f710.7f7fe",
"type": "tab",
"label": "Flow 3",
"disabled": false,
"info": ""
},
{
"id": "826ff31b.5cd5e",
"type": "function",
"z": "9d62f710.7f7fe",
"name": "Processor",
"func": "msg.source = {};\nmsg.source.topic = msg.topic;\nmsg.source.payload = msg.payload;\n\nvar topics = [];\n\nswitch(msg.source.topic) {\n case \"zigbee2mqtt/Office Switch\":\n // code block\n topics.push(\"zigbee2mqtt/Office RGB/set\");\n break;\n case \"zigbee2mqtt/Spare Bedroom Switch\":\n // code block\n topics.push(\"zigbee2mqtt/Spare Bedroom RGB/set\");\n break;\n case \"zigbee2mqtt/Downstairs Switch\":\n // code block\n topics.push(\"zigbee2mqtt/Hall/set\");\n topics.push(\"zigbee2mqtt/Landing/set\");\n break;\n case \"zigbee2mqtt/Landing Switch\":\n // code block\n topics.push(\"zigbee2mqtt/Hall/set\");\n topics.push(\"zigbee2mqtt/Landing/set\");\n break;\n case \"zigbee2mqtt/Loo PIR\":\n // code block\n topics.push(\"zigbee2mqtt/Loo White/set\");\n break;\n case \"zigbee2mqtt/Grey Switch\":\n // code block\n topics.push(\"zigbee2mqtt/Hall/set\");\n //,\"zigbee2mqtt/Landing/set\"};\n break; \n default:\n topics = [];\n // code block\n}\nif (msg.payload.action) {\n switch(msg.payload.action) {\n case \"up\":\n // code block\n msg.state = \"ON\";\n break;\n case \"down\":\n // code block\n msg.state = \"OFF\";\n break;\n case \"hold_up\":\n // code block\n msg.state = \"ON\";\n break;\n case \"hold_down\":\n // code block\n msg.state = \"OFF\";\n break;\n case \"circle_click\":\n // code block\n msg.state = \"ON\";\n break;\n default:\n msg.state = null;\n // code block\n }\n}\n\nif (msg.payload.occupancy !== null) {\n switch(msg.payload.occupancy) {\n case true:\n // code block\n msg.state = \"ON\";\n break;\n case false:\n // code block\n msg.state = \"OFF\";\n break; \n }\n}\n\nif (msg.state && topics.length > 0) {\n topics.forEach(function(element) {\n msg.topic = element;\n node.send([ msg , null ]);\n })\n \n}else{\n return [null,msg];\n} ",
"outputs": 2,
"noerr": 0,
"x": 250,
"y": 240,
"wires": [
[
"df6f0cd0.2354f",
"8fd756c4.3556a"
],
[
"541cc3eb.e55dac"
]
]
},
{
"id": "df6f0cd0.2354f",
"type": "template",
"z": "9d62f710.7f7fe",
"name": "Set State",
"field": "payload",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "{\"state\":\"{{state}}\"}",
"output": "str",
"x": 440,
"y": 100,
"wires": [
[
"aacb50fc.5354a"
]
]
},
{
"id": "aacb50fc.5354a",
"type": "debug",
"z": "9d62f710.7f7fe",
"name": "Post State Output",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 630,
"y": 100,
"wires": []
},
{
"id": "541cc3eb.e55dac",
"type": "debug",
"z": "9d62f710.7f7fe",
"name": "UnProcessed",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 440,
"y": 300,
"wires": []
},
{
"id": "5de67808.9aba9",
"type": "inject",
"z": "9d62f710.7f7fe",
"name": "",
"topic": "zigbee2mqtt/Downstairs Switch",
"payload": "{\"battery\":\"100.00\",\"voltage\":3000,\"linkquality\":5,\"brightness\":254,\"action\":\"up\"}",
"payloadType": "json",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 110,
"y": 300,
"wires": [
[
"826ff31b.5cd5e"
]
]
},
{
"id": "8fd756c4.3556a",
"type": "debug",
"z": "9d62f710.7f7fe",
"name": "Processor Output",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 510,
"y": 220,
"wires": []
}
]