Scene to turn off any light that has been on for x minutes?

This looks like it may involve some kind of complex programming?

Also, along the same lines, would like a scene that puts the brightness to 100% for any light that happens to be on and dimmed?

It seems there would be objects that give the current state of everything that I can iterate through?
I don’t want to hard-code any ids or anything.

This looks like it may involve some kind of complex programming?

It would involve a fair bit of programming. Probably not the best first project unless you are already familiar with Lua.

It would be less complex using the Program Logic Event Generator (PLEG) plugin. See PLEG Basics for an introduction.

Is there a way to get the state of each device without using the dreaded user_data XML? It seems that parsing the xml on the vera takes a prohibitively long period of time. I cannot believe I cannot easily and quickly get the devices and states easily from within the scripting language?


You also need to use luup.variable_get to get the actual state variables from the selected devices.

Preface - this is a huge issue that I cannot simply turn a dimmable light off while preserving its dim percentage state (like all my dim switches switches do) - perhaps I am overlooking something?

I finally got around to hacking something together - I don’t feel like formatting this or making it optimal, but here it is.
Turns off any dimmable light that has been on for more than 20 minutes. Unfortunately it does so by setting the LoadLevelStatus to 0 instead of turning the light off and preserving the dim state.
It uses the built in timestamp that tells when a variable has last been modified to do the timing calculation.

I think the variable times probably get reset whenever there is a reload or power cycle - not sure.
I put this code in a Manual Scene that runs every couple minutes.

[code]-- if (luup.is_night() == false) then

local device=0

– 20 minutes
local interval=1800

local device_type = “None”

local lightLevel=0

local tstamp=0

local currenttime=os.time()

for k, v in pairs(luup.devices) do

-- device=0

 for k2, v2 in pairs(v) do
    -- luup.log("Device #" .. k .. ":" .. k2 .. "=" .. tostring(v2))

    -- remove this - it is the altid - not sure what it is for
     -- if (k2=="id") then
        -- device=v2
     -- end

     if (k2 == "device_type") then 

 -- if it is on and is past the interval, turn it off

luup.log (device)
luup.log (device_type)

     if (device_type == "urn:schemas-upnp-org:device:DimmableLight:1") then

        lightLevel,tstamp = luup.variable_get("urn:upnp-org:serviceId:Dimming1", "LoadLevelStatus", device) -- variable_get returns 2 args

  luup.log (lightLevel)

luup.log (tstamp)
luup.log (currenttime)

if (tonumber(lightLevel) > 0) then
if (currenttime - tstamp > interval) then
luup.call_action(“urn:upnp-org:serviceId:Dimming1”, “SetLoadLevelTarget”, {newLoadlevelTarget=0}, device)
luup.log (“turning off”)
end --time check
end --it is on

end – correct device type

end --main loop

– end – night check[/code]

Couple of thoughts:

  1. There is a reported memory leak problem when using scenes triggered by regular time intervals (i.e. every hour). Keep this in mind should you start experiencing issues when Vera has not been rebooted in awhile.

  2. Have you tried using SetTarget to turn on/off the dimmer? This may preserve the dimming level.

luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“0” },DimingLightId)

Thank you for the suggestion - the settarget command works, but it does not preserve the dim level. I am guessing the switches have their own memory that keeps track of it.