5 * Author: Chris Sader (@csader)
6 * Collaborators: @chrisb
8 * URL: http://www.github.com/smartthings-users/smartapp.auto-lock-door
10 * Copyright (C) 2013 Chris Sader.
11 * Permission is hereby granted, free of charge, to any person obtaining a copy of this
12 * software and associated documentation files (the "Software"), to deal in the Software
13 * without restriction, including without limitation the rights to use, copy, modify,
14 * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
15 * permit persons to whom the Software is furnished to do so, subject to the following
16 * conditions: The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
20 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
21 * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
23 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
24 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 section("When a door unlocks...") {
30 input "lock1", "capability.lock"
32 section("Lock it how many minutes later?") {
33 input "minutesLater", "number", title: "When?"
35 section("Lock it only when this door is closed") {
36 input "openSensor", "capability.contactSensor", title: "Where?"
42 log.debug "Auto Lock Door installed. (URL: http://www.github.com/smartthings-users/smartapp.auto-lock-door)"
50 log.debug "Auto Lock Door updated."
56 log.debug "Settings: ${settings}"
57 subscribe(lock1, "lock", doorHandler)
58 subscribe(openSensor, "contact.closed", doorClosed)
59 subscribe(openSensor, "contact.open", doorOpen)
64 log.debug "Locking Door if Closed"
65 if((openSensor.latestValue("contact") == "closed")){
66 log.debug "Door Closed"
69 if ((openSensor.latestValue("contact") == "open")) {
70 def delay = minutesLater * 60
71 log.debug "Door open will try again in $minutesLater minutes"
72 runIn( delay, lockDoor )
78 log.debug "Door open reset previous lock task..."
79 unschedule( lockDoor )
80 def delay = minutesLater * 60
81 runIn( delay, lockDoor )
85 log.debug "Door Closed"
90 log.debug "Door ${openSensor.latestValue}"
91 log.debug "Lock ${evt.name} is ${evt.value}."
93 if (evt.value == "locked") { // If the human locks the door then...
94 log.debug "Cancelling previous lock task..."
95 unschedule( lockDoor ) // ...we don't need to lock it later.
97 else { // If the door is unlocked then...
98 def delay = minutesLater * 60 // runIn uses seconds
99 log.debug "Re-arming lock in ${minutesLater} minutes (${delay}s)."
100 runIn( delay, lockDoor ) // ...schedule to lock in x minutes.