Since @chris.sader is in the process of moving, I will post this here if anyone wants to use it until he makes whatever changes he wants to to his app. Updated the app code to be based on seconds instead of minutes and changed the optional to Required. Just replace the apps code with this modified version.
@chris.sader I will delete this if you don't approve of it.
/**
* **************** Auto Lock Door ****************
*
* Design Usage:
* Automatically locks a specific door after X seconds when closed and unlocks it when open after X seconds.
*
* Copyright 2019-2020 Chris Sader (@chris.sader)
*
* This App is free. If you like and use this app, please be sure to mention it on the Hubitat forums! Thanks.
*
* Donations to support development efforts are accepted via:
*
* Paypal at: https://paypal.me/csader
*
*-------------------------------------------------------------------------------------------------------------------
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
* for the specific language governing permissions and limitations under the License.
*
* ------------------------------------------------------------------------------------------------------------------------------
*
* If modifying this project, please keep the above header intact and add your comments/credits below - Thank you! - @chris.sader
*
* ------------------------------------------------------------------------------------------------------------------------------
*
* Changes:
*
* 1.0.1 Temporary fix by Chipworkz
*
*/
def setVersion(){
state.name = "Auto Lock Door"
state.version = "1.0.1"
}
definition(
name: "Auto Lock Door",
namespace: "chris.sader",
author: "Chris Sader",
description: "Automatically locks a specific door after X seconds when closed and unlocks it when open after X seconds.",
tag: "Locks",
iconUrl: "http://www.gharexpert.com/mid/4142010105208.jpg",
iconX2Url: "http://www.gharexpert.com/mid/4142010105208.jpg",
iconX3Url: "http://www.gharexpert.com/mid/4142010105208.jpg",
importUrl: "https://github.com/csader/AutoLockDoor/blob/master/AutoLockDoor.groovy"
)
preferences
page(name: "mainPage", title: "<b>Temporary fix by Chipworkz. Not Official</b>", install: true, uninstall: true)
{
section("When a door unlocks...") {
input "lock1", "capability.lock",
required: true,
multiple: false
}
section("Lock it how many seconds later?") {
input "secondsLater", "number", title: "Enter # Seconds",
required: true,
multiple: false
}
section("Lock it only when this door is closed. (Required)") {
input "openSensor", "capability.contactSensor", title: "Choose Door Contact Sensor (Required)",
required: true,
multiple: false
}
}
def installed()
{
log.debug "Auto Lock Door installed."
initialize()
}
def updated()
{
unsubscribe()
unschedule()
log.debug "Auto Lock Door updated."
initialize()
}
def initialize()
{
log.debug "Settings: ${settings}"
subscribe(lock1, "lock", doorHandler)
subscribe(openSensor, "contact.closed", doorClosed)
subscribe(openSensor, "contact.open", doorOpen)
}
def lockDoor()
{
log.debug "Locking Door if Closed"
if((openSensor.latestValue("contact") == "closed")){
log.debug "Door Closed"
lock1.lock()
} else {
if ((openSensor.latestValue("contact") == "open")) {
def delay = secondsLater
log.debug "Door open will try again in $secondsLater seconds"
runIn( delay, lockDoor )
}
}
}
def doorOpen(evt) {
log.debug "Door open reset previous lock task..."
unschedule( lockDoor )
def delay = secondsLater
runIn( delay, lockDoor )
}
def doorClosed(evt) {
log.debug "Door Closed"
}
def doorHandler(evt)
{
log.debug "Door ${openSensor.latestValue("contact")}"
log.debug "Lock ${evt.name} is ${evt.value}."
if (evt.value == "locked") { // If the human locks the door then...
log.debug "Cancelling previous lock task..."
unschedule( lockDoor ) // ...we don't need to lock it later.
}
else { // If the door is unlocked then...
def delay = secondsLater // runIn uses seconds
log.debug "Re-arming lock in ${secondsLater} seconds (${delay}s)."
runIn( delay, lockDoor ) // ...schedule to lock in x seconds.
}
}