Schlage Encode Wifi

@mcnutter1 Really appreciate the integration work. It installed perfectly for me and the locks now show up for use in scenes and everything else. Top notch!

2 Likes

Working great for me! Thank you for this! Question, I added it to my google home (assistant) for voice command functionality and it asked for a PIN. Where do I set this at?

The pin has to be setup in the Schlage app, under the ā€œWorks Withā€ > menu. Then in Home app, you have to add Schlage in itā€™s Set up a device > ā€œWork With Googleā€ menu. May end up with duplicate locks, one from Nabu Casa (if you use that service) and one from Schlage directly.

I will say I donā€™t think this capability to unlock with Google Assistant has been around all that long, perhaps a recent Schlage update.

The pin doesnā€™t flow from Schlage app through the Home Assistant integration to Google Assistant currently, and doubt thatā€™s even possible but the developer would have to chime in.

Can we add your repository via HACS and do it that way, does anybody know? I also thank all of you who got us this far. Iā€™ve been checking back in for years. Come to think of it I wonder if my lock is actually compatible. Iā€™ll go back and read some more. Mine is the schlage encode WiFi. I donā€™t think mine is the home kit compatible version. I was going to try and do something with Amazon key but it wasnā€™t clear if it was possible.

Yep, the Schlage Encode Wifi is what this is forā€¦ It PROBABLY works with any other Schlage locks that use the same app but Iā€™ve not tested with anything other than the Encode Wifi.

Alright yep works pretty darn good. Thanks for this! Wish I could safeguard the functionality. I will add here b/c I had to look around a bit to get the instructions in this thread. Cant install with HACS so just place in custom_components folder in your config folder. Restart HA. Add integrationā€¦search schlage and add, then its a little rough around the edges but first space for your name and second your password. Played around with the entities that it created to for me as they were generic and hard to find. At long last! though this lock is integrated into home assistant. I feel so naive looking back thinking this lock was the way to go after the rough ride with an August lock which was bluetooth with the junkiest wifi bridge you have ever seen. Thanks again ā€¦hope schlage doesnt screw us around some more.

1 Like

Hello! Is there a way to get the ā€œjammedā€ status into home assistant? Iā€™m currently using mcnutters home assistant integration for the schlage encode plus. I see that HomeKit shows when the door lock is jammed but home assistant only has locked or unlocked

That would be SUPER easy with my MQTT version, so it should be easy to do on Mcnutterā€™s version as wellā€¦ Iā€™m on vacation for Thanksgiving but Iā€™ll see if I can get some pull requests in to add that to both versions.

1 Like

I believe someone forked my original integration and has made some significant improvements, adding the jammed feature should be easy, but likely as another entity type.

Wondering if I should update to the forked integration. It seems to work pretty well so I was thinking of leaving it alone but I seem to be throwing these errors in the log.

Logger: homeassistant.helpers.integration_platform
Source: loader.py:745
First occurred: 2 December 2022 at 16:17:39 (9 occurrences)
Last logged: 10:30:57

Unexpected error importing schlage/diagnostics.py
Unexpected error importing schlage/recorder.py
Unexpected error importing schlage/cast.py
Unexpected error importing schlage/significant_change.py
Unexpected error importing schlage/hardware.py
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/integration_platform.py", line 40, in _async_process_single_integration_platform_component
    platform = integration.get_platform(platform_name)
  File "/usr/src/homeassistant/homeassistant/loader.py", line 728, in get_platform
    cache[full_name] = self._import_platform(platform_name)
  File "/usr/src/homeassistant/homeassistant/loader.py", line 745, in _import_platform
    return importlib.import_module(f"{self.pkg_path}.{platform_name}")
  File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'custom_components.homeasssitant-schlage-main.group'

Are you continuing to work on this? Not really a GitHub pro and wondering if I should update it?

Thanks

For what its worth Iā€™ve been getting those same errors regularly starting from the first integration version and even on the current version but everything seems to be working

Logger: homeassistant.helpers.integration_platform
Source: loader.py:745
First occurred: 1:49:01 PM (9 occurrences)
Last logged: 2:02:39 PM

Unexpected error importing schlage/diagnostics.py
Unexpected error importing schlage/recorder.py
Unexpected error importing schlage/significant_change.py
Unexpected error importing schlage/cast.py
Unexpected error importing schlage/hardware.py
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/integration_platform.py", line 40, in _async_process_single_integration_platform_component
    platform = integration.get_platform(platform_name)
  File "/usr/src/homeassistant/homeassistant/loader.py", line 728, in get_platform
    cache[full_name] = self._import_platform(platform_name)
  File "/usr/src/homeassistant/homeassistant/loader.py", line 745, in _import_platform
    return importlib.import_module(f"{self.pkg_path}.{platform_name}")
  File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'custom_components.Schlage.group'

