local LIGHTS = { 23, 99 } – Device # of the lights. For a single light this looks like this: { 23 }
local LAMP_ON_LEVEL = “100” – %
local LAMP_OFF_LEVEL = “0” – %
local TURN_OFF_DELAY = 8 – Seconds
– Constants
local DIMMING_SID = “urn:upnp-org:serviceId:Dimming1”
– Functions
– Concatenates a table using kev-value pairs.
– e.g. { [“a”] = 68, [“b”] = 69} : a=68,b=69
– ‘sepp’ is the pairs separator
– ‘sepkv’ is the key-value separator
function table.serialize (t, sepp, sepkv)
local sepp = sepp or “,”
local sepkv = sepkv or “=”
local s = “”
for k, v in pairs(t) do
if type(v) ~= "table" then
s = s .. tostring(k) .. sepkv .. tostring(v) .. sepp
end
end
return string.sub(s, 1, -(#sepp + 1))
end
– Splits a string using the given separator.
function string.split (s, sep)
local sep = sep or “,”
local t = {}
local pattern = string.format("([^%s]+)", sep)
s:gsub(pattern, function(w) t[#t + 1] = w end)
return t
end
function string.deserialize (s, sepp, sepkv)
local sepp = sepp or “,”
local sepkv = sepkv or “=”
local t = {}
local t1 = string.split(s, sepp)
for _, v in pairs(t1) do
local t2 = string.split(v, sepkv)
t[ t2[1] ] = t2[2]
end
return t
end
local function turnOnLights()
local previousLevels = {}
for _, light in pairs(LIGHTS) do
local previousLevel = luup.variable_get(DIMMING_SID, “LoadLevelStatus”, light) or “”
if previousLevel == “” then
previousLevel = LAMP_OFF_LEVEL
end
previousLevels[light] = previousLevel
luup.call_action(DIMMING_SID, “SetLoadLevelTarget”, { newLoadlevelTarget = LAMP_ON_LEVEL }, light)
end
-- Pass a parameter containing the timestamp and the levels to dim the lights to.
-- e.g. "1355230628|45,78"
luup.call_delay( "turnOffLights", TURN_OFF_DELAY, os.time() .."|".. table.serialize(previousLevels) )
end
function turnOffLights (param)
local timestamp = param:match(“^(%d+)|”)
if os.difftime( os.time(), timestamp ) < TURN_OFF_DELAY then
return
end
local previousLevels = param:match("|([%d,=]+)$"):deserialize()
for _, light in pairs(LIGHTS) do
luup.call_action(DIMMING_SID, "SetLoadLevelTarget", { newLoadlevelTarget = previousLevels[tostring(light)] }, light)
end
end
– Main
turnOnLights()
thats for brightness