Time of Day Based Lighting Levels

I have a set of hallway lights that are on a GE dimmer switch. However, the lights will primarily be turned on and off with a Leviton in-wall 4 button scene controller. There is no direct association between the scene controller and the lights - it goes through Vera.

Here is my concept— I don’t want to ‘waste’ buttons on my controller by having each button set a different lighting level. I want a single Vera scene to set the lighting level based on the time of day. I imagine that if I turn the lights on during the day, I want them full bright. If I turn them on in the evening, I want a dimmed level. And if I turn them on in the middle of the night, I want a low level. I can’t seem to get this working and am looking for the LUA help. If you are a real expert, I’d actually like to go one step further, and have the code also see if the lights are already on and if they are on already when the scene is activated, they go to full bright (so you can get full brightness during a normally dimmed period still using only one scene button).

The following is my attempted code:

local t = os.date(‘*t’)
local current_second = t.hour * 3600 + t.min * 60 + t.sec – number of sec since midnight
local highhr = 6 * 3600 + 0 * 60 – 06:00
local medhr = 18 * 3600 + 0 * 60 – 18:00
local lowhr = 21 * 3600 + 0 * 60 – 21:00

local halldimmer = 54

if (current_second > highhr) and (current_second < medhr) then
luup.call_action(“urn:upnp-org:serviceId:Dimming1”, “SetLoadLevelTarget”, {newLoadlevelTarget = “100”}, halldimmer)
else
return false
end

if (current_second > medhr) and (current_second < lowhr) then
luup.call_action(“urn:upnp-org:serviceId:Dimming1”, “SetLoadLevelTarget”, {newLoadlevelTarget = “50”}, halldimmer)
else
return false
end

The GUI scene itself then turns the light on at the middle of the night level. That way all issues with the midnight crossover would seem to be avoided in the LUA code.

The results I am getting with this seem to be my 100% light during the day, but no action at other times.

Thanks for your help.

[quote=“flyarmy, post:1, topic:171201”]I have a set of hallway lights that are on a GE dimmer switch. However, the lights will primarily be turned on and off with a Leviton in-wall 4 button scene controller. There is no direct association between the scene controller and the lights - it goes through Vera.

Here is my concept— I don’t want to ‘waste’ buttons on my controller by having each button set a different lighting level. I want a single Vera scene to set the lighting level based on the time of day. I imagine that if I turn the lights on during the day, I want them full bright. If I turn them on in the evening, I want a dimmed level. And if I turn them on in the middle of the night, I want a low level. I can’t seem to get this working and am looking for the LUA help. If you are a real expert, I’d actually like to go one step further, and have the code also see if the lights are already on and if they are on already when the scene is activated, they go to full bright (so you can get full brightness during a normally dimmed period still using only one scene button).

The following is my attempted code:

local t = os.date(‘*t’)
local current_second = t.hour * 3600 + t.min * 60 + t.sec – number of sec since midnight
local highhr = 6 * 3600 + 0 * 60 – 06:00
local medhr = 18 * 3600 + 0 * 60 – 18:00
local lowhr = 21 * 3600 + 0 * 60 – 21:00

local halldimmer = 54

if (current_second > highhr) and (current_second < medhr) then
luup.call_action(“urn:upnp-org:serviceId:Dimming1”, “SetLoadLevelTarget”, {newLoadlevelTarget = “100”}, halldimmer)
else
return false
end

if (current_second > medhr) and (current_second < lowhr) then
luup.call_action(“urn:upnp-org:serviceId:Dimming1”, “SetLoadLevelTarget”, {newLoadlevelTarget = “50”}, halldimmer)
else
return false
end

The GUI scene itself then turns the light on at the middle of the night level. That way all issues with the midnight crossover would seem to be avoided in the LUA code.

The results I am getting with this seem to be my 100% light during the day, but no action at other times.

Thanks for your help.[/quote]

You end if you fail the first conditional with a return false. You should use else if after the first test. “else
return false”

EDIT: My example wasn’t clear…

[size=11px][/code]
if (current_second > highhr) and (current_second < medhr) then
luup.call_action(“urn:upnp-org:serviceId:Dimming1”, “SetLoadLevelTarget”, {newLoadlevelTarget = “100”}, halldimmer)
else if (current_second > medhr) and (current_second < lowhr) then
luup.call_action(“urn:upnp-org:serviceId:Dimming1”, “SetLoadLevelTarget”, {newLoadlevelTarget = “50”}, halldimmer)
else
return false
end

[/size][/size]

You may want to check out this thread also:
http://forum.micasaverde.com/index.php/topic,7860.0.html

FYI,

Got this working to my satisfaction. Now I have a scene called Autolevel that sets the intensity only in the LUUP code, the UI5 graphical interface contains no commands. Gives me three different intensities out of the scene controlled based upon the time of day. Here is the LUUP coding…

local t = os.date(‘*t’)

local current_second = t.hour * 3600 + t.min * 60 – number of sec since midnight
local highhr = 6 * 3600 + 0 * 60 – 06:00
local medhr = 18 * 3600 + 0 * 60 – 18:00
local lowhr = 21 * 3600 + 0 * 60 – 21:00

local halldimmer = 54

if (current_second > highhr) and (current_second < medhr) then
luup.call_action(“urn:upnp-org:serviceId:Dimming1”, “SetLoadLevelTarget”, {newLoadlevelTarget = “100”}, halldimmer)
else

    if (current_second > medhr) and (current_second < lowhr) then
         luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", {newLoadlevelTarget = "40"}, halldimmer)  
    else

         luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", {newLoadlevelTarget = "15"}, halldimmer)  
    end

end

To do this, I suggest adding the following code before the others IFs:

local v = luup.variable_get(“urn:upnp-org:serviceId:Dimming1”, “LoadLevelTarget”, halldimmer)
if (v==“40” or v==“15”) then
luup.call_action(“urn:upnp-org:serviceId:Dimming1”, “SetLoadLevelTarget”, {newLoadlevelTarget = “100”}, halldimmer)
else