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