Motion Detectors and Lights

Hello

I have everspring motion detectors working in conjunction with fibaro dimmers, to turn the lights on when they sense motion

They then turn off after 3 minutes.

A problem though

If the light has been turned on manually, say were having a meal in the dining room, then the sensor is triggered by movement, it turns the light off after 3 mins, and we have to wave our hands frantically to trigger it again. How can I make the switch override the sensor?

You need to use scenes in Vera, and arm/disarm the motion detector. You can’t have the motion detector controlling the lights directly.

Create a scene called “Lights on” and set a trigger for “an armed sensor is tripped” then select your motion sensor, and then select “device armed is tripped” and adjust the devices in the scene accordingly.

Create a scene called “Lights off” and set a trigger for “an armed sensor is tripped” then select your motion sensor, and then select “device armed is untripped” and adjust the devices in the scene accordingly.

Then you can arm/disarm your motion sensor. Arm it only when you want them to be automatic (at night, when away, etc). Disarm it when you want them to be operated just by the switch (when you are home, daytime, etc).

I have scenes with triggers similar to how you have described. These are great as I live in a 3 story house, were on the top floor, baby on the middle floor, kitchen on the ground

Middle of the night i can find my way no problem. These scripts only run 8pm - 7am using luup

However along the way is the dining room, which i want to be able to leave on. Are you saying the only way I can stop the scene detecting motion and activating the scene is to disarm it? And if so how would you suggest disarming it, in a practical environment, one in which i would remember to re-arm at bedtime.

in the ideal world the switch would stay on if in the on position and operated manually, or run automatically in the off position

Which UI are you running? I’m still on UI4 but it is pretty easy using a scene. In the “Commands” tab when you create the scene check the box for the light you want to turn on, change it from “And leave it” to “After 3 minutes” which will bring up another menu for the action to take after 3 minutes. Choose “Go back to previous setting” and if the light was on when the motion sensor tripped it the light will stay on, but if it was off Vera will turn it back off. I do this with my basement lights which are turned on by the Schlage door lock. When the door is opened by a valid PIN the lights go on, and if they were off they go back off after 5 minutes. But if they were on (i.e., someone is doing something in the basement and had the lights on) they stay on.

UI5 - ive just found the little red arrows so trying your method!

Also, you could increase the sensitivity of your sensor, if supported. But that still may not be enough, so I have a dinner scene on a zone controller in the dining room. We hit that before dinner. It sets various lights to the right levels and puts the motion sensor that normally controls the lights in bypass. Also, there’s a second button that controls just the arm/bypass state of the motion sensor.

You can do something like this:

light = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”,“Status”,18)

if(light == “0”)then
return true
else
return false
end

As long as you have a scene that has the motion device as the trigger, you can add the above code into the luup section of the scene. Change “18” to the device number of the light. What this does is if the light is off, and the trigger of the motion is activated, the light will turn off. If the light is already on, it will not trigger the scene.

  • Garrett

Hi Garrett

Thanks for that. Previous state wasn’t really working, as if it got triggered and the light was already on, then the scene would run again and just leave the light on.

A scene controller might be an idea, we’ll see

I have written the following taking bits of code from a range of places to write my “find the bathroon” scene but my issue is that I have have the lights switch off on a 3 min delay once the scene is triggered through the standard device UI and not luup so although the lights don’t dim they still turn off after three minutes…

What would the luup code be to put the delayed off in the code where I can have the conditions.

[code]light51 = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”,“Status”,51)
light52 = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”,“Status”,52)

if (luup.is_night()) then

if (light51 =="0") then
     luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", {newLoadlevelTarget = "10"}, 51)

–this is where I need the delay statement

end                  

         if (light52 =="0") then
                luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", {newLoadlevelTarget = "10"}, 52)

–this is where I need the delay statement
end
return true
end

return false

[/code]

my new luup code is as follows - Quick Tip use “if not (luup.is_night()) then” to do testing in daytime.

This works however if the motion sensor is triggered again whilst the light is still on before the 3 minute timer, this is not reset, i will be investigating this and potentially looking at the countdown timer but not sure if there is an easier way.