I am seeing this as well. Has anyone figured out what allows the mobile app to work consistently w/ lock and unlock (albeit with a bad delay for a mobile app (seconds) at times) where as the HA integration seems to work for a bit after power cycling the lock and then not at all (or with extreme delay (minutes)) later when trying to lock and unlock?

Something else interesting that I observed is that it looks like the call to lock and unlock triggered a 403 from the API if the HA integration is configured with w/ a user that has a Virtual Key that isnā€™t an ā€œAdminā€ in the mobile app but it seems that it can still read the lock state OK. Is there perhaps a different API call that the app is using for non-administrative users or administrative users under certain circumstances?

I am pretty sure the official app uses websockets to subscribe to changes to almost immediate changes to the lock state. The tool I used to discover the API (mitmproxy) doesnā€™t trivially support sniffing websockets, so I donā€™t know what those look like. These integrations use cloud polling, which will always have a delay. Comment #59 has my investigation details, if someone can use it to reverse engineer the websocket API.

Iā€™ve been trying to figure that out myself. After a couple weeks my lock can take as much as 10 minutes between when the lock command has been sent and when the lock finally locks, which obviously isnā€™t ideal. A power cycle of the lock seems to fix that, making me think its the lock itself having the issue and nothing to do with the API or websockets though maybeā€¦ Iā€™m tempted to pull out my hardware debugging tools and see if I can dump the firmware off the lock, though Iā€™m expecting its probably encrypted. Its not the end of the world having to power cycle the lock occasionally, but it does take some of the ā€˜autoā€™ outa my automation.

This work has been amazing! Iā€™m so happy that my expensive locks can be used in HA finally.

Looks like it lost some steam - what would it take to keep this going to a more robust websocket solution with more resilient connectivity and availability sensing + all of the statuses?

Iā€™m happy to support a bounty / ā€œbuy coffeeā€ / donate to push this forward? Not sure how this stuff works, but would love to support!

I looked into the websockets bit and it looks like it only uses websockets to monitor state. So it would receive state updates faster with websockets instead of polling for status like it does now. The API call for changing the state of the lock is the same as the app uses. HOWEVER Iā€™ve noted that the app seems to spam the hell outa the API at times, sending the ā€˜lockā€™ command 5-6 times in a row. I wonder if thats to combat the lockā€™s tendancy to ignore the command for a long time. Iā€™ll do some testing to see if I can sus that outā€¦

That makes sense based on the experienceā€¦ The command spamming is probably to combat bad connectivityā€¦ Sometimes even via app, it takes a few seconds, but status shows fairly quickly and reliably.
With this integration, status updates take 30-60sec and the command takes anywhere from 3-10sec for me (but has never failed yet)ā€¦
I use a status light to show door unlocked, so itā€™s easy to see the delay when locking and it takes 30sec for the light to go off

Iā€™ve spent a bunch of time poking at a decompiled Android APK and I have a few answers. :upside_down_face:

The websockets are MQTT connections to Amazonā€™s IoT service. If you call https://api.allegion.yonomi.cloud/v1/wss with a Cognito identity token in the X-Web-Identity-Token header, you get back a JSON blob with a subscriber id, topics, and a websocket URI that contains authorization tokens as query parameters that you can pass to a MQTT client (note that you have to modify the MQTT client Host header to drop the :433 suffix (e.g. the port) and make sure itā€™s set up for websockets and has SSL enabled)

Thereā€™s a few problems, though:

  1. Only a single client id is generated per account. So if you want to use the Schlage mobile app at the same time, it will punt your other connection. Reconnects are spotty and donā€™t seem reliable.
  2. Worse, you can only get a subscription for a single device at a time. If you try to subscribe to multiple devices, it seems to just silently not return anything. (The underlying websocket may be returning an errorā€“I havenā€™t checked that)

So unfortunately this isnā€™t very helpful for a Home Assistant integration.

In brighter news, Iā€™ve taken some of the breadcrumbs you folks have left in this thread and combined them with my own sleuthing in the decompiled APK and Iā€™ve produced a Python library for talking to the API: GitHub - dknowles2/pyschlage: Python 3 library for interacting with Schlage Encode WiFi locks. (also on PyPi).

Iā€™m hoping to find some time over the holidays to integrate my library into the integration @mcnutter1 started (by the way, you misspelled ā€œassistantā€ in the repo name :stuck_out_tongue_closed_eyes:), but if someone else wants to take a crack at it, be my guest.

Cheers!

3 Likes

Hey, very nice sluthing!! Iā€™ll have to take a look at your library and see about standardizing the MQTT version on it too. Itā€™d be convenient if they both shared the same library.

1 Like