[RELEASE] Auto Lock Door

Re: no contact sensor

If all you want is an auto timed door lock there's not much reason to install this app or even get an HE.
Most smart locks have that as a built in feature that the owner can activate without any additional equipment.
Not to say this app shouldn't be capable of functioning without a contact sensor, just that it's use without one is a very unlikely scenario.
(Maybe just a disclaimer in the instructions.)

Difference is, the lock on the door needs to know if the door is open or closed. AFAIK my Schlage BE469 doesn't have a sensor that tells it if the door is closed or not.

1 Like

Exactly, neither does my Yale, which is why I've never activated it.
And why I don't think anyone would use this app without a contact sensor.

Yup - the Schlage auto-lock is a "dumb" auto-lock, simply locks the door 30s after it's been unlocked, regardless of the door status.

I don't want the door to lock quickly when I'm taking the dogs out front for a quick pee break, getting our mail, talking w/a neighbor out front for a bit. And if the door is open when it tries to lock you end up w/an extended dead bolt that you have to retract before you can close the door. Just not useful for me and likely not for many people.

You are correct so I think all that @chris.sader really needs to do is just remove the "(optional)" from lines 62 and 63 or replace it with (Required) and call it good.

62 section("Lock it only when this door is closed. (optional)") {
63 input "openSensor", "capability.contactSensor", title: "Choose Door Contact Sensor (optional)"

1 Like

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.
    }
}
2 Likes

Darn, I should have thought of that. :wink:

Hopefully Chris likes the idea of requiring a contact sensor and adds that to his official release. Since there is the virtual contact sensor work-around not one would be blocked from using the app. :smiley:

Version number should be updated to avoid confusion.

Both the version number in the comment AND the state.version value. :+1:

1 Like

lol yes I caught that after I saved it the first time and then saw your edit after I saved it the second time. :slight_smile:

@672southmain Should be no confusion now. See the updated screenshot.

1 Like

Is anyone else seeing Door null in their logs?
I'm trying to figure out why I'm seeing that, and if it's causing any negative effects or not for me.

Any idea?
image

It looks like that would be your Door Sensor latestValue is null.

log.debug "Door ${openSensor.latestValue}"
log.debug "Lock ${evt.name} is ${evt.value}."

What's weird though is I have a lot of consecutive events there that show "Door Closed" then "Door null".

I'm wondering, should that log item be openSensor.latestValue("contact") instead?

Edit: Confirmed, updating that debug log to the above fixes the null problem for me.

1 Like

Oh yes good catch, I updated my temp fix above but @chris.sader will need to fix his code when he is free.

1 Like

Changes merged. Tested and it works on my end. Update the app and let me know if you're still getting any errors.

2 Likes

Great. Hope your move is going well, nice of you to check in when you're so busy... [eek!]

Thanks...moving back in to our house that we were renting and tenants left us a nice disaster. Fun times. This was a nice little reprieve from all of that. Now to figure out which switches to put in the house - I want to go Lutron throughout, but thinking about the cost makes me want to cry.

1 Like

Renters can be a real PITA. My mom rented a house for a few years, and when they moved back in the place was just a mess. Their cleaning deposit was way short of the mess they made. Worst was the ceiling over a chair in the living room. Not only did they smoke (said didn't) but they smoked cigars. The ceiling was just black from the cigar smoke.

I feel you comment about Lutron, really well done/designed/reliable, but man they are not cheap.

Would it be possible to have the timer enter a time frame like the example below?

image
Maybe just have minutes and seconds.

Let me look into it.

Just another suggestion, you removed the "Optional" comment but if you still do not define a sensor, it will still throw the error on Line 118 and so on. I suggest adding the required: true, and multiple: false comments below to make each one of these selections mandatory before saving since they are all actually required for the app to work.

{
    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 
    }
}
3 Likes