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
device=k
device_type="None"
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
device_type=v2
end
end
-- 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]