[code]skip = luup.variable_get(“urn:upnp-org:serviceId:VSwitch1”,“Status”,34)
function lightoffdelay51()
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”, “SetTarget”, {newTargetValue = “0”}, 51)
end

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

if(skip==“1”)then
return false
else

light51 = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”,“Status”,51)
light52 = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”,“Status”,52)

if (luup.is_night()) then

if (light51 =="0") then
luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", {newLoadlevelTarget = "10"}, 51)
luup.call_delay('lightoffdelay51', 180)
     
end                  

         if (light52 =="0") then
            luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", {newLoadlevelTarget = "10"}, 52)
	luup.call_delay('lightoffdelay52', 180)
                             
         end

return true
end

return false
end
[/code]

Hi

What do you have in the device 34?

But if the tripped status remains for one minute and your light for 3 minutes, what happen if the device 34 will be retripped in the remaing two minutes?

ok let me provide a little more detail, this luup code is triggered by the motion sensor being triggered, this is done in the GUI, device 34 is my “Party Mode” virtual switch. I have this at the start of most of my scripts as if im entertaining then I generally don’t want anything to trigger automatically.

the motion sensor will continually be tripped but the way i have it set up at the moment means that it doesn’t fire if the light is already on code[/code] but also means it doesn’t reset the timer. I could do a check i guess on the brightness, ie if equal to 10% then reset timer but this does have its risk associated with it in that i could set it to 10%

Ok I have finally achieved what i wanted to do with the following

I have a scene which is triggered by the respective countdown timer going “ding” which turns the lights off and my way to essentially stop this happening if I do want to keep the lights on is to cancel the timer, I do this by turning the lights on too 100%l, as long as the motion sensor is triggered after this (which hopefully will be impossible not to do) then the lights will stay on and the motion sensor triggering from then on will not do anything as the lights will be on.

I know there is probably ways to make the code a little more efficient (that was never my strong point) but I’m happy for now!

[code]-- String “0” (not counting down) or “1” (counting down).
isCounting68 = luup.variable_get(“urn:futzle-com:serviceId:CountdownTimer1”, “Counting”, 68)
isCounting69 = luup.variable_get(“urn:futzle-com:serviceId:CountdownTimer1”, “Counting”, 69)
– device 34 is party mode switch
skip = luup.variable_get(“urn:upnp-org:serviceId:VSwitch1”,“Status”,34)
light51 = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”,“Status”,51)
light52 = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”,“Status”,52)
light51level = luup.variable_get(“urn:upnp-org:serviceId:Dimming1”,“LoadLevelStatus”,51)
light52level = luup.variable_get(“urn:upnp-org:serviceId:Dimming1”,“LoadLevelStatus”,52)

if(skip==“1”)then
return false
else
if (luup.is_night()) then
– 51 Hallway
– 69 -Nightlight Hallway timer
if (light51 ==“0”) then
luup.call_action(“urn:upnp-org:serviceId:Dimming1”, “SetLoadLevelTarget”, {newLoadlevelTarget = “10”}, 51)
luup.call_action(“urn:futzle-com:serviceId:CountdownTimer1”, “StartTimer”, {}, 69)
else
if (light51 ==“1”) and (isCounting69 ==“1”) and (light51level ~=“100”) then
luup.call_action(“urn:futzle-com:serviceId:CountdownTimer1”, “RestartTimer”, {}, 69)
else
if (light51 ==“1”) and (isCounting69 ==“1”) and (light51level ==“100”) then
luup.call_action(“urn:futzle-com:serviceId:CountdownTimer1”, “CancelTimer”, {}, 69)
end
end

	end                  
-- 52 Landing
-- 68 LandingNighlight Time    
			 if (light52 =="0") then
				luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", {newLoadlevelTarget = "10"}, 52)
				luup.call_action("urn:futzle-com:serviceId:CountdownTimer1", "StartTimer", {}, 68)
					else 
						if (light52 =="1") and (isCounting68 =="1") and (light52level ~="100")  then
							luup.call_action("urn:futzle-com:serviceId:CountdownTimer1", "RestartTimer", {}, 68)
							else
								if (light52 =="1") and (isCounting68 =="1") and (light52level =="100")  then
									luup.call_action("urn:futzle-com:serviceId:CountdownTimer1", "CancelTimer", {}, 68)
								end	
						end	
			end
	return true
