Some members of my family have a habit of forgetting to lock the door. I’d like to set up an SMS and/or voice notification if the door is left unlocked for longer than X minutes. There’s a built-in dashboard app to notify when the door is left open, but I don’t see an equivalent for the door being unlocked. Just wanted to check if there’s a solution already before I put on my coder’s hat.
Based off the open door
/**
- Left It unlocked
- Author: matt
- Date: 2014-10-10
*/
definition(
name: “Left It Unlocked”,
namespace: “matt”,
author: “matt”,
description: “Notifies you when you have left a unlocked longer that a specified amount of time.”,
category: “Convenience”,
iconUrl: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png”,
iconX2Url: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png”
)
preferences {
section(“Monitor this lock”) {
input “lock”, “capability.lock”
}
section(“And notify me if it’s unlocked for more than this many minutes (default 10)”) {
input “unlockedThreshold”, “number”, description: “Number of minutes”, required: false
}
section(“Via text message at this number (or via push notification if not specified”) {
input “phone”, “phone”, title: “Phone number (optional)”, required: false
}
}
def installed() {
log.trace “installed()”
subscribe()
}
def updated() {
log.trace “updated()”
unsubscribe()
subscribe()
}
def subscribe() {
subscribe(lock, “lock.unlocked”, doorUnlocked)
subscribe(lock, “lock.locked”, doorLocked)
}
def doorUnlocked(evt)
{
log.trace “doorUnlocked($evt.name: $evt.value)”
def t0 = now()
def delay = (unlockedThreshold != null && unlockedThreshold != “”) ? unlockedThreshold * 60 : 600
runIn(delay, doorUnlockedTooLong, [overwrite: false])
log.debug “scheduled doorUnlockedTooLong in ${now() - t0} msec”
}
def doorLocked(evt)
{
log.trace “doorLocked($evt.name: $evt.value)”
}
def doorUnlockedTooLong() {
def lockState = lock.currentState(“lock”)
if (lockState.value == “unlocked”) {
def elapsed = now() - lockState.rawDateCreated.time
def threshold = ((unlockedThreshold != null && unlockedThreshold != “”) ? unlockedThreshold * 60000 : 60000) - 1000
if (elapsed >= threshold) {
log.debug “Lock has stayed unlocked long enough since last check ($elapsed ms): calling sendMessage()”
sendMessage()
} else {
log.debug “Lock has not stayed unlocked long enough since last check ($elapsed ms): doing nothing”
}
} else {
log.warn “doorUnlockedTooLong() called but door is locked: doing nothing”
}
}
void sendMessage()
{
def minutes = (unlockedThreshold != null && unlockedThreshold != “”) ? unlockedThreshold : 10
def msg = “${lock.displayName} has been left unlocked for ${minutes} minutes.”
log.info msg
if (phone) {
sendSms phone, msg
}
else {
sendPush msg
}
}
Thanks! That’s a good starting point
Yup, I remembered I did this but couldn’t find it in my IDE. I found the local file installed it and tested it to be sure it worked.
Also, should you go ahead and automatically lock it if it’s unlocked that long? That’s what I do but mine are keypad locks so maybe that does not make sense for other types.
That should be optional, I believe, because there may be a good reason why the door was left unlocked. I don’t want to “over-automate” things. Also, if you going to auto-lock, you’d better make sure that the door is actually closed.
Agree 100% with you @geko if my doors aren’t shut and I tell them to lock it messes them up and I have to recalibrate them (kwikset) They have an auto lock feature but I don’t use it.
I just want to be notified that they are unlocked so that if it wasn’t intentional they can be locked. I suppose we could tell it to check if door is open and then not lock. But I’m really not that great at groovy yet.
Anyway this works for my needs and since you asked I posted. There are probably numerous ways it could be better.
There is an app to auto lock the doors after x min only if closed. Of course if the magnet is close enough the contact sensor will report closed but if it’s not closed fully then it still tries to lock and might cause issues.
I stay at home so it’s easier I guess. I auto lock after 5 min. Sure the kids have to put in their code to get back in from the back yard but I think it’s helping them learn their numbers
The new and improved “Remind to Lock” smart app is now available! Again, thanks to @mattjfrank for the original idea.
Get it here: https://github.com/statusbits/smartthings/tree/master/RemindToLock
Features
- Sends Push notifications (delivered to your SmartThings mobile app).
- Sends text message (SMS) notifications to up to three phone numbers.
- Voice notifications using compatible Text-to-Speech device.
- Configurable time interval (in minutes) before the notification is sent.
- Optionally, notifications can be repeated every N minutes.
- Can set a limit on the number of notifications sent.
No thanks needed, I only modified a ST app. You made it great. Thanks for your contribution to the community, again.
I tried to load this last night and got the following.
error java.lang.NullPointerException: Cannot execute null+null @ line 186
Another person did too that I told about this.
Found the problem. Note to self: last minute changes never pay off
Fixed in version 1.0.2.
Has anyone built a SmartApp to notify you when you leave home with your doors unlocked? I’d find this more useful than the time based since we often leave our doors unlocked when we’re home.
Thanks @mattjfrank! I’m new here. Took me a while to figure out how to only run smartapps in particular modes. I combined it with Bon Voyage and Greetings Earthling to hopefully remind me to lock the doors when I leave.
Hey @geko thanks for taking the time to code this. I’m unfortunately unable to access the code via the github link you provided. I keep getting directed to a “Page not found” page. Could you please post your code either in the thread itself, or with a live link? I’d really like to have this functionality, thanks again!
Also, thanks to @mattjfrank for your work on this.
It’s you guys that really make this product great!
It appears as though he’s removed the code. I’m sure he has a reason so I won’t post it. @geko was this intentional or accidental.
Yeah, stuff got moved around. Here’s the new link:
https://github.com/statusbits/smartthings/tree/master/RemindToLock
Thanks for the quick follow up! Have it installed and it’s working perfectly =)
I have tried to run this remindtolock smartapp in the Smartthings simulator and I get the following error:
java.lang.NullPointerException: Cannot get property ‘value’ on null object @ line 91
This line # points to:
if (lockState.value == “unlocked”) {
Any ideas?