Time Delay for Presence Sensing


(Joe) #1

I am using a presence tag on my dog’s collar. He is kept contained by a Safer Barrier WiFi fence, but the range of his enclosure is larger than my z-wave mesh net. I have altered the timeout time on the hub to five minutes, but that does not seem to help. I am also worried that it will make my other sensors effectively worthless. As I am new to this, can someone tell me how to set his tag to not report away until he is gone for more than 10 minutes? Looking over the event log, he is rarely out of range for more than 5 or 6 minutes, but I am worried that if I change my hub to that timing, my other presence sensors will not work when they arrive home.


(Convinced ST will never be unbroken…) #2

The default “everyone leaves” app has a specific time delay you can set, and you can set which presence sensor(s) it uses to determine “everyone”. If you are already using that app for another purpose, you’ll need another with a similar timer function.

Off the top of my head I am not sure if there is already one in shared apps to do this but it’s worth a look. If you don’t find something usable let us know.


(Joe) #3

I looked through everything I could find regarding the presence tag, but I could not find anything that would allow a delay that can be applied to just a single tag. As I said, I am relatively new to this, and I am still working on getting the system I desire purchased and set up. This issue is the only irritation I have found so far. Everything else is working the way it should.


(Miguel Corteguera) #4

Hi Joe- I ran into a similar challenge tracking my dogs. In our case we have a doggie door and they come in and out at times. I really wanted to be notified only if they are missing more than 15 or 20 minutes.

I was looking through some of the sample apps out there and found something similar for the garage door being opened. So I combined it with another app that did the presence tracking. Below is the result.

You basically pick a presence sensor, pick the amount of minutes in delay before it notifies you, and you can put an SMS number to be texted (otherwise it will provide a push notification).

Hope this helps you and others out there. BTW I’m not a developer. I just know enough to be dangerous with coding so if there are any suggestions or improvements you can think of please pass them along.

/**

  • This application monitors presence sennsors and will send out an update
  • if they are not present for a user-defined amount of time. It will
  • continue to send updates at the same interval until presence is detected.
  • Author: Miguel Corteguera (created from a combination of SmartThings
  • presence and garage door monitoring apps)
    */

// Automatically generated. Make future change here.
definition(
name: “DoggieMonitor”,
namespace: “”,
author: “Miguel Corteguera”,
description: “Presence sensor delayed inform”,
category: “My Apps”,
iconUrl: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png”,
iconX2Url: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png”,
oauth: true)

preferences {
section(“When a presence sensor arrives or departs this location…”) {
input “presence”, “capability.presenceSensor”, title: “Which sensor?”
}
section(“For too long…”) {
input “maxGoneTime”, “number”, title: “Minutes?”
}
section(“Text me at (optional, sends a push notification if not specified)…”) {
input “phone”, “phone”, title: “Phone number?”, required: false
}
}

def installed() {
subscribe(presence, “presence”, presenceHandler)
}

def updated() {
unsubscribe()
subscribe(presence, “presence”, presenceHandler)
}

def presenceHandler(evt) {
def isNotScheduled = state.status != "scheduled"
if (evt.value == “present”) {
log.debug "${presence.label ?: presence.name} has arrived at the ${location}"
clearSmsHistory()
clearStatus()
} else if (evt.value == “not present”) {
log.debug "${presence.label ?: presence.name} has left the ${location}"
runIn(maxGoneTime * 60, takeAction, [overwrite: false])
state.status = “scheduled”
}

}

def takeAction(){
if (state.status == “scheduled”)
{
def deltaMillis = 1000 * 60 * maxGoneTime
def timeAgo = new Date(now() - deltaMillis)
def goneTooLong = presence.presenceState.dateCreated.toSystemDate() < timeAgo

	def recentTexts = state.smsHistory.find { it.sentDate.toSystemDate() > timeAgo }

	if (!recentTexts) {
		sendTextMessage()
	}
	runIn(maxGoneTime * 60, takeAction, [overwrite: false])
} else {
	log.trace "Status is no longer scheduled. Not sending text."
}

}

def sendTextMessage() {
log.debug “$presence has been gone too long, texting $phone”

updateSmsHistory()
def goneMinutes = maxGoneTime * (state.smsHistory?.size() ?: 1)
def msg = "Your ${presence.label ?: presence.name} has been gone for more than ${goneMinutes} minutes!"
if (phone) {
	sendSms(phone, msg)
}
else {
	sendPush msg
}

}

def updateSmsHistory() {
if (!state.smsHistory) state.smsHistory = []

if(state.smsHistory.size() > 9) {
	log.debug "SmsHistory is too big, reducing size"
	state.smsHistory = state.smsHistory[-9..-1]
}
state.smsHistory << [sentDate: new Date().toSystemFormat()]

}

def clearSmsHistory() {
state.smsHistory = null
}

def clearStatus() {
state.status = null
}