[RELEASE] Auto Lock Door

That's because I assumed I had code for it in there because it showed up when I tested it... :stuck_out_tongue:

1 Like

Updated description to clarify (hopefully).

Would be cool if you had an option for Seconds as well as Minutes after door closes. I like it to lock 5 seconds after closed so I can hear it lock before I disappear. That way I know it locked and didnt jam up.
Looks like I could just modify the DH by removing the '* 60' from 'minutesLater * 60' in several places

1 Like

First off, thanks for taking the time to put this together and offering it up to everyone.

With that said, I feel there are a couple of issues with this however.

  1. This appears to only lock the lock if the Door Sensor goes to an Open and then Closed state. If a kid for example just walks up and unlocks the door without opening and closing the door, it doesn't trigger the lock to lock again.
  2. This is a bigger security concern along the lines that @kampto stated. There is nothing in this app that verifies if the lock is ACTUALLY getting locked and can result in a false sense of security. I originally setup my automation without this consideration at first too until I thought about it more. If you do not fully close your door and it is left open just slightly, the lock will try to lock but fails. It will either report jammbed or unknown. If you are just relying on this app, you will assume the door is locked when it really is not. I would suggest that a notification method is added for at least this final check.

Or people can just understand the limitations of the app and use it as is. :slight_smile:

This is resolved in the newest platform update (2.2.3.148)

2 Likes

It does lock the door if only the lock is unlocked, just confirmed by testing it. It would be more helpful if you did a quick check to confirm an issue exists before posting about it. :slight_smile:

I have notifications set up in the Notifications app on all my doors set up to notify me if they are open either 1) Too long (something that varies by door) or 2) When they shouldn't be. That is my preferred method to ensure things are closed/locked when they should be.

IMHO, anyone who relies on consumer level smart home stuff like this as if it's actual "Home Security" is making a big mistake in general...this stuff generically is not 100% reliable and is no substitute for normal pesonal diligence w/family and especially kids.

I look at this as a helpful tool that makes me less likely to do something dumb like leave my door unlocked all night, but I always also check directly w/my own eyes. Trust, but verify. :smiley:

I just re-read my reply and realized it may sound a little brusque - just wanted to note that was not my intent, just typing fast. It's good you raised the points you did, as folks need to realize that Hubitat lock automations, no matter how they are designed and what app/tool they run on, are no substitute for normal due-diligence.

That said, I feel this one is wonderfully simple and easy to set up (reduces operator error in config) and has run 100% reliably for me since I got my C7. If you're going to use an auto-lock app, this is a very good choice. It is also probably much better than a bunch of users creating flawed rules in RM that are (unknown to them) designed to fail. Count me in that group... :wink:

3 Likes

Ah, thanks for this. Updating did fix the "sticky" issue with the modes I was having with this app.
I haven't had a chance to actually test if the modes work, but that is for another time.

Thank you!

Again, love this app!

Actually I did check it and that is why I mentioned it. I did multiple tests yesterday and for me at least, if I unlocked the door but did not open the door so the sensor goes open and then closed, the lock did not auto lock. They only way I could get it to lock after being unlocked was to actually open and close the door. I just installed this app again today to test it again and now it is working so something is buggy. I installed it both times using HPM.

Another bug that I didn't report yesterday but will today is even though is says the Door Sensor is optional, if I do not pick a sensor then this app doesn't work at all. I get this error. This happened yesterday as well as today. Again, this is just for information purposes as I do not intend to use the app but just trying to help out. Both issues I have seen are related to the Door Sensor so their may be some bugs that need to be worked out in the code.

My Rule I posted works 100% of the time so I have no issues with my lock or door sensor.

Again, I am not saying people shouldn't use this and did thank the creator for putting in the time on this. Just pointing a few things out is all. :slight_smile:

2 Likes

I'm in the middle of a move, so can't test this with my lock (it's in a box somewhere). Let me know if anyone else runs into issues running this app without a door sensor.

Edit: I'll also note that my app code is on github, so anyone who wants to propose any changes to the app code is welcome to submit a pull request. :wink:

1 Like

Just so you have the logs,
You can see I installed it and did not pick a door sensor so when I unlocked the door the two times, it threw the error.

Then when I updated the app and picked a sensor, then when I unlocked it, it worked correctly.
Auto Lock Issue2

The error will come back if I remove the door sensor again.

Confirmed...I get the same debug log error when I don't select a contact sensor, and the door doesn't lock in that case. Good catch.

Code section:
115 def doorHandler(evt)
116 {
117 log.debug "Door ${openSensor.latestValue}"
118 log.debug "Lock ${evt.name} is ${evt.value}."

I'm not a coder, sadly, so other than commenting that line out (and testing to see what that breaks) I'm not much use in actually proprosing a change. :slight_smile:

@chris.sader - You may want to consider whether you want to make a door sensor required to avoid the case (as much as possible) where the door isn't closed when the lock action runs.

That keeps the app simple (single use-case of Lock+sensor) and easy to troubleshoot. I'd vote for that constraint. I would expect that the vast majority of users who have a smart lock on a door also have a contact sensor on it as well. If they don't they should get one, dammit! :wink: (And if they are really cheap and/or don't care, or for some odd reason can't put a sensor on the door, they can create a virtual contact sensor device and set it to "Closed" permanently and just use that.)

1 Like

It isn't just trying to log the step in 117. If you comment that step out, then the next error is step 92.

89 def lockDoor()
90 {
91 log.debug "Locking Door if Closed"
92 if((openSensor.latestValue("contact") == "closed")){
93 log.debug "Door Closed"
94 lock1.lock()
95 } else {
96 if ((openSensor.latestValue("contact") == "open")) {
97 def delay = minutesLater * 60
98 log.debug "Door open will try again in $minutesLater minutes"
99 runIn( delay, lockDoor )
100 }
101 }
102 }

Yup, as I mentioned I don't expect to have the skills to debug/fix (at least not efficiently) so I didn't continue the investigation. :slight_smile: Was just showing the line of code where the problem starts.

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: