Control an auto-retracting light switch to turn the light On and Off

Hi Guys!

I m new here and I need some advice with the setup light switches at home. I have installed "buzzer" light switches at home, but I am not sure how to setup their flow in Node Red. The Switch has 2 position On and Off. When you press the light switch it sends an impulse to the controller, which should turn on the lights and then releases back to the Off mode.

My problem is that I need to check if the light is Off and then turn on the light and if the light is On then turn off the light. At this point I need to hold the button pressed in order for the light to stay On. It seems I need to find a way to make Node Red receive the Impulse, check the state of the light if it's On or Off and then perform the switching action.

I have already tried combinations using these nodes: counter, switch, change, function and toggle, but so far I haven't reached a working solution.

Can any one please advise what would be the best setup for this operation?

Never heard of Buzzer Light Switches. Is that a product name? If so can you supply their website address?

You need to provide a bit more information and your 'flow' as there are many ways to achieve what you are trying to do. Details on how you interface to the lights and the switches is also needed, as well as details about your hardware (e.g. Raspberry Pi, Wemos ESP8266, etc..).

Hi and welcome to the forum.

I too am a bit confused but I also think I know what you mean.

Ok, so you have this switch connected to one of the RasPi's GPIO pins.
You use a GPIO node to monitor that input.

Then depending on what is seen the light is either turned on or off.

If that is true, try this:

[{"id":"35453c96.47930c","type":"function","z":"68e3655f.b606b4","name":"","func":"var x = context.get(\"state\") || 0;\nx = (x + 1) % 2;\n\nif (x == 1)\n{\n    //  Turn on.\n    //  Put code here.\n} eles\nif (x == 0 )\n{\n    //  Turn off.\n    //  Put code here.\n}\nmsg.payload = x;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1500,"y":390,"wires":[[]]},{"id":"2cf00056.eb8b08","type":"comment","z":"68e3655f.b606b4","name":"Input from \"buzzer switch\"","info":"","x":1300,"y":390,"wires":[]},{"id":"7a2b13a1.ea0714","type":"comment","z":"68e3655f.b606b4","name":"To the rest of the flow.","info":"","x":1690,"y":390,"wires":[]}]

Thank you for your help and a quick reply!

Apologies for not being clear enough with my description.

I am using the WirenBoard hardware for my home automation, here is my setup:
Wiren Board 6 - Controller running NodeRed
WBIO-DI-WD-14 - Input module for light switches
WB-MR6 - Relay module for lighting management

@dynamicdave I literally translated the type of switch that I m using from Czech to English, so that came out as "buzzer".

The type of switch that I am using is ABB 3559-A91345. The issue with this switch is basically that it has a retraction mechanism, so it is always in the OFF state. When you press it, the ON signal is sent, but then it mechanically switches back to the OFF state, so it also sends an OFF signal. I assume this would require some delay or trigger nodes with a reset setting.

Here is my current setup

