Toggle Philips Hue on/off

Wondering if anyone could help, I’m trying to create a scene to toggle two hue bulbs off and on. Since they are actually always on and it’s just the brightness level that changes, a toggle doesn’t work. Is it possible with code to check the brightness levels of the two bulbs and if it returns 0% set it to 100% and if it returns 100% set it to 0% ? if yes, I would appreciate if you could post an example of it here.

there is switch status that determines the on/off status. I tested this with my own Hue.

It checks to see if the switch is on and then turns the light off. If the light is off it turns it back on at 100%.

just replace “39” with your hue device id.

local device=39 local switchOnOff = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", device)
if (switchOnOff == "1") then
  -- Switch is on

luup.call_action(“urn:upnp-org:serviceId:Dimming1”, “SetLoadLevelTarget”, {newLoadlevelTarget = “0”}, device)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“0” },device)
else
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“1” },device)
luup.call_action(“urn:upnp-org:serviceId:Dimming1”, “SetLoadLevelTarget”, {newLoadlevelTarget = “100”}, device)

end </blockquote>

Thanks kigmatzomat, that’s just what I needed.

Hey there, sorry that i dig out this older thread, but its what i am looking for…

I am new to hue / scripting. So i have to ask a dumb question:

where can i use scripts (esp. this script) … a small hint might be enough to on searching … but i wasnt able to find the answer yet.

Sorry again, and thx for your help !

Under “automation” you can configure a scene. Then choose the tab marked “luup”.

Be so kind to tell me where I can find Automation
Thnaks

Hi.
I would like to toggle hue on and off using a scene. I tried the code from this topic but couldn’t get it to work. Vera says that there is an error in lua. Could you please help?

81 is the id of my hue bulb.

I used this in lua:

[code]
local device=81
local switchOnOff = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”, “Status”, device)

if (switchOnOff == "1") then
  -- Switch is on

luup.call_action(“urn:upnp-org:serviceId:Dimming1”, “SetLoadLevelTarget”, {newLoadlevelTarget = “0”}, device)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“0” },device)
else
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“1” },device)
luup.call_action(“urn:upnp-org:serviceId:Dimming1”, “SetLoadLevelTarget”, {newLoadlevelTarget = “100”}, device)

end[/code]

I copied that code to the UI5 test code window and it didn’t complain. Then I tried it under AltUI in the test window and it also didn’t complain. Is that an exact copy of what you are testing? (Note that I only checked the syntax, not the functionality.)

Hurray! Problem solved. I upgraged to the latest firmware (1.7.947) and now I can toggle the hue light(s).

Thank you very much for testing. That helped me to know that the code was not the problem. kudos

Btw, Why this line is in the code:

luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{ newTargetValue="1" },device)

Is it necessary? It seems that hue light is turned on even without that line. The transition from off to on is smoother if bright value is something else than 100, e.g. 20. If that line of code is implemented, hue bulb first set the brightness to max and then lower it to 20, which is somewhat irritating.

It may not be necessary. Take it out if it works for you.

I can’t point to an example, but in my head there are dimmer switches where you can set the level but that won’t turn on until Switchpower=1 and I like my code to be usable with all devices.

Thank you for explaining.
I guess as hue lights are actually always on, switchpower=1 causes unwanted changes in brightness when the scene is activated.