Motion -> turn light on -> No Motion -> Return previous state

Very simple question…

I have a motion sensor which detects motion (SP814). I currently make:

  1. a scene (telling what light to turn on) on motion
  2. a trigger (in that scene) - an armed sensor is tripped - device armed is tripped

Then when motion is there, the light turns on…

but now how can I switch that light off? after x seconds or after no motion after x seconds… what is the best way for doing this? And most important. What if the light was already on? I dont want it to be switched off again.

I have searched on “motion on off” “motion restore previous state”, etc… but the answers al give me fragments off ideas but not a total simple solution. And I think I am looking to complex.

If you use the delay feature of a scene, you can do the on and off in one scene. this works fine for single devices. the exception being that a vera/lua restart during the delay will cancel the delayed scene.

for multiple devices to be controlled by a sensor, i use the countdown timer plugin with two scenes (on and off).

‘on’ scene: motion starts and restarts the timer
‘off’ scene: triggered by countdown timer finishing.

Hm… is there any other option?

This can be done with the just released Progam Logic Timer Switch plugin.

Switch Type (Delayed Toggle Explicit Reset)
RESET CONDITION When Light is turned Off
RESTART CONDITION When Light is turned On and Motion (Only if you want to extend the timer based on more motion)
TRIGGER CONDITION When Motion is detected and LIGHT IS OFF

Me I also have a DAYTIME device. That I (AND NOT DAYTIME) into the TRIGGER condition.

Two Scenes:
1) An Auto Light ON Scene
Triggered When Program Logic state is TRIGGERED
2) An Auto Light Off Scene
Trigger When Program Logic state is TOGGLED

Richard,

thanks for you reply… I have UI5…

I have read for hours how to make this possible to work… but as a newbie… and not a native English speaker this is very difficult, thus undoable for me ???.. Can you please help me? I don’t know what fields to fill “with what”…

BTW it really looks good!

Does the Smart Switch Plugin not do what you want?

No scenes required if you want the basic on/off based on motion. Just set it and forget it.

If you want to change the brightness based on time of day, etc. you can do that with scenes.

Hi, PudueGuy, whan trying to add my light (via zwave controlled dimmer) with ID 18 I receive:

Smart Switch : Add Switch: Invalid switch id (18)

I do have to add the ID of the switch which controls the lamp do I?

You are using the device ID, and not node/alt ID, correct?

Hi Pordueguy,

yes, correct device ID added… SS switch made. then added motion sensor…
It works…

but now, if my lamp is already on and motion is detected after timetout the light goed out again… how can i “go back to previous state”?

Sorry, your initial post described a different scenario than your subject.

You use cases are:
Scenario1) Light is on, motion is detected, turn light on, wait X minutes, leave light on
Scenario2) Light is off, motion is detected, turn light on, wait X minutes of no motion, turn light off

Since the light is already on in Scenario1, and you want to leave that on, that simplifies to:
Scenario1) Light is on, motion is detected, do nothing

Does that sound right?

The Smart Switch plugin doesn’t have a “forever” for the manual timeout (maybe you can ask that it be added?)

Hi All,

after a long time and some mail with MCV here’s my short exposure. I have got it working. At least for a dimmable light. It doesn’t matter on what level my light is. When there is movement on a motion sensor and the scene is tripped it gives my dimmable light a boost for an amount of time configured in the luup code. What I have done:

  1. create a scene
  2. do not take actions on devices
  3. create trigger (motion detector tripped)
  4. insert luup code (copy paste)

And change device ID to ID of dimmable light

This is the code (thanks to MCV):


– User configurable variables

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

Wow, pretty complicated.

As it was said above you may totally remove the vera from this case.
SP814 supports 2 groups. Group 2 is triggered taking to account lighting sensor. You can just setup you lighting sensor threshold and add you dimmer to group 2.