Author Topic: Only run scene if no motion detected for ten minutes  (Read 549 times)

Offline Callero

  • Newbie
  • *
  • Posts: 4
  • Karma: +0/-0
Only run scene if no motion detected for ten minutes
« on: December 04, 2017, 12:06:52 pm »
I have a scene that triggers on light level.
It basically cuts the light after sunrise.

But I don't want it to cut the light if the family is having breakfast, so I would like it not to run unless there has been no motion for ten minutes.

Can someone help point me towards a code example I could build on?

I'm a total Luup newbie, but I am somewhat proficient with JS and Python.

Offline melsman

  • Sr. Newbie
  • *
  • Posts: 46
  • Karma: +2/-0
Re: Only run scene if no motion detected for ten minutes
« Reply #1 on: December 07, 2017, 11:28:38 pm »
I have a similar routine that I run to turn off my garage light after 15 minutes if it sees no motion.  I use the countdown timer app to create a countdown timer (in my case, wittily called, "Garage Light Timer"), that I trigger when the garage light is turned on manually, or by motion sensor. (Using a scene called - again very wittily - "AutoOn Garage Lts").  Basically, I tell the countdown timer to "Restart" each time there is a motion or door sensor trigger, and the timer starts over, counting down to 0. 

However, the magic comes from using a scene called "AutoOff Garage Lts" that is triggered when the countdown timer completes.  Thus, if the timer counts down to zero without getting a motion or sensor trigger (and restarts because of the trigger), it triggers a scene that turns off the light.

Melsman

Offline RichardTSchaefer

  • Master Member
  • *******
  • Posts: 10059
  • Karma: +759/-141
Re: Only run scene if no motion detected for ten minutes
« Reply #2 on: December 08, 2017, 12:58:05 am »
If you want to get more serious about automation you might want to look at PLEG.
It's much higher level than LUA ... and all in one spot as opposed to a couple of scenes and a plugin that work together. There are many PLEG examples for this topic out there.

Offline Chrisfraser05

  • Sr. Member
  • ****
  • Posts: 449
  • Karma: +16/-31
Re: Only run scene if no motion detected for ten minutes
« Reply #3 on: December 08, 2017, 01:43:58 am »
Pleg is amazing to be fair

Offline jchin

  • Sr. Newbie
  • *
  • Posts: 41
  • Karma: +0/-0
Re: Only run scene if no motion detected for ten minutes
« Reply #4 on: December 30, 2017, 01:22:01 pm »
I have a similar routine that I run to turn off my garage light after 15 minutes if it sees no motion.  I use the countdown timer app to create a countdown timer (in my case, wittily called, "Garage Light Timer"), that I trigger when the garage light is turned on manually, or by motion sensor. (Using a scene called - again very wittily - "AutoOn Garage Lts").  Basically, I tell the countdown timer to "Restart" each time there is a motion or door sensor trigger, and the timer starts over, counting down to 0. 

However, the magic comes from using a scene called "AutoOff Garage Lts" that is triggered when the countdown timer completes.  Thus, if the timer counts down to zero without getting a motion or sensor trigger (and restarts because of the trigger), it triggers a scene that turns off the light.

Melsman


Would you mind sharing the code?


Offline RichardTSchaefer

  • Master Member
  • *******
  • Posts: 10059
  • Karma: +759/-141
Re: Only run scene if no motion detected for ten minutes
« Reply #5 on: December 31, 2017, 10:45:58 am »
You can use the Countdown timer and a couple of scenes for EACH door you want this behavior with.

Or you can use a single PLEG to do all of your doors and other activities.
I used Futzle's Countdown Timer and Combination plugins when I first started using Vera.
But I had to create so many Countdown Timer and Combination Plugin devices that I ran out of memory. Her countdown Plugin was the motivation to create PLTS and the Combination plugin motivate PLEG ... each condition in PLEG is like a single Combination plugin device. A single input timer in PLEG is like a single Countdown timer device. Using PLEG can save a lot of memory. A single plugin device in PLEG uses minimally 2 MB of memory.
This was really important on a Vera 3 and Vera Lite. Less important on newer devices with more memory. But there are other benefits to using PLEG as well.

Offline parkerc

  • Sr. Hero Member
  • ******
  • Posts: 2405
  • Karma: +33/-45
  • Life Moves Pretty Fast....
Re: Only run scene if no motion detected for ten minutes
« Reply #6 on: January 21, 2018, 12:10:44 pm »
I don't want it to cut the light if the family is having breakfast, so I would like it not to run unless there has been no motion for ten minutes.

Im doing this on the fly so cant test it, but maybe something like this to your scene would do what you want.

Code: [Select]
kitchen_motion_sensor_ID = 380
target_inactivity_in_minutes = 10

local lastTrip = luup.variable_get ("urn:micasaverde-com:serviceId:SecuritySensor1", "LastTrip", kitchen_motion_sensor_ID) or os.time()

inactivity_in_seconds = os.difftime (os.time(), lastTrip)
inactivity_in_mins = inactivity_in_seconds /60

if (inactivity_in_mins >= target_inactivity_in_minutes) then
return true -- to run scene
else
return false -- to not run scene
end
« Last Edit: January 21, 2018, 12:15:54 pm by parkerc »