Restore dimlevel after temporary 100%

Hi all,

I have a PLEG to turn on outside lights to turn on to maximum brightness when motion is detected (during dark hours and not when i have a party outside).
Whenever these lights are already on (say when manually turned on) the lights remain at the current dimlevel (so lights do no change/nothing happens when there is motion).
So far so good…

What I want is the following. If the lights are turned on and manually set at a dimlevel of e.g. 30 and there is motion, the max brightness must be set for 2 minutes.
After those 2 minutes, the previously dimlevel must be restored. (in this example 30).

How do i save the dimming level and recall that value?

Also see the attached report.

Any suggestions?

would be something like storing a property of a device (dimlevel) and than - after a temporary full brightness - use that property to set the dimlevel back to its previous value.

Multistring plug in provides an easy way to store variables like that without having to learn Luna.

I found this awhile back (LINK)… but I have it doing exactly what you are asking. I have my front porch lights set at 40% from sunset to midnight. If there is motion when they are on, it will turn them up to 100% for 5 minutes, then return them to the previous set level. If they are off (after midnight) it will turn the on to 100% for five minutes, then off.

You will edit the local Lights with the device number of the lights you want to control, and adjust local TURN_OFF_DELAY for the duration.

– User configurable variables

local LIGHTS = { 10,9 } – 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 = 300 – 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

return string.sub(s, 1, -(#sepp + 1))


– 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


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]

return t


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
previousLevels[light] = previousLevel
luup.call_action(DIMMING_SID, “SetLoadLevelTarget”, { newLoadlevelTarget = LAMP_ON_LEVEL }, light)

-- 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) )


function turnOffLights (param)
local timestamp = param:match(“^(%d+)|”)
if os.difftime( os.time(), timestamp ) < TURN_OFF_DELAY then

local previousLevels = param:match("|([%d,=]+)$"):deserialize()
for _, light in pairs(LIGHTS) do
    luup.call_action(DIMMING_SID, "SetLoadLevelTarget", { newLoadlevelTarget = previousLevels[tostring(light)] }, light)


– Main