We have moved at community.getvera.com

Author Topic: Motion Detectors and Lights  (Read 23135 times)

Offline richskiddle

  • Sr. Newbie
  • *
  • Posts: 29
  • Karma: +0/-0
Motion Detectors and Lights
« on: March 29, 2012, 03:47:09 pm »
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?

Offline PurdueGuy

  • Hero Member
  • *****
  • Posts: 1169
  • Karma: +21/-0
Re: Motion Detectors and Lights
« Reply #1 on: March 29, 2012, 05:22:45 pm »
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).
Vera3, Leviton, Intermatic, SQ Blaster, HomeWave, DSC 1832, Insteon/Altsteon

Offline richskiddle

  • Sr. Newbie
  • *
  • Posts: 29
  • Karma: +0/-0
Re: Motion Detectors and Lights
« Reply #2 on: March 29, 2012, 05:58:13 pm »
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

guest13871

  • Guest
Re: Motion Detectors and Lights
« Reply #3 on: March 29, 2012, 06:35:13 pm »
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.

Offline richskiddle

  • Sr. Newbie
  • *
  • Posts: 29
  • Karma: +0/-0
Re: Motion Detectors and Lights
« Reply #4 on: March 30, 2012, 01:46:04 am »
UI5 - ive just found the little red arrows so trying your method!

Offline oTi@

  • Community Beta
  • Master Member
  • ******
  • Posts: 4041
  • Karma: +32/-6
  • UI what ?!
Re: Motion Detectors and Lights
« Reply #5 on: March 30, 2012, 06:30:33 am »
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.
Dezwaved at the moment...

Offline garrettwp

  • Master Member
  • *******
  • Posts: 6371
  • Karma: +227/-128
  • Vera 3, Lite, ISY994
Re: Motion Detectors and Lights
« Reply #6 on: March 30, 2012, 06:38:32 am »
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

Offline richskiddle

  • Sr. Newbie
  • *
  • Posts: 29
  • Karma: +0/-0
Re: Motion Detectors and Lights
« Reply #7 on: April 07, 2012, 10:31:51 am »
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


Offline trouty00

  • Full Member
  • ***
  • Posts: 207
  • Karma: +2/-1
Re: Motion Detectors and Lights
« Reply #8 on: April 08, 2012, 04:55:30 am »
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: [Select]
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


Offline trouty00

  • Full Member
  • ***
  • Posts: 207
  • Karma: +2/-1
Re: Motion Detectors and Lights
« Reply #9 on: April 17, 2012, 05:26:11 pm »

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: [Select]
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

Offline teonebello

  • Sr. Member
  • ****
  • Posts: 405
  • Karma: +0/-0
  • Macs, Home Automation, Bikers
Motion Detectors and Lights
« Reply #10 on: April 17, 2012, 05:51:14 pm »
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?

Offline trouty00

  • Full Member
  • ***
  • Posts: 207
  • Karma: +2/-1
Re: Motion Detectors and Lights
« Reply #11 on: April 18, 2012, 04:46:55 am »
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: [Select]
(if (light51 =="0")) 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%

Offline trouty00

  • Full Member
  • ***
  • Posts: 207
  • Karma: +2/-1
Re: Motion Detectors and Lights
« Reply #12 on: April 18, 2012, 06:31:38 pm »
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: [Select]
-- 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

Offline ryan219

  • Sr. Newbie
  • *
  • Posts: 27
  • Karma: +0/-0
Re: Motion Detectors and Lights
« Reply #13 on: January 22, 2014, 07:48:28 am »
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: [Select]
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 <period> seconds.
    end
end
 
luup.call_delay ("checkLastTrip", period)
 
return true
« Last Edit: January 22, 2014, 09:06:29 am by oTi@ »

Offline trouty00

  • Full Member
  • ***
  • Posts: 207
  • Karma: +2/-1
Re: Motion Detectors and Lights
« Reply #14 on: January 22, 2014, 09:53:49 am »
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..