Create toggle switch

Hi there,

I am currently playing around with HomeMatic, NodeRed and some HUE lights.

What I would like to implement is a toggle switch so that I can turn a HUE light on and off by pressing the same button.

The HomeMAtic Switch is integrated via RedMatic, Hue via HueMagic.

The HomeMatic Switch is delivering a boolean "true" every time I press the button.

I can get the status of the HueLight by reading out the msg.payload.on value - this is either true or false.

What I don't seem to get working is to read out the status and dependent on the outcome change the output from the HomeMatic switch to false to then turn off the light.

In simple terms I guess I am looking for an implementation of an if statement that checks the status of the hue light but here I start to get lost :slight_smile:

Thanks so much in advance for any help

Cheers!
Aufruf

I'm not sure if I fully understand what you are trying to do.
But there are some examples in the cookbook which might help, such as
https://cookbook.nodered.org/basic/route-on-context
and
https://cookbook.nodered.org/basic/route-on-property

Many thanks for the links - the first one seems interesting. Will def give it a try and reply back.

Sorry if my description was not clear enough.

I habe a light which is either true (on) or false (off). This needs to be checked.
I then have a light switch which will always send true.
Dependent on the current state of the light I want the switch to trigger the opposite.

Check Light Status --> Light:OFF --> Press_Switch:True --> Light:On
Check Light Status --> LightOn --> Press_Switch:True --> Light Off

Hope this makes it a bit clearer.

YES! First link helped. Thanks a lot!

1 Like

Hi @aufruf

I am trying to do the same. Know the status of a bulb and according to its state, activate or remove the button.

Can you share how you did it?

Thank you very much in advance.

@aufruf Here is my solution. Instead of the butten I am using a 433 mhz remote control (Sonoff RF Bridge) to turn on/off a mixture of Sonoff S26, Sonoff Basic and KNX devices.

[{"id":"29e7d45f.dea00c","type":"change","z":"adb29586.1f2388","name":"","rules":[{"t":"set","p":"toggle-me","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":880,"y":280,"wires":[["38a5d91c.0be77e"]]},{"id":"1b6fe3d1.5580a4","type":"switch","z":"adb29586.1f2388","name":"","property":"toggle-me","propertyType":"flow","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":670,"y":380,"wires":[["8991bf63.f4d578"],["5fec9b00.abd0d4"]]},{"id":"8cddecf3.4a24f","type":"change","z":"adb29586.1f2388","name":"","rules":[{"t":"set","p":"toggle-me","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1100,"y":420,"wires":[["38a5d91c.0be77e"]]},{"id":"1e692860.33a6d","type":"change","z":"adb29586.1f2388","name":"","rules":[{"t":"set","p":"toggle-me","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1100,"y":340,"wires":[["38a5d91c.0be77e"]]},{"id":"dc371121.720208","type":"inject","z":"adb29586.1f2388","name":"","topic":"","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":550,"y":280,"wires":[["29e7d45f.dea00c"]]},{"id":"5fec9b00.abd0d4","type":"change","z":"adb29586.1f2388","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":870,"y":420,"wires":[["8cddecf3.4a24f"]]},{"id":"8991bf63.f4d578","type":"change","z":"adb29586.1f2388","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":870,"y":340,"wires":[["1e692860.33a6d"]]},{"id":"38a5d91c.0be77e","type":"ui_text_input","z":"adb29586.1f2388","name":"","label":"","tooltip":"","group":"65a72644.483318","order":3,"width":0,"height":0,"passthru":true,"mode":"text","delay":300,"topic":"","x":1340,"y":380,"wires":[[]]},{"id":"9af5b2c6.42c3d","type":"ui_button","z":"adb29586.1f2388","name":"","group":"65a72644.483318","order":1,"width":0,"height":0,"passthru":true,"label":"button","tooltip":"","color":"","bgcolor":"","icon":"","payload":"true","payloadType":"bool","topic":"","x":550,"y":380,"wires":[["1b6fe3d1.5580a4"]]},{"id":"f40c5c0.c964128","type":"comment","z":"adb29586.1f2388","name":"At startup set default value (false)","info":"","x":900,"y":240,"wires":[]},{"id":"e62c42b2.ed0408","type":"comment","z":"adb29586.1f2388","name":"if flow.state is true set it to false, if flow.state is false set it to true","info":"","x":990,"y":380,"wires":[]},{"id":"65a72644.483318","type":"ui_group","z":"","name":"Virtuelle Taste BidCoS-RF:1","tab":"fe205248.f04ed","disp":true,"width":"6","collapse":false},{"id":"fe205248.f04ed","type":"ui_tab","z":"","name":"Geräte","icon":"dashboard","order":1}]
1 Like

@egeu5 This toggle switch is really elegant and useful.

Thanks egeu5.

1 Like