Switch node to toggle light switch on/off

Hello

I have a zigbee controlled light switch. A msg.payload {"state": "OFF"} turns the switch off and a payload with {"state": "ON turns it on"}

I then want to a dashboard with a button. Pressing the button once turns the light on, pressing the same button again turns the light off.

I have the button and dashboard working, but not sure how to make the same button toggle the state on/off.

Here is my flow currently:

The first node is status from the switch everytime it is initiated.

The 2nd node is a function node to change the colour of the light switch on the dashboard (i.e. press it once, it's green (on), press it again, it's red (off)).

The 3rd node is the UI dashboard button

The 4th node (this is where I am stuck), needs to turn the light on/off when pressing the same UI dashboard.

The 5th node is passing the payload from the 4th node to the light switch.

Any ideas on what to do here on the 4th node?

Does the light not accept a command "TOGGLE"?

1 Like

Here's a link to a thread about buttons you might find useful...

Here's the link to the tutorial I wrote for my IoT students about implementing different types of buttons...
http://www.resources-area.co.uk/node-red-flows/having_fun_with_buttons.pdf

It sounds as if what you actually want is a switch not a button. Then you will not have to mess about making it toggle, and will have feedback as to whether it is on or off.

Thanks - managed to do it with global variables!

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