Lights on before sunset


I am trying to find a code which can;

Dim up +%20 every 5 minitues before sunset (light will be on 25 min. before sunset and %100 when its sunset)

opposite of this;
Dim down -%20 every 5 minitues before sunrise (light will be off when its sunrise)


Create a timer with a start time at 25 minutes before sunset and off time 25 minutes before sunrise.

Call it Night

Create a condition called Level.

It’s value is:

Night ? (((Level ; Now > 4:59) and (Level < 100)) ? Level + 20 : Level) : (((Level ; Now > 4:59) and (Level > 0)) ? Level - 20 : Level)

Wow. … That’s complicated!

Now create an action … Set your light to 100 percent.
Then go to the advanced tab for the action and change the 100 to

You are done!
If you understand all of the details to this solution you will be a PLEG master!

I dont know how to create a timer?

What will this code do? (((Level ; Now > 4:59) and (Level < 100)) ? Level + 20 : Level) : (((Level ; Now > 4:59) and (Level > 0)) ? Level - 20 : Level)

Is “action” to lua code? or where to create?

Is there any ready solution code?

This code is for the PLEG plugin. You’ll need to install the PLEG and PLC from the apps section of the Vera UI.

  • Garrett

I cheated on this in the past i think . I just created two schedules. One 20 minutes before sunset, and the other just at sunset. For the two conditions I just set the schedule name, and the action for each of the conditions is the setting of the lights.

I figure you can do the same with 5 schedules (-25,-20,-15,-10,-5,0), however nowhere as elegant as Richards solution of course.

Thanks all of you.

I see this plugin first time now ouchhh! This is beyond of a plugin:)

I want to test somethings like;

1-schedule is interval 15 secs named Night

2-Night ? (((Level ; Now > 00:03) and (Level < 100)) ? Level + 20 : Level) : (((Level ; Now > 00:03) and (Level > 0)) ? Level - 20 : Level))

3-Level as you said Ricard

Now why doesnt it dim up +20 every 3 secs and after 15secs dim down -20?

Can i make more than 1 scene or just 1 ?

Awesome i really love it!

NOW is equivalent to a 1 Minute interval timer … So it only evaluates conditions every minute.

This didnt work for me.

How can i dim up (in 5 minutes) +20 +20 +20 +20 +20 in 1 scene?

If you want to do it in a scene, add the following code in LUUP. Change dID to the device ID of your dimmer. The code will increase the dimmer level by 20 every 60 seconds until it reaches 100.

[code]local dID = 99

function dimUp20(devstr)
local dev = tonumber(devstr)
local curlev = tonumber((luup.variable_get(“urn:upnp-org:serviceId:Dimming1”,“LoadLevelStatus”,dev)))
local newlev = curlev + 20
if newlev > 100 then newlev = 100 end
if newlev < 100 then luup.call_delay(“dimUp20”,60,dev) end


Wow thank you RexBeckett!

In which platform did you write this?

In which platform did you write this?
Do you mean what tool did I use to write the Lua code? I used [url=,17780.msg138343.html#msg138343]ZeroBrane Studio[/url] which supports Vera's [i]luup[/i] library and allows testing by connecting to Vera.

You could also use Lua for Windows but this does not know about luup so cannot test the whole code. You can also use Notepad++ or any text editor to write the code and then paste it into APPS, Develop Apps, Test Luup code (Lua) for testing.

I will try ZeroBrane Studio later.

What is lua code for; open lights 15 minutes before sunset or 15 minutes lafter after sunrise?

You can do this under the scene editor in the schedules section.

  • Garrett

Thank you Garett,


Is it possible to use time under 1 sec?

RexBeckett wrote;

if newlev < 100 then luup.call_delay(“dimUp20”,60,dev) end

I changed 60 to 1 but im trying more smoother on/off