3 name: "Enhanced Auto Lock Door",
4 namespace: "Lock Auto Super Enhanced",
6 description: "Automatically locks a specific door after X minutes when closed and unlocks it when open after X seconds.",
7 category: "Safety & Security",
8 iconUrl: "http://www.gharexpert.com/mid/4142010105208.jpg",
9 iconX2Url: "http://www.gharexpert.com/mid/4142010105208.jpg"
13 section("Select the door lock:") {
14 input "lock1", "capability.lock", required: true
16 section("Select the door contact sensor:") {
17 input "contact", "capability.contactSensor", required: true
19 section("Automatically lock the door when closed...") {
20 input "minutesLater", "number", title: "Delay (in minutes):", required: true
22 section("Automatically unlock the door when open...") {
23 input "secondsLater", "number", title: "Delay (in seconds):", required: true
25 section( "Notifications" ) {
26 input("recipients", "contact", title: "Send notifications to", required: false) {
27 input "phoneNumber", "phone", title: "Warn with text message (optional)", description: "Phone Number", required: false
43 log.debug "Settings: ${settings}"
44 subscribe(lock1, "lock", doorHandler, [filterEvents: false])
45 subscribe(lock1, "unlock", doorHandler, [filterEvents: false])
46 subscribe(contact, "contact.open", doorHandler)
47 subscribe(contact, "contact.closed", doorHandler)
51 log.debug "Locking the door."
53 if(location.contactBookEnabled) {
55 log.debug ( "Sending Push Notification..." )
56 sendNotificationToContacts( "${lock1} locked after ${contact} was closed for ${minutesLater} minutes!", recipients)
60 log.debug("Sending text message...")
61 sendSms( phoneNumber, "${lock1} locked after ${contact} was closed for ${minutesLater} minutes!")
66 log.debug "Unlocking the door."
68 if(location.contactBookEnabled) {
70 log.debug ( "Sending Push Notification..." )
71 sendNotificationToContacts( "${lock1} unlocked after ${contact} was opened for ${secondsLater} seconds!", recipients)
75 log.debug("Sending text message...")
76 sendSms( phoneNumber, "${lock1} unlocked after ${contact} was opened for ${secondsLater} seconds!")
81 if ((contact.latestValue("contact") == "open") && (evt.value == "locked")) { // If the door is open and a person locks the door then...
82 //def delay = (secondsLater) // runIn uses seconds
83 runIn( secondsLater, unlockDoor ) // ...schedule (in minutes) to unlock... We don't want the door to be closed while the lock is engaged.
85 else if ((contact.latestValue("contact") == "open") && (evt.value == "unlocked")) { // If the door is open and a person unlocks it then...
86 unschedule( unlockDoor ) // ...we don't need to unlock it later.
88 else if ((contact.latestValue("contact") == "closed") && (evt.value == "locked")) { // If the door is closed and a person manually locks it then...
89 unschedule( lockDoor ) // ...we don't need to lock it later.
91 else if ((contact.latestValue("contact") == "closed") && (evt.value == "unlocked")) { // If the door is closed and a person unlocks it then...
92 //def delay = (minutesLater * 60) // runIn uses seconds
93 runIn( (minutesLater * 60), lockDoor ) // ...schedule (in minutes) to lock.
95 else if ((lock1.latestValue("lock") == "unlocked") && (evt.value == "open")) { // If a person opens an unlocked door...
96 unschedule( lockDoor ) // ...we don't need to lock it later.
98 else if ((lock1.latestValue("lock") == "unlocked") && (evt.value == "closed")) { // If a person closes an unlocked door...
99 //def delay = (minutesLater * 60) // runIn uses seconds
100 runIn( (minutesLater * 60), lockDoor ) // ...schedule (in minutes) to lock.
102 else { //Opening or Closing door when locked (in case you have a handle lock)
103 log.debug "Unlocking the door."
105 if(location.contactBookEnabled) {
107 log.debug ( "Sending Push Notification..." )
108 sendNotificationToContacts( "${lock1} unlocked after ${contact} was opened or closed when ${lock1} was locked!", recipients)
112 log.debug("Sending text message...")
113 sendSms( phoneNumber, "${lock1} unlocked after ${contact} was opened or closed when ${lock1} was locked!")