Synology Diskstation & Cameras

I think the runIn call in the handleMotion method might fail periodically and leave the cameras stuck on. I haven’t seen this happen, but I’ve seen my cameras get stuck activated. No further motion events will be registered.

So I put in a redundant scheduled call. I have it calling the cleanup method every 5 minutes. So far things have been stable for over a day.

btw. I renamed handleMotion for my own benefit, since it’s not really handling motion. It’s handling deactivating, cleaning up after motion. I just did this:

// runIn appears to be unreliable. For backup, schedule a cleanup every 5 minutes
def doAndScheduleHandleMotion() {
handleMotionCleanup()
// This orverwrites any other scheduled event. We’ll only get one extra call to handleMotion this way.
runEvery5Minutes( “handleMotionCleanup” )
}

// Deactivate the cameras is the motion event is old. Runs itself again in the least time left.
def handleMotionCleanup() {
def children = getChildDevices()
def nextTimeDefault = 120000; //1000000
def nextTime = nextTimeDefault;
log.debug “handleMotionCleanup”

children.each {
	def newTime = checkMotionDeactivate(it)
    if ((newTime != null) && (newTime < nextTime)) {
    	nextTime = newTime
    }
}

//log.debug “handleMotion nextTime = ${nextTime}”
if (nextTime != nextTimeDefault){
log.trace "nextTime = " + nextTime
nextTime = (nextTime >= 25) ? nextTime : 25
runIn((nextTime+5).toInteger(), “handleMotionCleanup”)
}
}

I’m going to keep an eye on it and report back.