More intelligent lighting scene?

I have a few lights that are triggered by sensors. They work well, until I want to change the light manually.

What the event does now:

Luup script: If the light is off (sometimes wrong),
Turn on the light to 20%
Wait 3 minutes
Turn it off.

What I really want it to do:

  1. Poll the light switch and get its real status
  2. If the light is off - turn it on to 20%
  3. Wait 3 minutes
  4. Poll the light switch again
  5. If the light is still at 20%, turn it off.

Is this possible? I’v seen that there is a way to initiate a poll request:


The first part seems like it should be straightforward, but I’m not sure how to schedule another block of luup code to run 3 minutes later. I’ve read that there are problems with using “sleep” in an event, and it seems like it could be messy (what happens if the event fires again while the script is sleeping?)

You can put that block of code in a function and call it 3 minutes later with:


djrobx, I do something similar with my foyer lights at sunrise and sunset… for example, an hour before sunset, vera checks the level of the foyer lights, and based on that level, vera dims up the lights one percent at a time to end up at 60% at sunset, and it keeps going until it ends at 80% 20 minutes after sunset. Before dimming up a percent every minute, it verifies that the level is where it was set a minute before - that way if I manually control the lights during that 80 minutes, vera stops messing with it.

@woodsby, could you share with the rest of us as to how you accomplished this e.g. LUA and setup schema? Many thanxs in advance Mike

@Woodsby - Please enlighten us with the code. Thanks

Bump… @woodsby. Looks like your back… Welcome!
Please advise, thanks

Guys - just a disclaimer - this has been working only 95% of the time lately, and can only be intervened with manually… meaning if you adjust the lights from another non-vera controller, chances are vera will not pick up the intervening control. This is not actually polling every minute - what happens is, as long as your dimmer is associated with vera, the dimmer tells vera it’s light level every time it’s manually adjusted - well, at least the Leviton’s do. I remember having some association issues with the Homepro’s a few years ago, so I don’t know about those.
Anyway, I created a scene and put the below in the luup scene page. Please note this is one of the first luup scenes I created (back on UI2), and it’s probably not the cleanest code. I am running this on UI4 now. You can follow the code - it doesn’t run if the lights are already at 50% or higher. If it’s less than 50% but greater than 0%, it delays that number of minutes before starting the Dim On process. Every minute, it checks what the light level variable should have been against what it is, and dims or stops accordingly. You may want to tweak it so that it dims 3% every 3 minutes (or more), which would minimize the potential failures, and allow for actual polling. Or, you can insert the OP’s poll code… I haven’t tested that, but I think I’ll try it this evening. The one thing I don’t know about is if the poll command actually gets a chance to complete prior to running the next line of code, or if you need to build in a delay to allow the poll to complete.

local FoyerDev = 11
local FoyerNewLevel
local FoyerCurrentLevel =  luup.variable_get("urn:upnp-org:serviceId:Dimming1", "LoadLevelStatus", FoyerDev)
FoyerCurrentLevel = tonumber(FoyerCurrentLevel)

function StartSunsetFoyerDimOn()
  FoyerNewLevel =  luup.variable_get("urn:upnp-org:serviceId:Dimming1", "LoadLevelStatus", FoyerDev)
  if (FoyerCurrentLevel == tonumber(FoyerNewLevel)) then

function SunsetFoyerDimOn()
  FoyerNewLevel =  luup.variable_get("urn:upnp-org:serviceId:Dimming1", "LoadLevelStatus", FoyerDev)
  if (FoyerCurrentLevel == tonumber(FoyerNewLevel)) then
    if (FoyerCurrentLevel < 80) then
      FoyerCurrentLevel = FoyerCurrentLevel + 1
      luup.call_action("urn:upnp-org:serviceId:Dimming1","SetLoadLevelTarget",{ newLoadlevelTarget= FoyerCurrentLevel },FoyerDev)
      luup.call_timer("SunsetFoyerDimOn","1", "1m", "", "")

if (FoyerCurrentLevel < 50) then
  if (FoyerCurrentLevel > 0) then
    local startDelay = tostring(FoyerCurrentLevel) .. "m"
    luup.call_timer("StartSunsetFoyerDimOn","1", startDelay,"","")