Schlage Encode Wifi

Thanks, keep us in the loop if you come up with an integration! I was working the Yonomi angle but they didn’t want to work with individuals.

Thanks for the groundwork!

My pleasure! Glad I can share something useful! I’ve been running this with my home automation setup for the last 5 days and so far its pretty solid. Not too bad for something hacked together in an afternoon :stuck_out_tongue: Mcnutter1 was going to look into bringing it to full integration status, so hopefully it’ll get there in the near future. But for now it should work ok as an MQTT client.

1 Like

First, thank thank you punk-kaos and everyone who has been working at a solution!
I apologize in advance for my ignorance, but if I want to try and test this right away, do I just drop this file (doorlock.py) into a subfolder under custom_components and modify the text to suit my case (i.e. input username, password, & mqtt broker)? or is there more I need to do here?

1 Like

Almost.

I configured an MQTT lock; restarted HA to pickup new configs; downloaded doorlock.py; configured the username, password with my Schlage credentials; configured broker, port, topic with my MQTT info; installed python dependencies (in a virtualenv, by trying to run doorlock.py, getting an error, pip installing the dependency); let doorlock.py run forever; profit!

2 Likes

I appreciate the response. The part I am struggling with is running doorlock.py in a virtual environment. What can/should I use given that I am running HASS on a PI 4B? AppDaemon?

AppDaemon is the path I have been pursuing so far, but without success. It seems AppDaemon is looking for a class statement (i.e. class DoorLock(hass.Hass) ) within doorlock.py , which it then wants called out within the apps.yaml file…??

…so it seems I’m stuck

any help would be appreciated.

1 Like

I’m not sure if this is all set up right but it’s been working for a week without issue.
In apps.yaml I have this

schlage:
module: schlage
class: script
logs: error

On first startup the log showed that I needed some extra packages. I added them using the configuration tab in AppDaemon (in the add-ons area)

Hope this helps

1 Like

I tried following your instructions on my HA server running via Debian 11 and a supervised docker install.

I keep getting pip, pip3, discutil,cmd, etc not found when I try to troubleshoot installing the missing dependency “boto3”

Any tips you can share?

Thanks for this script. It works partially with my Schlage Sense & WiFi Adapter. I am able to read the status of the lock, but not control the lock. I have rebooted both the lock and the WiFi adapter. It is the same with a guest account or my main owner account. Is there a debug log? A (future) feature request: I would like to see the user that locked/unlocked, as then I can perform automations on who comes home.

1 Like

Hmm, interesting. I’ve not tried it on a guest account, but the main account should work no problem. I’ll have to cook some debug in. There’s not a LOT that the API gives back, but there is some… As far as knowing WHO unlocked the door, the app has a history of that so I should be able to figure out how thats done and add something to report that. I’ll noodle on that a bit.

1 Like

This would be awesome as it could be linked to disarming the alarm. At the moment this isn’t possible as someone could have broken down the door and then turned the thumb turn to disarm!

Please forgive my ineptitude:)
Could someone point me towards a step by step instruction set to integrate the Schlage lock into HA?
I have created the .py file and added the MQTT lines to configuration.yaml but beyond that I am well and truly stuck!
Thanks for looking!

2 Likes

I’ve just done this on my Ubuntu 22.04 system.

sudo apt install python3-pip python3.10-venv
mkdir ~/schlage
cd ~/schlage
git clone https://github.com/punk-kaos/Schlage-encode-API-reverse-engineering.git schlage-door
python3 -m venv schlage-door
source schlage-door/bin/activate
cd schlage-door
pip install paho-mqtt boto3 requests pycognito

edit (vi or nano) doorlock.py and insert your username and password for Schlage and your MQTT broker address and run it with

python3 doorlock.py

Then add this to home assistant config.yaml

mqtt:
  lock:
    - name: Front Door
      command_topic: "schlage/lock/command"
      state_topic: "schlage/lock/state"
      payload_lock: "LOCK"
      payload_unlock: "UNLOCK"
      state_locked: "LOCKED"
      state_unlocked: "UNLOCKED"

my lock is a Schlage Sense connected through a BR400 Wi-Fi adapter, so the commands to lock/unlock don’t work, but it connects, and shows the status.

Thats interesting the lock/unlock commands are no good. Do you happen to know what they are? It would be easy to add them if you do.

@punk-kaos any luck with the history API? Who locked / unlocked the lock?

Also, as an update, I have the basic HASS API built, working on building it into an integration.

Also, any chance you can make this work with asyncio? ITs going to be the roadblock for HASS.

It depends on what you need for asyncio. Its already synchronous with the MQTT code. If you can provide some detail, I’m happy to explore it.

As far as the history, yes I’ve made some progress on that front. Looks like it does get returned. I’m working on adding that and the ability to query multiple locks for people who have more than one. I’ll finish that out once I get a spare second to write some code… Busy work week this week!

The token call is synchronous, for HASS to not block the main event loop it needs to be async.

I have your code ported into a direct hass integration with support for multiple locks but I can’t figure out how to make the token request async. I tried aioboto3 but it doesn’t support cognito.

Ahh, yeah that part is… Hmmm. I’ll put some thought into how to deal with that. Shouldn’t be TOO hard to make happen.

I solved the AsyncIO issue, but it seems like there is some weirdness with the lock/unlock commands. There isn’t an instant result sent to the lock, instead its a minute or so later… does the app api send the same request over and over or something to wake the lock up?

Also, first version of the hass integration here: GitHub - mcnutter1/homeasssitant-schlage: Schlage Encode implementation for Home Assistant… Supports multiple locks, lock/unlock (with the observed delay)… Setup through the UI… no error checking / handling so check logs and post if anything doesn’t work.

Also,

1 Like