# Help with how to make a node to do this function

**URL:** https://discourse.nodered.org/t/help-with-how-to-make-a-node-to-do-this-function/94381
**Category:** General
**Created:** [6 January 2025 08:59 UTC](https://discourse.nodered.org/t/help-with-how-to-make-a-node-to-do-this-function/94381 "2025-01-06T08:59:41Z")
**Posts on this page:** 4
**Page:** 3

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [7 January 2025 21:32 UTC](https://discourse.nodered.org/t/help-with-how-to-make-a-node-to-do-this-function/94381/42 "2025-01-07T21:32:28Z")

</div>

Forget the message off it is just the light trigger pulsing. when it does not receive a message with in the time of the trigger, set the trigger to send nothing rather than off. Or turn the debug off.

watch the blue dots and watch the switch states (status) which shows how the switches are positioned.

The light trigger is just a representation that the message (electricity is being received) the light trigger could be deleted it's there just to signify  
message received, by showing a blue dot.

The default state is all switches in a position to turn on light, i.e light on.

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [7 January 2025 21:39 UTC](https://discourse.nodered.org/t/help-with-how-to-make-a-node-to-do-this-function/94381/43 "2025-01-07T21:39:01Z")

</div>

Yeah, ok, with you not.

But - gee I have to ZOOM IN something shocking - to see the states clearly.  
(having colours would help)

With you now.

Ok.

I'm kind of understanding your way now too.  
Just a bit confusing for me as I was looking at the wrong things for the wrong reasons, and expecting to see something different.

All good now.

But I may (now) go and mark my latest one as the solution.

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [7 January 2025 21:44 UTC](https://discourse.nodered.org/t/help-with-how-to-make-a-node-to-do-this-function/94381/44 "2025-01-07T21:44:38Z")

</div>

For the sake of keeping things clean:  
The code I posted was mentioned to me I made a mistake with ` and ' being used incorrectly.

This is the code which - to me - clearly shows me what is going on and the _trick_ with the DPDT switches and how they allow multiple (unlimited) numbers of them to control a light.

Yes: Outside the scope of NR. Just it is my _go to program/language_ for testing things just now.

```auto
[{"id":"512885e1dfc85d57","type":"change","z":"b25fd092.bcc758","name":"STOP","rules":[{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":6470,"wires":[["188b0c7758d721af"]]},{"id":"15b5283d986df757","type":"change","z":"b25fd092.bcc758","name":"STOP","rules":[{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":6510,"wires":[["b275c8b2d07f2578"]]},{"id":"893473637099af23","type":"inject","z":"b25fd092.bcc758","name":"ON","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"ON","payloadType":"str","x":250,"y":6540,"wires":[["b275c8b2d07f2578","512885e1dfc85d57"]]},{"id":"188b0c7758d721af","type":"trigger","z":"b25fd092.bcc758","name":"OFF","op1":"0,1","op2":"0","op1type":"str","op2type":"str","duration":"-1","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":520,"y":6470,"wires":[["79dfd23d02073a19"]]},{"id":"54d68a866d3e8353","type":"inject","z":"b25fd092.bcc758","name":"OFF","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"OFF","payloadType":"str","x":250,"y":6440,"wires":[["15b5283d986df757","188b0c7758d721af"]]},{"id":"b275c8b2d07f2578","type":"trigger","z":"b25fd092.bcc758","name":"ON","op1":"1,0","op2":"0","op1type":"str","op2type":"str","duration":"-1","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":520,"y":6510,"wires":[["79dfd23d02073a19"]]},{"id":"79dfd23d02073a19","type":"function","z":"b25fd092.bcc758","name":"function 186","func":"let x = msg.payload;\nlet y = context.get(\"toggle\") || 0;\nif (x == \"TOGGLE\")\n{\n y = ((y + 1) % 2);\n context.set(\"toggle\",y)\n if (y == 0)\n {\n node.status({fill: \"green\", text: \"normal\"});\n }\n else\n {\n node.status({fill: \"red\", text: \"flip\"});\n }\n return;\n}\n\nif (y == 1)\n{\n //\n if (x == '1,0')\n {\n x = '0,1'\n msg.payload = x;\n return msg;\n }\n //\n if (x == '0,1')\n {\n x = '1,0'\n msg.payload = x;\n return msg;\n }\n}\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":709,"y":6496,"wires":[["ae171e439487547e","32e7de687114a89f"]]},{"id":"aa890c59737b287b","type":"inject","z":"b25fd092.bcc758","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"TOGGLE","payloadType":"str","x":699,"y":6446,"wires":[["79dfd23d02073a19"]]},{"id":"ae171e439487547e","type":"function","z":"b25fd092.bcc758","name":"function 187","func":"let x = msg.payload;\nlet y = context.get(\"toggle\") || 0;\nif (x == \"TOGGLE\")\n{\n y = ((y + 1) % 2);\n context.set(\"toggle\",y)\n if (y == 0)\n {\n node.status({fill: \"green\", text: \"normal\"});\n }\n else\n {\n node.status({fill: \"red\", text: \"flip\"});\n }\n return;\n}\n\nif (y == 1)\n{\n //\n if (x == '1,0')\n {\n x = '0,1'\n msg.payload = x;\n return msg;\n }\n //\n if (x == '0,1')\n {\n x = '1,0'\n msg.payload = x;\n return msg;\n }\n}\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":929,"y":6496,"wires":[["87a2abd50a00c54c","070b96c2e0e3ce92"]]},{"id":"32e7de687114a89f","type":"debug","z":"b25fd092.bcc758","name":"SW1","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":690,"y":6560,"wires":[]},{"id":"c96ea5a2349e3ffc","type":"inject","z":"b25fd092.bcc758","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"TOGGLE","payloadType":"str","x":919,"y":6446,"wires":[["ae171e439487547e"]]},{"id":"87a2abd50a00c54c","type":"function","z":"b25fd092.bcc758","name":"function 188","func":"let x = msg.payload;\nlet y = context.get(\"toggle\") || 0;\nif (x == \"TOGGLE\")\n{\n y = ((y + 1) % 2);\n context.set(\"toggle\",y)\n if (y == 0)\n {\n node.status({fill: \"green\", text: \"normal\"});\n }\n else\n {\n node.status({fill: \"red\", text: \"flip\"});\n }\n return;\n}\n\nif (y == 1)\n{\n //\n if (x == '1,0')\n {\n x = '0,1'\n msg.payload = x;\n return msg;\n }\n //\n if (x == '0,1')\n {\n x = '1,0'\n msg.payload = x;\n return msg;\n }\n}\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1139,"y":6496,"wires":[["8799bfd981b0a666","d5b233c2e3220144"]]},{"id":"070b96c2e0e3ce92","type":"debug","z":"b25fd092.bcc758","name":"SW2","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":910,"y":6560,"wires":[]},{"id":"ea4d2a8c0b6140a6","type":"inject","z":"b25fd092.bcc758","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"TOGGLE","payloadType":"str","x":1129,"y":6446,"wires":[["87a2abd50a00c54c"]]},{"id":"8799bfd981b0a666","type":"function","z":"b25fd092.bcc758","name":"function 189","func":"let x = msg.payload;\nlet y = x.split(',');\n\nlet state = y[0];\n\nif (state == 0)\n{\n msg.payload = \"OFF\"\n}\nelse\n{\n msg.payload = \"ON\"\n}\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1329,"y":6496,"wires":[["415745113788cc72"]]},{"id":"d5b233c2e3220144","type":"debug","z":"b25fd092.bcc758","name":"SW3","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1120,"y":6560,"wires":[]},{"id":"415745113788cc72","type":"rbe","z":"b25fd092.bcc758","name":"","func":"rbe","gap":"","start":"","inout":"out","septopics":true,"property":"payload","topi":"topic","x":1480,"y":6496,"wires":[["ca5264fb7de95619"]]},{"id":"ca5264fb7de95619","type":"debug","z":"b25fd092.bcc758","name":"Light is.....","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1330,"y":6550,"wires":[]}]

```

 ![Screenshot from 2025-01-08 08-43-01](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/d/fd17f76efaf8c335bdbab1dac919750dd8b7379e.png)

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [21 January 2025 21:44 UTC](https://discourse.nodered.org/t/help-with-how-to-make-a-node-to-do-this-function/94381/45 "2025-01-21T21:44:57Z")

</div>

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

[Previous page](https://discourse.nodered.org/t/help-with-how-to-make-a-node-to-do-this-function/94381.md?page=2)
