AARRGGHH!
Believe me, it wasn’t working.
Only after I posted it did it start to work.
I am frantically looking how to delete the thread/post, but it still eludes me.
Sorry folks, I’m stuck - again.
Problem:
Two signals into a Function node. (as typical with me)
1 controls what happens to the other input.
The second input msg.payload is modified depending on what the msg.payload of the other input stream is/was.
But the topic for the first input doesn’t seem to be set by the inject node.
Press NORMAL, then press KNOCK KNOCK.
After pressing NORMAL, the second function node sets a yellow flag saying NORMAL.
But NORMAL should NOT be on sent to the output.
Likewise when you press the KNOCK KNOCK injection point, that should become BUZZ.
The KNOCK KNOCK injection point was set to the topic of KNOCK. That didn’t work. See top debug node. All I see is KNOCK KNOCK with no topic shown.
I added the first function node to set the topic, but even that doesn’t seem to be working.
Sorry, buy could someone have a quick look?
[{"id":"b77f100d.befd08","type":"inject","z":"97a50a2e.90f4e","name":"knock knock","topic":"\"","payload":"KNOCK","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":1460,"y":600,"wires":[["efcc64c.6263b98"]]},{"id":"efcc64c.6263b98","type":"function","z":"97a50a2e.90f4e","name":"","func":"msg.topic = \"KNOCK\";\nreturn msg;","outputs":1,"noerr":0,"x":1460,"y":670,"wires":[["1099070c.e158e1","82b0ea91.ae6e8"]]},{"id":"82b0ea91.ae6e8","type":"debug","z":"97a50a2e.90f4e","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1640,"y":620,"wires":[]},{"id":"1099070c.e158e1","type":"function","z":"97a50a2e.90f4e","name":"","func":"// Depending on \"mode\" depends on what happens when an input is received.\n// msg.payload gets parsed and acted upon depending on 'mode'.\n\n\n// OUTPUT:\n// msg.payload - OPEN to open door. BUZZ to sound buzzer. QUIET to do nothing.\nif (msg.topic != \"KNOCK\")\n{\n // This package has the mode.\n var mode = msg.payload;\n node.status({fill:\"yellow\",shape:\"dot\",text:mode});\n context.set('mode',mode);\n context.set('called',0);\n}\nelse\nif (msg.topic == \"KNOCK\")\n{\n if (mode == \"NORMAL\")\n {\n // Do the normal thing here.\n msg.payload = \"BUZZ\";\n }else\n if (mode == \"BUSY\")\n {\n // Do the busy stuff. This is if I am expecting a call and am busy.\n\n }else\n if (mode == \"OTO\")\n {\n // Open the door once.\n //\tSo we now have to clearn the OTO mode too.\n var called = context.get('called');\n if (called === 0)\n {\n // Increment called and open door.\n called = called + 1;\n msg.payload = \"OPEN\";\n }\n }else\n if (mode == \"CODED\")\n {\n //\tLooking for code input.\n\n }else\n if (mode == \"DND\")\n {\n //\tDo not disturb. Basically do nothing.\n msg.payload = \"QUIET\";\n }\n}\n// Send msg telling the next stage what to do.\nreturn msg;\n","outputs":1,"noerr":0,"x":1640,"y":670,"wires":[["ff40fc81.0d5b68"]]},{"id":"bc685e56.c22568","type":"inject","z":"97a50a2e.90f4e","name":"","topic":"","payload":"NORMAL","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":1470,"y":780,"wires":[["1099070c.e158e1"]]},{"id":"ff40fc81.0d5b68","type":"debug","z":"97a50a2e.90f4e","name":"Door command","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1660,"y":810,"wires":[]}]