[{"id":"27bec42f.db165c","type":"inject","z":"f6f2187d.f17ca8","name":"light is OFF","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"str","x":130,"y":120,"wires":[["1681b75f.3d0249"]]},{"id":"b8508bb5.e048b8","type":"inject","z":"f6f2187d.f17ca8","name":"Button Press ON","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"str","x":120,"y":280,"wires":[["a327a4fb.0885d8"]]},{"id":"f1696f23.19765","type":"inject","z":"f6f2187d.f17ca8","name":"light is ON","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"str","x":120,"y":80,"wires":[["1681b75f.3d0249"]]},{"id":"1681b75f.3d0249","type":"toggle","z":"f6f2187d.f17ca8","name":"","onOffTopic":"","onValue":"1","onType":"str","offValue":"0","offType":"str","toggleTopic":"payload","toggleValue":"","toggleType":"str","passOnOff":"ifChanged","x":310,"y":120,"wires":[["3e7bb509.e4e12a"]]},{"id":"3e7bb509.e4e12a","type":"function","z":"f6f2187d.f17ca8","name":"Set light status","func":"if (msg.payload == 1) {\n    global.set(\"light\",\"ON\");\n    return msg\n} else if (msg.payload == 0) {\n    global.set(\"light\",\"OFF\");\n    return msg\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":480,"y":120,"wires":[["8d1b303f.82ac4"]]},{"id":"a327a4fb.0885d8","type":"function","z":"f6f2187d.f17ca8","name":"Set button status","func":"global.set(\"button\",msg.payload)","outputs":1,"noerr":0,"initialize":"","finalize":"","x":510,"y":280,"wires":[["8d1b303f.82ac4"]]},{"id":"8d1b303f.82ac4","type":"function","z":"f6f2187d.f17ca8","name":"ON OFF logic","func":"var lightstatus = global.get(\"light\");\nvar buttonstatus = global.get(\"button\");\n\nif (buttonstatus == \"1\" && lightstatus == \"ON\" ) {\n        global.set(\"light\",\"OFF\");\n        msg.payload = \"Turn lights Off\";\n} else if (buttonstatus == \"1\" && lightstatus == \"OFF\" ) {\n        global.set(\"light\",\"ON\");\n        msg.payload = \"Turn lights On\";\n} else {\n        msg.payload = \"Nothing to do\";\n}\n\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","x":700,"y":200,"wires":[["bb74c5bc.655048","834dfce8.bbde8"]]},{"id":"bb74c5bc.655048","type":"debug","z":"f6f2187d.f17ca8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":950,"y":200,"wires":[]},{"id":"ad7b61a8.cc752","type":"function","z":"f6f2187d.f17ca8","name":"Change status","func":"var light=global.get(\"light\");\n\nif (light == \"ON\") {\n    msg.payload = \"0\";\n} else if (light == \"OFF\") {\n    msg.payload = \"1\";\n}\n\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","x":540,"y":40,"wires":[["1681b75f.3d0249"]]},{"id":"834dfce8.bbde8","type":"delay","z":"f6f2187d.f17ca8","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":370,"y":40,"wires":[["ad7b61a8.cc752"]]}]

In this setup the button press ON should change the state of the toggle to the opposite value. The "Light is ON/Off" inject nodes are only there to override the values. This setup is not working, pressing the "Button Press ON" doesn't change the value of the toggle.
The main issues are:

  • To figure out how to deal with the ABB 3559-A91345 retracting to it's initial OFF position. This switch should be pressed once to turn the Toggle ON and once again in 3 seconds to Toggle the light OFF.
  • How to check the status of the Toggle node and change it to the opposite value.

@Trying_to_learn the function "ON OFF logic" has a similar logic to what you are suggesting.

Side-note: I am using global variable because I saw that being used to add multiple values to a function and I assume I'd probably have to change that to flow instead of global to avoid issues in the future.

In my ideal scenario I would have the switches listen for single press, double press or even long press, but these settings I'd implement later once I figure out how to simply turn the lights ON and OFF with a single press of a button.

Here is a flow that I found that could solve the multiple press options.

[{"id":"1139a03d.d1ca","type":"change","z":"f6f2187d.f17ca8","name":"Reset","rules":[{"t":"set","p":"reset","pt":"msg","to":"foo","tot":"str"},{"t":"delete","p":"payload","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":880,"wires":[["fcb3cb17.693a9"]]},{"id":"900577c3.9deb4","type":"inject","z":"f6f2187d.f17ca8","name":"Reset","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":"0.5","topic":"","payload":"","payloadType":"date","x":250,"y":840,"wires":[["1139a03d.d1ca"]]},{"id":"820bd696.fbc028","type":"debug","z":"f6f2187d.f17ca8","name":"Four presses","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1000,"y":980,"wires":[]},{"id":"525e3ec9.3bb6b8","type":"inject","z":"f6f2187d.f17ca8","name":"Start","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":93.33331298828125,"y":811.111083984375,"wires":[["fcb3cb17.693a9","ba72e20d.299b8"]]},{"id":"4189a6d1.44073","type":"switch","z":"f6f2187d.f17ca8","name":"count presses","property":"count","propertyType":"flow","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"2","vt":"num"},{"t":"eq","v":"3","vt":"num"},{"t":"eq","v":"4","vt":"num"}],"checkall":"true","repair":false,"outputs":4,"x":610,"y":920,"wires":[["83d02113.4743b8"],["fbfe53e5.4fcae8"],["e22efc97.c6b018"],["d9a249bd.1f82a8"]],"info":"Just expand the flow.count to how ever many\npresses you want/need."},{"id":"ba72e20d.299b8","type":"trigger","z":"f6f2187d.f17ca8","name":"","op1":"","op2":"0","op1type":"nul","op2type":"str","duration":"1","extend":true,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":260,"y":920,"wires":[["62860129.ec7bd","4189a6d1.44073"]]},{"id":"9faf97df.4ce4a","type":"change","z":"f6f2187d.f17ca8","name":"Flow set","rules":[{"t":"set","p":"count","pt":"flow","to":"count","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":810,"wires":[["a018a094.13d14"]]},{"id":"ddd0ab58.0a3e58","type":"debug","z":"f6f2187d.f17ca8","name":"Tripple press","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1000,"y":940,"wires":[]},{"id":"ed9739c.0628148","type":"debug","z":"f6f2187d.f17ca8","name":"Double press","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1000,"y":900,"wires":[]},{"id":"8082f0.4ba02d1","type":"debug","z":"f6f2187d.f17ca8","name":"Single Press","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1000,"y":860,"wires":[]},{"id":"83d02113.4743b8","type":"change","z":"f6f2187d.f17ca8","name":"Single Press","rules":[{"t":"set","p":"payload","pt":"msg","to":"Single Press","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":860,"wires":[["8082f0.4ba02d1"]]},{"id":"fbfe53e5.4fcae8","type":"change","z":"f6f2187d.f17ca8","name":"Double Press","rules":[{"t":"set","p":"payload","pt":"msg","to":"Double Press","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":830,"y":900,"wires":[["ed9739c.0628148"]]},{"id":"e22efc97.c6b018","type":"change","z":"f6f2187d.f17ca8","name":"Tripple Press","rules":[{"t":"set","p":"payload","pt":"msg","to":"Tripple Press","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":940,"wires":[["ddd0ab58.0a3e58"]]},{"id":"d9a249bd.1f82a8","type":"change","z":"f6f2187d.f17ca8","name":"Four Press","rules":[{"t":"set","p":"payload","pt":"msg","to":"Four Press","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":980,"wires":[["820bd696.fbc028"]]},{"id":"a1783324.3f9f","type":"comment","z":"f6f2187d.f17ca8","name":"DELAY - Readme","info":"The DELAY time has to be a bit longer than how\nlong it takes you to press the button the\nmaximum number of times.\nRead information in the SWITCH node too!","x":640,"y":730,"wires":[]},{"id":"660d35d0.b41aa4","type":"comment","z":"f6f2187d.f17ca8","name":"Input","info":"","x":250,"y":770,"wires":[]},{"id":"f91932b.cacfb5","type":"comment","z":"f6f2187d.f17ca8","name":"Outputs","info":"Debug nodes are here now, but just connect\nthem to what ever you want.\nThe messages sent are in the nodes just before\nthe debug nodes.\n","x":980,"y":820,"wires":[]},{"id":"a018a094.13d14","type":"debug","z":"f6f2187d.f17ca8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"count","targetType":"msg","x":820,"y":810,"wires":[]},{"id":"62860129.ec7bd","type":"delay","z":"f6f2187d.f17ca8","name":"Delay","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":250,"y":880,"wires":[["1139a03d.d1ca"]]},{"id":"fcb3cb17.693a9","type":"counter","z":"f6f2187d.f17ca8","name":"","init":"0","step":"1","lower":"","upper":"","mode":"increment","outputs":"1","x":440,"y":810,"wires":[["9faf97df.4ce4a"]]}]

Here's a link to a tutorial I wrote for my IoT students. It covers how to deal with buttons that have different actions. One of the examples shows how to make a single button with a Toggle Action which you should be able to modify to suit your particular application.

Having fun with buttons

Note:
There's a link at the bottom of the last page of the PDF to the Node-RED flow.

1 Like

Hi @dynamicdave,

I'm looking are your tutorial, will give this a try and post a solution for my workflow once I figure this out.

Thank you for support, I really appreciate it!
Anton.

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