Scene that will set a light level dependent on Time of Day

Hello All,
I’ve been searching for some examples of how to accomplish this. I basically have a switch assigned to a scene that simply turns a light on. I really want this Scene to set the brightness up or down dependent on the day (particularly around sunset)
So activating the scene after sunrise will turn brightness to 100%
Brightness 1 hour before Sunset will be 80%
Brightness at sunset will be 70%
1 hour after sunset will be 60%

There was another thread that Woodsby replied stating he was doing something very similar:
But no response from him :-\

If anyone can point me in the right direction or provide an example of how to accomplish this, it will make my investment a lot more enjoyable.

Thank you,

Maybe you can find this thread useful:

Not quite what i’m looking for, but I appreciate it, and that is one of the threads that inspired this request.

More specifically i’m looking to hit the “ON” button, and the light will be set to a certain dim % dependent on the time of day.

I actually found another thread with luup code to set it up based on “night” but that is only one variable, i’m looking for a 1 hour before sunset, and 1 hour after sunset, 2 hours after sunset etc…

So the Scene will be triggered by the device turning ON, and set dim level appropriately.


You could use Heliotrope (better adaption to the variable day length) or DAD.

The following code (untested, may contain typos/bugs) is based on DAD:

local DAD_device_id    =  11 -- adjust accordingly
local dimmer_device_id =  22 -- adjust accordingly

local sunset_timestamp = tonumber( luup.variable_get( 'urn:upnp-ap15e-com:serviceId:DAD1', 'Sunset', DAD_device_id ) or 0 )
local delta_h = ( sunset_timestamp - os.time() ) / 3600
local dim_level

if delta_h > 3 or delta_h < -7
  if luup.is_night()
    dim_level = 0
    dim_level = 100
  dim_level = math.floor( ( delta_h + 7 ) * 10 + 0.5 )
-- one never knows ...
dim_level = math.min( 100, dim_level )
dim_level = math.max(   0, dim_level )
luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", { newLoadlevelTarget = dim_level }, dimmer_device_id )

[tt]is_night() -> luup.is_night()[/tt]

What kind (model) switches are you looking to use? From your other post I get the impression it’s regular light switches, not a scene controller, and you’re looking to have Vera quickly adjust to the desired dim level after the light has come on?

I’m using the GE/Jasco Dimmers, and Vizia 4 button Zone Controllers.
Thank you for that code above, i’m not savvy enough to understand what some of those variables are, but I will paste it, and see what happens. I also have tech support working on this as well so I will be sure to post their code as well.
If anyone uses the code above in the meantime with success or makes changes / fixes to it, please post.

Ultimately once the right code and behavior is established it would be great to allow for ONE scene to be present and control all the dimmers in the house with this behavior instead of creating 40 scenes (1 for each dimmer)

Thank you!

OK; thanks.

The in-wall dimmers or the plug-in modules?
Are you looking to control the dimmers solely with the zone controllers, or would you also operate the dimmers with their local button?

In other words, I’m still not clear on what the event is that will trigger the scene you are describing. Is it switching the local dimmer ([tt]A device is turned on or off[/tt]), a button on the zone controller ([tt]A scene is activated[/tt]), possibly both?

These are in-wall wired dimmers and controllers.

I want to turn on any light in my house with the local switch and have that particular light’s brightness be determined by the hours around “sunset and sunrise” (the topic states “time” but really i’m looking for the solution based on light conditions outside)

So if it’s a group of lights assigned to a Zone, Scene, or simply a single light, whatever light(s) we’re turning on will only turn on to the brightness defined below:
Ideally these would be the rules;

DURING THE DAY (1 hour after sunrise, and 1 hour before sunset) brightness = 100%

1 Hour BEFORE sunset brightness = 80%
Within 10 minutes of sunset, brightness = 70%
1 hour AFTER sunset brightness = 60%
2 hours after sunset brightness = 40%
3 hours after sunset brightness = 20%

I dont want a timer that is set to dim in increments (I already use this for the patio lights).

Now that I’m thinking about this from a programming point, i’m wondering if there could be a script that globally goes through all interior dimmers (defined by device#?) and sets the brightness to these levels IF ALREADY ON, but ALSO be responsive enough to Catch a light that is currently off and being turned on by someone in the house to automatically set the level to the guidelines above. (I say “responsive” enough" because it needs to catch the light at the time it’s being turned on, not check it later then dim after 5 minutes or something).


The GE’s don’t support associations, i.e. they do not report back to Vera when switched on/off. But as far as I can tell MCV uses a workaround so you will see an ‘instant’ update in some cases. Probably only when the switch is close enough to Vera. And only when switched on the primary switch (not the auxiliary ones, in case of multi-way setups).

I guess ideally, you’d want to be able to preset the dim-level on each dimmer based on your requirements, without turning the load on; but I’m not aware of a way to do that.

It doesnt need to make the level a preset. There is a luup code in another thread I used that check if_night and sets the max brightness to 40% and that works flawlessly with the event “a light is switched on”. There appears to be no delay.
The problem is that only allows 1 setting, and I need to create that scene for EVERY dimmer.


I’ve been trying to get your code above to work with no such luck.

Nothing happens, i’ve pasted it in a LUA code checker and get this:
input:4: attempt to index global ‘luup’ (a nil value)

No errors coming from the Vera however so i’m not sure if it’s because i’m testing at 7:55am which is 20 minutes AFTER sunset accorded to DAD.
I have it setup as a Scene with the event (the subject device is turned on)

If this works as needed, that would be great, the next step would be to have this 1 scene allow for multiple devices, but ONLY manipulate the respective device, not all.

Copy the code into the ‘MiOS developers’ -> ‘Test Luup code (Lua)’ window, adjust the device ids and click ‘Go’. If it’s working from there, something is wrong with your scene setup or your devices do not report back to Vera when switched on/off.

It says code failed.

Im testing on the ge dimmer. Can you give it a shot?


Code updated, please try again.

Code failed again :frowning:

The script works for me. I’m clueless … You should check the LuaUPnP logfile for errors.

Ok, so It must have been some copy past issues (i was doing it from an ipad >:()
So i’m testing right now, it’s 6:50am. Definately “night”. And running this code sets my dimmer to 0. I was hoping since it’s night it would set it to “15%” so I changed the code to dim_level = 15 after your if/else statement.

I’m trying to wrap my head around what numbers are being created for the sunset_timestamp and os.time, i’m assuming something like 1934 for sunset (7:34pm). is that a correct assumption?


The numbers that are in the region of 1.3 billion are Unix epoch time. That Wikipedia page links to a ton of online converters.

Perhaps I just need to test this in the evening, but I was hoping this would also work in the morning so if it’s just after sunset the level is set to 30%, and 30 minutes after sunset its set to 40% or something relative like that… Thats why I was asking about the math involved.
Heading to work, thanks all!

Please find attached a visualization of the dimming level for sunrise at 9:00 and sunset at 16:00. It should match your requirements outlined at [tt][/tt].