2 name: "Enhanced Auto Lock Door",
3 namespace: "Lock Auto Super Enhanced",
5 description: "Automatically locks a specific door after X minutes when closed and unlocks it when open after X seconds.",
6 category: "Safety & Security",
7 iconUrl: "http://www.gharexpert.com/mid/4142010105208.jpg",
8 iconX2Url: "http://www.gharexpert.com/mid/4142010105208.jpg"
12 section("Select the door lock:") {
13 input "lock1", "capability.lock", required: true
15 section("Select the door contact sensor:") {
16 input "contact", "capability.contactSensor", required: true
18 section("Automatically lock the door when closed...") {
19 input "minutesLater", "number", title: "Delay (in minutes):", required: true
21 section("Automatically unlock the door when open...") {
22 input "secondsLater", "number", title: "Delay (in seconds):", required: true
24 section( "Notifications" ) {
25 input("recipients", "contact", title: "Send notifications to", required: false) {
26 input "phoneNumber", "phone", title: "Warn with text message (optional)", description: "Phone Number", required: false
42 log.debug "Settings: ${settings}"
43 subscribe(lock1, "lock", doorHandler, [filterEvents: false])
44 subscribe(lock1, "unlock", doorHandler, [filterEvents: false])
45 subscribe(contact, "contact.open", doorHandler)
46 subscribe(contact, "contact.closed", doorHandler)
50 log.debug "Locking the door."
52 if(location.contactBookEnabled) {
54 log.debug ( "Sending Push Notification..." )
55 sendNotificationToContacts( "${lock1} locked after ${contact} was closed for ${minutesLater} minutes!", recipients)
59 log.debug("Sending text message...")
60 sendSms( phoneNumber, "${lock1} locked after ${contact} was closed for ${minutesLater} minutes!")
65 log.debug "Unlocking the door."
67 if(location.contactBookEnabled) {
69 log.debug ( "Sending Push Notification..." )
70 sendNotificationToContacts( "${lock1} unlocked after ${contact} was opened for ${secondsLater} seconds!", recipients)
74 log.debug("Sending text message...")
75 sendSms( phoneNumber, "${lock1} unlocked after ${contact} was opened for ${secondsLater} seconds!")
80 if ((contact.latestValue("contact") == "open") && (evt.value == "locked")) { // If the door is open and a person locks the door then...
81 //def delay = (secondsLater) // runIn uses seconds
82 runIn( secondsLater, unlockDoor ) // ...schedule (in minutes) to unlock... We don't want the door to be closed while the lock is engaged.
84 else if ((contact.latestValue("contact") == "open") && (evt.value == "unlocked")) { // If the door is open and a person unlocks it then...
85 unschedule( unlockDoor ) // ...we don't need to unlock it later.
87 else if ((contact.latestValue("contact") == "closed") && (evt.value == "locked")) { // If the door is closed and a person manually locks it then...
88 unschedule( lockDoor ) // ...we don't need to lock it later.
90 else if ((contact.latestValue("contact") == "closed") && (evt.value == "unlocked")) { // If the door is closed and a person unlocks it then...
91 //def delay = (minutesLater * 60) // runIn uses seconds
92 runIn( (minutesLater * 60), lockDoor ) // ...schedule (in minutes) to lock.
94 else if ((lock1.latestValue("lock") == "unlocked") && (evt.value == "open")) { // If a person opens an unlocked door...
95 unschedule( lockDoor ) // ...we don't need to lock it later.
97 else if ((lock1.latestValue("lock") == "unlocked") && (evt.value == "closed")) { // If a person closes an unlocked door...
98 //def delay = (minutesLater * 60) // runIn uses seconds
99 runIn( (minutesLater * 60), lockDoor ) // ...schedule (in minutes) to lock.
101 else { //Opening or Closing door when locked (in case you have a handle lock)
102 log.debug "Unlocking the door."
104 if(location.contactBookEnabled) {
106 log.debug ( "Sending Push Notification..." )
107 sendNotificationToContacts( "${lock1} unlocked after ${contact} was opened or closed when ${lock1} was locked!", recipients)
111 log.debug("Sending text message...")
112 sendSms( phoneNumber, "${lock1} unlocked after ${contact} was opened or closed when ${lock1} was locked!")