end

return true
end

– Actions for countdowntimer are: StartTimer, RestartTimer, CancelTimer, ForceComplete
[/code]

wouldn’t this be better? I know this post is old but just trying to help out…

Scene that turns on the light when it detects movement and turns off the light when it doesn’t detect movement for a while

  1. Create a scene to turn on the light when a sensor is tripped.
  2. Add this code in the Luup code section:

[code]local sensorDeviceNo = 16 – Motion Sensor device number
local lightDeviceNo = 13 – Light device number
local period = 10 – Seconds

local SS_SID = “urn:micasaverde-com:serviceId:SecuritySensor1” – Security Sensor Service ID
local SP_SID = “urn:upnp-org:serviceId:SwitchPower1” – Switch Power Service ID

function checkLastTrip()
local lastTrip = luup.variable_get (SS_SID, “LastTrip”, sensorDeviceNo) or os.time()
if (os.difftime (os.time(), tonumber (lastTrip)) >= period) then
luup.call_action (SP_SID, “SetTarget”, {[“newTargetValue”] = 0}, lightDeviceNo) – Turn off the light.
else
luup.call_delay (“checkLastTrip”, period) – Check when the sensor was last tripped every seconds.
end
end

luup.call_delay (“checkLastTrip”, period)

return true[/code]

thanks for responding, i did in fact end up getting rid of this scene as i had issues with the countdown timer plugging causing lockup issues on the vera. I’ve found a solution but its not perfect and have been thinking about investing some time in sorting this out. I like to have a manual overide so that if i turn the light on to 100% then all automation stops but I can probably just add a step into your script to query the light level and return false, now on to your solution - i can see that this would be great to turn on the device but how to you turn the device off if there is no tripping of motion sensor or does the function just loop until the fact that the motion sensor hasn’t triggered for 10 seconds and then turn it off…

[quote=“garrettwp, post:7, topic:171074”]You can do something like this:

light = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”,“Status”,18)

if(light == “0”)then
return true
else
return false
end

As long as you have a scene that has the motion device as the trigger, you can add the above code into the luup section of the scene. Change “18” to the device number of the light. What this does is if the light is off, and the trigger of the motion is activated, the light will turn off. If the light is already on, it will not trigger the scene.

  • Garrett[/quote]

This works great…

I am reading about combining multiple conditions and don’t have the formatting down right.
I would like to add to the above:

if (luup.is_night()) then
return true
else
return false
end

If I just add it in it errors… so I’m not sure how to add the night condition to the script ???

I think your missing an “end” but i could be wrong as im no coding pro but you could give it a go whilst waiting for others to respond.

Both those chunks of code work by themselves
I just need to put them ion one LUUP script.

ok, this may help or it may confuse things, this is a script which works fine on mine, you may be able to adapt to fit.

[code]- device 34 is party mode switch
skip = luup.variable_get(“urn:upnp-org:serviceId:VSwitch1”,“Status”,34)
light51 = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”,“Status”,51)
light51level = luup.variable_get(“urn:upnp-org:serviceId:Dimming1”,“LoadLevelStatus”,51)

if(skip==“1”) or (luup.is_night())then
return false
else
– 51 Hallway
if (light51 ==“1”) and (light51level ==“100”) then
return false
else
return true
end

return true
end[/code]

so what does this do exactly?

[quote=“trouty00, post:19, topic:171074”]ok, this may help or it may confuse things, this is a script which works fine on mine, you may be able to adapt to fit.

[code]- device 34 is party mode switch
skip = luup.variable_get(“urn:upnp-org:serviceId:VSwitch1”,“Status”,34)
light51 = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”,“Status”,51)
light51level = luup.variable_get(“urn:upnp-org:serviceId:Dimming1”,“LoadLevelStatus”,51)

if(skip==“1”) or (luup.is_night())then
return false
else
– 51 Hallway
if (light51 ==“1”) and (light51level ==“100”) then
return false
else
return true
end

return true
end[/code][/quote]