Send Distress Message When Door Lock Code Used

This app basically sends a text message to someone when a certain code is used to unlock the door. This is similar to how distress codes are setup on alarm systems and I figured most people here aren’t paying for an alarm system. There is a code discovery mode in the app also so that you can find which code is assigned to your unlock code without needing a computer. I have only tested this with a Schlage lock so I’d like to know if this works for other lock types.

https://github.com/skp19/st_door_lock_code_distress_message


If you find this app useful, please support the developer:

6 Likes

This is a brilliant idea. Something pretty simple that could have a profound impact, especially if someone is “jumped” as they are entering their house / apartment.

@eparkerjr, Which device handler are you using with this app?

@625alex It’s connecting to anything with lock capability. What I’m not sure of is if the system reads the codes differently depending on the lock type.

You should submit this into the publishing process when you are ready - to share with everyone.

This is such a cool idea. Dan actually text me to tell me about it when he saw the submission. Super duper cool. I feel like the professor guy in the Bourne Identity movie.

I have a separate alarm system but still would love this app. It would be great if the app can alert on multiple codes such as 0000 and 7777 which is a sign someone is trying to break in. Almost like an intrusion detection system…is that possible?

1 Like

@Mbhforum Do you mean when someone enters the wrong code multiple times or specific codes?

Yes, if someone entered a group of codes you cared about that are weak such as 0000,1111,1234, etc. It would be a good Intrusion Detection warning if someone came up to your door and tried multiple codes.

@Mbhforum I don’t think it’s possible at the moment to detect something like that. Right now the Schlage lock only returns the user code the unlock code is assigned to which means that to detect those codes they would have to exist in the lock already. But that would also mean that the codes would unlock the door.

This could also be used to let you know that your contractor/house cleaner/dog walker arrived at your house.

@eparkerjr I’ve updated your code slightly to include a push notification and make the SMS optional. Please feel free to include it into your code and thanks a lot for this excellent functionality.

@Ben something for the ST community to include in the apps, custom notifications on user codes.

/**
 *  Door Lock Code Access Message
 *
 *  Taken from skp19
 *
 * UPDATED: 2014-11-17
 *
 */
definition(
    name: "User door unlock notification",
    namespace: "rboy",
    author: "RBoy",
    description: "Sends a notification and text when a specific user unlocks the door",
    category: "Safety & Security",
    iconUrl: "https://s3.amazonaws.com/smartapp-icons/Solution/doors-locks-active.png",
    iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Solution/doors-locks-active@2x.png")

import groovy.json.JsonSlurper

preferences {
	section("Choose Locks") {
		input "lock", "capability.lock", multiple: true
	}
    section("Enter User Slot Number (This is not the code used to unlock the door)") {
    	input "userSlot", "number", defaultValue: "1"
    }
    section("Notification Options") {
    	input "distressMsg", "text", title: "Message to send"
    	input "notification", "bool", title: "Send notification"
    	input "phone", "phone", title: "Phone number to send SMS to (optional)", required: false
    }
    section("User Code Discovery Mode (Enable and unlock the door using desired code. A message will be sent containing the user code used to unlock the door.)") {
    	input "discoveryMode", "bool", title: "Enable"
    }
}

def installed() {
    subscribe(lock, "lock", checkCode)
}

def updated() {
	unsubscribe()
    subscribe(lock, "lock", checkCode)
}

def checkCode(evt) {
    log.debug "$evt.value: $evt, $settings"

    if(evt.value == "unlocked" && evt.data) {
    	def lockData = new JsonSlurper().parseText(evt.data)
        
        if(discoveryMode) {
        	sendPush "Door unlocked with user code $lockData.usedCode"
            return
        }
        
        if(lockData.usedCode == userSlot && discoveryMode == false) {
        	if (phone) {
        		sendSms(phone, distressMsg)
            }
            if (notification == true) {
            	sendPush "$distressMsg"
            }
        	log.info "Distress Message Sent"
        }
    }
}
1 Like

Another great app with this functionality AND a lot more.

@eparkerjr

I’ve installed this and have selected to receive texts but it is not working. I do know text notifications are working in other smart apps…any ideas what to check?

Did you find the problem? If not, I’ll take a look at it today…

Hello Barry,

I did finally get it working although I’m not certain what the resolution was as it just started working a few days later.

I appreciate your follow up. Merry Christmas!

I expanded on this code to have a little more functionality.