Philips Button State

Hi everyone!!!

I have a Philips Hue with a couple of bulbs installed and Huemagic in NodeRed.

I want to control the bulbs with a button that knows what "state" the bulb is in and then activate (true / false) depending on the state of the bulb.

I explain;

The light works as true (on) or false (off). This needs to be verified. The "hue light" node sends the state of the bulb.
Then I have a light button that will always send true.
Depending on the current state of the light, I want the button to activate otherwise.

Check the light status -> Light: OFF -> Press_button: True -> Light: On
Check the light status -> LightOn -> Press_button: True -> Light Off

Has anyone worked with this?

Thank you.

Greetings

Hi!!!

I have been doing several tests.

I took the @davidcgu example and set it to enable / disable the bulb or group of bulbs. This is done correctly, but I still have problems with the state of the bulb.

Any idea why the button does not change color and icon depending on the state returned by the bulb?

Grateful in advance and sorry for being such a rookie.

[{"id":"497d3328.acf7dc","type":"tab","label":"Hue","disabled":false,"info":""},{"id":"b0c184da.7839f8","type":"function","z":"497d3328.acf7dc","name":"if is on","func":"msg.color = \"black\";\nmsg.background = \"#EF2F4F\";\nmsg.text = \"TURN OFF\";\nreturn msg;","outputs":1,"noerr":0,"x":470,"y":240,"wires":[["14cf5db5.4b0d92"]]},{"id":"7e21507c.e6f65","type":"function","z":"497d3328.acf7dc","name":"if its off","func":"msg.color = \"black\";\nmsg.background = \"#B4EEB4\";\nmsg.text = \"TURN ON\";\nreturn msg;","outputs":1,"noerr":0,"x":480,"y":300,"wires":[["14cf5db5.4b0d92"]]},{"id":"14cf5db5.4b0d92","type":"ui_button","z":"497d3328.acf7dc","name":"on/off","group":"d46ce13f.57145","order":5,"width":"7","height":"1","passthru":false,"label":"{{msg.text}}","tooltip":"","color":"{{msg.color}}","bgcolor":"{{msg.background}}","icon":"ac_unit","payload":"none","payloadType":"str","topic":"button","x":630,"y":260,"wires":[["795fd827.ea6158"]]},{"id":"795fd827.ea6158","type":"switch","z":"497d3328.acf7dc","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"button","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":750,"y":260,"wires":[["9b6c17ee.5ddd38"]]},{"id":"9b6c17ee.5ddd38","type":"function","z":"497d3328.acf7dc","name":"","func":"var obtaindata = global.get (\"switch\")\nif (obtaindata == \"1\"){msg.payload = 0}\nif (obtaindata == \"0\"){msg.payload = 1}\nreturn msg;\n\n","outputs":1,"noerr":0,"x":870,"y":260,"wires":[["544bf558.edbbfc","3214efcd.8599a"]]},{"id":"4f23455a.d2d40c","type":"debug","z":"497d3328.acf7dc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1250,"y":480,"wires":[]},{"id":"3214efcd.8599a","type":"change","z":"497d3328.acf7dc","name":"re-wirte switch variable","rules":[{"t":"move","p":"payload","pt":"msg","to":"switch","tot":"global"}],"action":"","property":"","from":"","to":"","reg":false,"x":1060,"y":200,"wires":[[]]},{"id":"ca7e656e.c96468","type":"function","z":"497d3328.acf7dc","name":"","func":"var obtaindata = global.get (\"switch\");\nmsg.payload = obtaindata;\n\nreturn msg;\n","outputs":1,"noerr":0,"x":130,"y":280,"wires":[["b68a09b2.6f22b8"]]},{"id":"544bf558.edbbfc","type":"change","z":"497d3328.acf7dc","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"1","fromt":"num","to":"true","tot":"bool"},{"t":"change","p":"payload","pt":"msg","from":"0","fromt":"num","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":1040,"y":340,"wires":[["3bd31d4c.91b1c2"]]},{"id":"3bd31d4c.91b1c2","type":"hue-group","z":"497d3328.acf7dc","name":"Salon","bridge":"c9eab922.43e148","groupid":"1","colornamer":true,"skipevents":false,"x":1210,"y":340,"wires":[["3e901968.540616"]]},{"id":"b68a09b2.6f22b8","type":"switch","z":"497d3328.acf7dc","name":"ON/OFF state","property":"switch","propertyType":"global","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":300,"y":280,"wires":[["b0c184da.7839f8"],["7e21507c.e6f65"]]},{"id":"3e901968.540616","type":"change","z":"497d3328.acf7dc","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"true","fromt":"bool","to":"1","tot":"num"},{"t":"change","p":"payload","pt":"msg","from":"false","fromt":"bool","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":480,"wires":[["4f23455a.d2d40c","ca7e656e.c96468"]]},{"id":"d46ce13f.57145","type":"ui_group","z":"","name":"test","tab":"27c50e50.5b08a2","order":3,"disp":true,"width":"7","collapse":true},{"id":"c9eab922.43e148","type":"hue-bridge","z":"","name":"Philips hue Bridge","bridge":"192.168.11.151","key":"fkRRh1XTEda2MyYvGFOxuHa6x5x6Og0sYgzGkqH1","interval":"3000","disableupdates":false},{"id":"27c50e50.5b08a2","type":"ui_tab","z":"","name":"test","icon":"fa-television","order":2}]

Hi!!!

I have already managed to solve the problem.

There is nothing like self help, :slight_smile: