-def doorHandler(evt){
- log.debug evt.value
- log.debug contact.latestValue("contact")
- if ((contact.latestValue("contact") == "open") && (evt.value == "locked")) { // If the door is open and a person locks the door then...
- //def delay = (secondsLater) // runIn uses seconds
- log.debug "1"
- runIn( secondsLater, unlockDoor ) // ...schedule (in minutes) to unlock... We don't want the door to be closed while the lock is engaged.
- }
- else if ((contact.latestValue("contact") == "open") && (evt.value == "unlocked")) { // If the door is open and a person unlocks it then...
- log.debug "2"
- unschedule( unlockDoor ) // ...we don't need to unlock it later.
- }
- else if ((contact.latestValue("contact") == "closed") && (evt.value == "locked")) { // If the door is closed and a person manually locks it then...
- log.debug "3"
- unschedule( lockDoor ) // ...we don't need to lock it later.
- }
- else if ((contact.latestValue("contact") == "closed") && (evt.value == "unlocked")) { // If the door is closed and a person unlocks it then...
- log.debug "4"
- //def delay = (minutesLater * 60) // runIn uses seconds
- runIn( (minutesLater * 60), lockDoor ) // ...schedule (in minutes) to lock.
- }
- else if ((lock1.latestValue("lock") == "unlocked") && (evt.value == "open")) { // If a person opens an unlocked door...
- log.debug "5"
- unschedule( lockDoor ) // ...we don't need to lock it later.
- }
- else if ((lock1.latestValue("lock") == "unlocked") && (evt.value == "closed")) { // If a person closes an unlocked door...
- //def delay = (minutesLater * 60) // runIn uses seconds
- log.debug "6"
- runIn( (minutesLater * 60), lockDoor ) // ...schedule (in minutes) to lock.
- }
- else { //Opening or Closing door when locked (in case you have a handle lock)
- log.debug "Unlocking the door."
- lock1.unlock()
- if(location.contactBookEnabled) {
- if ( recipients ) {
- log.debug ( "Sending Push Notification..." )
- sendNotificationToContacts( "${lock1} unlocked after ${contact} was opened or closed when ${lock1} was locked!", recipients)
- }
- }
- if ( phoneNumber ) {
- log.debug("Sending text message...")
- sendSms( phoneNumber, "${lock1} unlocked after ${contact} was opened or closed when ${lock1} was locked!")
- }
- }
+def appTouch(evt) {
+ log.debug "changeMode, location.mode = $location.mode, newMode = $newMode, location.modes = $location.modes"
+ if (location.mode != newMode) {
+ setLocationMode(newMode)
+ log.debug "Changed the mode to '${newMode}'"
+ } else {
+ log.debug "New mode is the same as the old mode, leaving it be"
+ }
+ log.debug "appTouch: $evt"
+ lock1.lock()
+ switcheson.on()
+ def delay = (waitfor != null && waitfor != "") ? waitfor * 1000 : 120000
+ switchesoff.off(delay: delay)