Skip to content

Commit

Permalink
HH presense check on lock level
Browse files Browse the repository at this point in the history
  • Loading branch information
ethayer committed Apr 11, 2017
1 parent b65cacd commit ea8e63b
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions smartapps/ethayer/lock.src/lock.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def initialize() {
// reset listeners
unsubscribe()
unschedule()

subscribe(lock, 'codeReport', updateCode, [filterEvents:false])
subscribe(lock, "reportAllCodes", pollCodeReport, [filterEvents:false])
subscribe(lock, "lock", codeUsed)
Expand Down Expand Up @@ -189,6 +190,9 @@ def helloHomePage() {
if (state.supportsKeypadData) {
input(name: 'keypadLockRoutine', title: 'On keypad Lock', type: 'enum', options: actions, required: false, multiple: true)
}

input "userNoRunPresence", "capability.presenceSensor", title: "DO NOT run Actions if any of these are present:", multiple: true, required: false
input "userDoRunPresence", "capability.presenceSensor", title: "ONLY run Actions if any of these are present:", multiple: true, required: false
}
}
}
Expand Down Expand Up @@ -391,7 +395,7 @@ def codeUsed(evt) {
// unlocked manually

if (manualUnlockRoutine) {
location.helloHome.execute(manualUnlockRoutine)
executeHelloPresenceCheck(manualUnlockRoutine)
}
message = "${lock.label} was unlocked manually"
if (notifyMaunualUnlock) {
Expand All @@ -413,7 +417,7 @@ def codeUsed(evt) {
if (data && data.usedCode == 0) {
message = "${lock.label} was locked by keypad"
if (keypadLockRoutine) {
location.helloHome.execute(keypadLockRoutine)
executeHelloPresenceCheck(keypadLockRoutine)
}
if (notifyKeypadLock) {
send(message)
Expand All @@ -426,7 +430,7 @@ def codeUsed(evt) {
// locked manually
message = "${lock.label} was locked manually"
if (manualLockRoutine) {
location.helloHome.execute(manualLockRoutine)
executeHelloPresenceCheck(manualLockRoutine)
}
if (notifyMaunualLock) {
send(message)
Expand Down Expand Up @@ -690,3 +694,21 @@ def debugger(message) {
log.debug(message)
}
}

def executeHelloPresenceCheck(routines) {
if (userNoRunPresence && userDoRunPresence == null) {
if (!anyoneHome(userNoRunPresence)) {
location.helloHome.execute(routines)
}
} else if (userDoRunPresence && userNoRunPresence == null) {
if (anyoneHome(userDoRunPresence)) {
location.helloHome.execute(routines)
}
} else if (userDoRunPresence && userNoRunPresence) {
if (anyoneHome(userDoRunPresence) && !anyoneHome(userNoRunPresence)) {
location.helloHome.execute(routines)
}
} else {
location.helloHome.execute(routines)
}
}

0 comments on commit ea8e63b

Please sign in to comment.