Skip to content

Instantly share code, notes, and snippets.

@steve28
Created March 3, 2014 23:31
Show Gist options
  • Save steve28/9336914 to your computer and use it in GitHub Desktop.
Save steve28/9336914 to your computer and use it in GitHub Desktop.
/**
* Alert if garage doors are open
*
* Author: steve.sell@gmail.com
*
*
* Date: 2013-10-15
*/
preferences {
section("Select the Garage Controller") {
input "theGarage", "capability.poll", title: "Pick The Garage", required: true
input "timeout", "number", title: "Timeout (min) [Default: 15 min]", required: false
}
section("Alert") {
input "push", "bool", title: "Alert via push?", required: false
input "smsNum", "phone", title: "Phone for SMS Alert", required: false
}
}
def installed()
{
initialize()
}
def updated()
{
unsubscribe()
initialize()
}
def initialize()
{
subscribe(theGarage, "leftDoor", evtHandler)
subscribe(theGarage, "rightDoor", evtHandler)
log.debug "Left door is ${theGarage.currentLeftDoor}"
log.debug "Right door is ${theGarage.currentRightDoor}"
log.debug "Timeout set to ${timeout?:15} min"
}
def evtHandler(evt) {
if (evt.name == "leftDoor")
{
unschedule(checkLeft)
if (evt.value == "open")
{
// Schedule a check in 'timeout' min
log.debug "Left door opened - scheduling the check"
runIn((timeout?:15)*60, checkLeft)
}
}
else if (evt.name == "rightDoor")
{
unschedule(checkRight)
if (evt.value == "open")
{
// Schedule a check in 'timeout' min
log.debug "Right door opened - scheduling the check"
runIn((timeout?:15)*60, checkRight)
}
}
else
{
// No idea how it would get here
log.warn "This is weird - don't know how I got here"
}
}
def checkLeft()
{
log.debug "Checking if left door is still open"
if (theGarage.currentLeftDoor == "open")
{
log.debug "Left garage door still open - sending alert"
sendAlert("Left Garage has been open for ${timeout?:15} min")
}
}
def checkRight()
{
log.debug "Checking if right door is still open"
if (theGarage.currentRightDoor == "open")
{
log.debug "Right garage door still open - sending alert"
sendAlert("Right Garage has been open for ${timeout?:15} min")
}
}
def sendAlert( theMsg )
{
if(push)
{
log.debug "Sending push notification"
sendPush(theMsg)
}
if(smsNum)
{
log.debug "Sending SMS notification"
sendSms(smsNum, theMsg)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment