Auto-Lock Doors

The runIn runs for any event that is not equal to “lock”. I felt it was safer that way, I do not know what other states there are (I don’t want to assume only two, I do not have one to test).

The problem is that the doorHandler is being called unnecessarily, perhaps do the filterEvents. Can you pastebin your log so I can get some idea of what’s going on?

Ah… I just looked at the code on github. It got changed to an If-Then-Else statement.

If the door is locked do A, B, C otherwise do X, Y, Z.

I think what’s happening is the door is reporting back something other than lock or unlock during the normal poll events. The original two If-Then statements only did things if it was locked or unlocked. But the If-Then-Else statement does the X,Y,Z on any response from the lock if it’s something other than ‘lock.’

The code should ideally be changed back to two If-Then statements. I think the filterEvents: False should also be removed, but the real problem is the If-Then-Else.

It’s subscribing to events, it’s not being polled. The device is REPORTING more than lock/unlock events. Yes the if-then is the reason for the spam, but that’s because the function is being called more than it should. If-Then-Else is treating the symptom, calling doorHandler properly is the cure.

Can you pastebin a log or fedex me a lock so I can diagnose?

@jnovack http://pastebin.com/wWgNHnDN

Interestingly, it’s not actually locking my lock. It just says it is. And loops the same commands every 30 secs or so.

  1. change evt.value == “lock” to “locked”. And “unlock” to “unlocked”.

  2. the lock() function is not accurate. I do know know what the correct statement to actually lock the lock.

Seems to be working for me, now that I changed “lock” to “locked”

@jnovack, according to the Lock It When I Leave SmartApp, lock1.lock() is the correct statement, which is what this SmartApp uses.

Also, you say to change “unlock” to “unlocked” but I don’t see an “unlock” statement anywhere. Since it appears to be working, I assume I don’t need to add anything about “unlocked”.

Hey @jforshee, how about not posting a Shared SmartApp that you didn’t write under your own authorship?

How about giving credit where credit is due? To myself, @chrisb and @jnovack.

Your “Door Auto-Lock” shared app is a blatant ripoff of the code that I, with the help of chrisb, wrote, and clearly put Authorship and collaboration credits on.

Thanks to @chrisb , @jnovack and @csader for their work on this SmartApp, It is very useful.

I have ran into a problem with this SmartApp though. One time when I was closing the door the lock engaged from this SmartApp and the Deadbolt slammed agents the molding surrounding the door. Lucky the lock was not damaged just a small dent in the molding. So i added a check to see if the door is closed before the lock in engaged.

Below is my code that i modified from your SmartApp. Sorry if its a little sloppy.

preferences
{
    section("When a door unlocks...") {
        input "lock1", "capability.lock"
    }
    section("Lock it how many minutes later?") {
        input "minutesLater", "number", title: "When?"
    }
    section("Lock it only when this door is closed") {
        input "openSensor", "capability.contactSensor", title: "Where?"
    }
}

def installed()
{
    log.debug "Auto Lock Door installed. (URL: http://www.github.com/smartthings-users/smartapp.auto-lock-door)"
    initialize()
}

def updated()
{
    unsubscribe()
    unschedule()
    log.debug "Auto Lock Door updated."
    initialize()
}

def initialize()
{
    log.debug "Settings: ${settings}"
    subscribe(lock1, "lock", doorHandler, [filterEvents: false])
    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 = minutesLater * 60
        log.debug "Door open will try again in $minutesLater minutes"
        runIn( delay, lockDoor )
        }
    }
}

def doorOpen(evt) {
log.debug "Door open reset previous lock task..."
unschedule( lockDoor )
def delay = minutesLater * 60
runIn( delay, lockDoor )
}

def doorClosed(evt) {
log.debug "Door Closed"
}

def doorHandler(evt)
{
	log.debug "Door ${openSensor.latestValue}"
    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 = minutesLater * 60          // runIn uses seconds
        log.debug "Re-arming lock in ${minutesLater} minutes (${delay}s)."
        runIn( delay, lockDoor )                // ...schedule to lock in x minutes.
    }
}

Submit a pull request.

@jnovack

Are you asking that I pull my post?

Or are you talking about a “pull request” in the code?

@bigpunk6 he means submit a pull request on the github page: https://github.com/smartthings-users/smartapp.auto-lock-door

@csader Sorry, I was not familiar with GetHub.

Pull request has been submitted.

I’m curious, fellas… I read earlier in this thread, and others, that there is a problem, (of some sort,) where these Kwiksets deadbolt locks do not report the status when manually changed. If I take the cover off mine, and turn the deadbolt, the radio communication LED starts to glow for about 5 seconds–the same as when I programmed it. Is the SmartThings hub simply not programmed to or capable of receiving these push alerts?

I checked my hub events list, and the pushed event doesn’t appear. Is this simply a coincidence that the light comes on?

@stevenascott There is a hub firmware update that fixes this problem.

email support@smartthings.com

Tell them you would like the new firmware and they will push it to you.

Whoa, thanks Mike!

@bigpunk6 @stevenascott I have this latest firmware and just to clarify, it’s better but not perfect (for me at least). I’ve noticed that on occasion it does not update the status very quickly, and sometimes it doesn’t update at all if I unlock the door from the inside (with the lever). Not sure if this is a problem with ST or Kwikset, but something to keep in mind.

@csader Did you remove and readd the lock after the firmware update (with the hub within 15ft)? After I did that ST would update the status of the lock before the red light on the lock that indicates zwave communication even goes off.

So apparently I already received the latest firmware on September 20th. I didn’t re-add my locks or do anything special. Everything was working like normal (never reporting lock status, but still unlocking/locking/etc,) until I factory reset my Android phone last Friday. Since then, my locks barely work, and get out of sync every time they are triggered. I did not move my locks or hub, so I doubt it’s a range issue. What I’m noticing is that if I manually turn my deadbolt to what the app thinks, (locked,) then try to unlock, it actually unlocks. The app never updates though, just says UNLOCKING, despite the Z-Wave light. For whatever reason, the resulting change is not being communicated back to my hub from either of my locks. My deadbolt lock is about 100ft away, where it’s been since I deployed it months ago… my bedroom lock is 35 ft away, and I’m having the same issues. Kwikset 910 and 912 model locks.

I’m working with support on this, but I wonder if anyone else has had an issue with the new firmware, or maybe unrelated, but factory resetting your phone.

Is anyone else noticing that with the newer, ‘pretty’ Android app, that lock notification is working a bit better? Not perfect, but probably 10 times better than the older app? I don’t know if the hub was also upgraded recently, but I know I didn’t change anything else on my end.

I’m going to win for “least useful post this year” with this one - I hope you’ll forgive me. I just bought/installed my very first Smart Thing (a lock - and a hub). I’ve got the app working just fine and I can lock/unlock the door with no problem. Yippee!

This Auto-Lock Doors thing is the VERY reason I bought this. I’d love to be able to have the lock automatically lock itself after give minutes (as described above). It sounds like you’ve all figured out exactly how to do this. (Yippee again!). But I have no clue how to take advantage of your code. I was hoping it might be in the SmartThings Labs section of the new app, but, well, nope. I suspect there’s a way to add this - but I don’t have any clue where/how. Can someone point me in the right direction?

Any help will be much appreciated. I’m gonna love all this, I just know. Now, while I wait for your answer, I’m going to see if I can load all my Hue bulbs and set up the SmartThings equivalents of the various “Scenes” I’ve created already. Then, back to the online store to order more sensors and such (I’ve thought of dozens of uses already!).