Dim lights at 10pm ONLY if they are on?

I want to be able to dim my lights in the living room to 60% at 10pm and 40% at 11pm? But if the living room lights are off then I just want to leave them off.

How do I do this??

Thanks.

Setup a scene for 40% and a second scene for 60% and add Luup code to the Luup tab of both scenes.

Pseudo-code (must be translated into Lua):

return CurrentLevel(dimmer) ~= 0

http://wiki.micasaverde.com/index.php/Luup_Scenes_Events#Adding_Lua_code_to_scenes_and_events
http://wiki.micasaverde.com/index.php/Luup_Lua_extensions#function:_variable_get
http://wiki.micasaverde.com/index.php/Luup_Scenes_Events#Do_something_if_switch_device_.235_is_on

Add this code to both scenes, just change the device number (XX)…

– Find the status of the light switch
local LightState=luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”,“Status”,XX)

– Exit the scene if the light is off
if (LightState == “0”) then
return false
end

[quote=“JimMac, post:3, topic:168050”]Add this code to both scenes, just change the device number (XX)…

– Find the status of the light switch
local LightState=luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”,“Status”,XX)

– Exit the scene if the light is off
if (LightState == “0”) then
return false
end[/quote]

2 Questions (as it is coming back with Luup errors).

Where do I find the device number? (same as “ID”) and do I just put it without “” - so
local LightState=luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”,“Status”,2)
OR
local LightState=luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”,“Status”,“2”)

When you have your scene open go to the “Commands” tab and find the light you want to check, the device number is on the left hand side starting with #.
Use that number to directly replace the XX or X, do not use “”. Your first example is correct.

[quote=“JimMac, post:5, topic:168050”]When you have your scene open go to the “Commands” tab and find the light you want to check, the device number is on the left hand side starting with #.
Use that number to directly replace the XX or X, do not use “”. Your first example is correct.[/quote]

It says error in the Luup code

This is exactly what is in the luua field;

– Find the status of the light switch
local LightState=luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”,“Status”,3)

– Exit the scene if the light is off
if (LightState == “0”) then
return false
end

I just ran your code with your device # with the Test Luup code tab and it says “Success, message sent successful”
When I add it to a scene and change the device number it updates successfully & runs fine.

Edit. Make sure you are selecting the correct device # and you are not using the node ID.

JOD.

I use this code to test almost all my lighting conditions before activating scenes, it has been working for well over a year. For example I have motion sensors that detect motion @ night and turn on hallway lights and the bathroom light @ 10%. This code will determine if the bathroom light is already on and exit the scene otherwise the light will dim to 10% then go off after 2 minute. Shortly after that my wife threatens to divorce me because the lights went out during her shower…

Well - it seems to be me that is having the problem then.

Here is what I get when I try to use the LUUP Tester;

Here is how my scene is currently setup;

Help! : ???

Ok try this…

– Find the status of the light switch
local LightState= luup.variable_get(“urn:upnp-org:serviceId:Dimming1”, “LoadLevelTarget”, 3)

– Exit the scene if the light is off
if (LightState == “0”) then
return false
end

[quote=“JimMac, post:11, topic:168050”]Ok try this…

– Find the status of the light switch
local LightState= luup.variable_get(“urn:upnp-org:serviceId:Dimming1”, “LoadLevelTarget”, 3)

– Exit the scene if the light is off
if (LightState == “0”) then
return false
end[/quote]

That worked!! :slight_smile: Thanks!

So this code is usable anytime I want a scene to check to make sure a light is on before activating?

Yes. You can test multiple light conditions by copying the code and changing both the local variable name and the device number. My first post I mistakenly copied the code for a standard on/off light, the new code is for a dimmer.

Here is an example of testing for both a dimmer and a on/off light AND it must be dark out.

– Find the status of two light switches
local Light1State= luup.variable_get(“urn:upnp-org:serviceId:Dimming1”, “LoadLevelStatus”, 3)
local Light2State=luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”,“Status”,?)

– Exit the scene if either of the lights are off and it is not dark out.
if (Light1State == “0”) or (Light2State == “0”) or not ( luup.is_night() ) then
return false
end

You can change the “or” to an “and” if you want both light to be off before your scene executes. I always test for a light condition so I don’t have scenes over-riding any lights when we are home, there’s nothing more annoying when a scene kills a light when you have guests, not a great first impression.

[quote=“MotoElement, post:12, topic:168050”][quote=“JimMac, post:11, topic:168050”]Ok try this…

– Find the status of the light switch
local LightState= luup.variable_get(“urn:upnp-org:serviceId:Dimming1”, “LoadLevelTarget”, 3)

– Exit the scene if the light is off
if (LightState == “0”) then
return false
end[/quote]

That worked!! :slight_smile: Thanks!

So this code is usable anytime I want a scene to check to make sure a light is on before activating?[/quote]

I spoke too soon, it actually dims the lights regardless of whether they are on or not. So last light we went to bed earlier, and the lights turned on (to the dim level), even though it was off. Any ideas?

My bad, should have been LoadLevelStatus not LoadLevelTarget. Replace the line of code.
local LightState= luup.variable_get(“urn:upnp-org:serviceId:Dimming1”, “LoadLevelStatus”, 3)

Edit: I modified the code above with the correction.

[quote=“JimMac, post:15, topic:168050”]My bad, should have been LoadLevelStatus not LoadLevelTarget. Replace the line of code.
local LightState= luup.variable_get(“urn:upnp-org:serviceId:Dimming1”, “LoadLevelStatus”, 3)[/quote]

Ahh - that worked like a charm. Thanks.

I’m brand new, and tying to recreate this code in my setup. I have my device number, but what about the device?

Is this (urn:upnp-org:serviceId:Dimming1) the same for every dimmer light? Or is it unique to my/your setup?

Thanks

Look in the advanced tab for your device- as long as the “Device Type” shows: urn:schemas-upnp-org:device:DimmableLight:1 for that device you’re good with that code.

Yes it is the same for every dimmer.

Thanks, got it. This little piece of code is great for understanding the basics of making conditionals. I’ll be using it alot. Thank you so much!