Last active
August 29, 2015 13:56
-
-
Save markjaquith/9295648 to your computer and use it in GitHub Desktop.
Alerts me when someone opens my office door when I'm not at home
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* My office is off-limits when I am gone | |
* | |
* Author: Mark Jaquith | |
* Date: 2014-03-01 | |
*/ | |
preferences { | |
section("Monitor this door") { | |
input "door", "capability.contactSensor" | |
} | |
section("When this person is away") { | |
input "person", "capability.presenceSensor" | |
} | |
} | |
def installed() { | |
log.trace "installed()" | |
subscribe() | |
} | |
def updated() { | |
log.trace "updated()" | |
unsubscribe() | |
subscribe() | |
} | |
def subscribe() { | |
subscribe(door, "contact.open", doorOpen) | |
subscribe(door, "contact.closed", doorClosed) | |
} | |
def doorOpen(evt) { | |
log.trace "doorOpen($evt.name: $evt.value)" | |
def presenceValue = person.find{it.currentPresence == "present"} | |
if ( ! presenceValue ) { | |
sendOpenedMessage() | |
} | |
} | |
def doorClosed(evt) { | |
log.trace "doorClosed($evt.name: $evt.value)" | |
def presenceValue = person.find{it.currentPresence == "present"} | |
if ( ! presenceValue ) { | |
sendClosedMessage() | |
} | |
} | |
void sendOpenedMessage() { | |
def msg = "${door.displayName} was opened while ${person.displayName} was away" | |
log.info msg | |
sendPush msg | |
} | |
void sendClosedMessage() { | |
def msg = "${door.displayName} was closed while ${person.displayName} was away" | |
log.info msg | |
sendPush msg | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment