How do you prolong a delay until everything quiets down?


(Ben Lebson) #1

I’ve created a SmartApp which will start video recording when there is motion/contact opens, etc. When an event happens it will turn on recording, then wait for a specified amount of time (or a specific amount of time after motion stops for a motion detector) and then it sends the command to stop recording.

Now here’s my issue; In a scenario where a contact opens and starts recording for 30 seconds and then motion starts 15 seconds later the camera will get the ‘on’ command twice, no big deal. But then when the initial delay hits at 30 seconds it will turn off the video recording even though there is still motion. How do I link it all together so that the video doesn’t stop until ALL devices go ‘quiet’ again?

The SmartApp in question: https://github.com/blebson/Smart-Security-Camera/blob/master/smartapps/blebson/smart-security-camera.src/smart-security-camera.groovy


(Kevin Tierney) #2

You need a state to track that everything is actually quiet. So when you turn it on you’ll need something like

state motionActive = true

Then when things die down, in addition to scheduling the turn off, set motionActive to false

In your video off section,check that motionActive is currently false before turning off

In the case that there’s new motion during the cooling off period, motionActive will be set back to true and the first scheduled off won’t do anything

Here’s the docs on using states
http://docs.smartthings.com/en/latest/smartapp-developers-guide/state.html


(Ben Lebson) #3

That makes sense, but how would I handle it when there is a motion event and after motion stops and the delay kicks in there is an open contact or other momentary trigger?


(Kevin Tierney) #4

This would work in the case where the 2nd active event happened during the runIn delay, and stayed active. If it happened to also go inactive during that delay, it would stop recording during the 1st delay

A better option would probably be to just unschedule all runIn’s each time you had a new active event
so before calling your runIn call unschedule(videoOff)
http://docs.smartthings.com/en/latest/smartapp-developers-guide/scheduling.html?highlight=runin#removing-scheduled-executions


(Ben Lebson) #5

For some reason I didn’t think unschedule affected the runIn command, I think this is the best way to handle it if it works properly.