TTLOCK Integration with HA

Hello, i am a big newb at this stuff an am hoping i can please get some help.

I’ve tried both techniques above, and am currently struggling with the Docker container, here is the log:

192.168.1.129 - - [31/Dec/2022 07:00:37] “GET /123 HTTP/1.1” 500 -
192.168.1.129 - - [31/Dec/2022 07:00:46] “GET /123/getstatus HTTP/1.1” 404 -
[2022-12-31 07:01:38,667] ERROR in app: Exception on /123 [GET]
Traceback (most recent call last):
File “/usr/local/lib/python3.8/site-packages/flask/app.py”, line 2073, in wsgi_app
response = self.full_dispatch_request()
File “/usr/local/lib/python3.8/site-packages/flask/app.py”, line 1518, in full_dispatch_request
rv = self.handle_user_exception(e)
File “/usr/local/lib/python3.8/site-packages/flask/app.py”, line 1516, in full_dispatch_request
rv = self.dispatch_request()
File “/usr/local/lib/python3.8/site-packages/flask/app.py”, line 1502, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File “/ttlock_rest.py”, line 81, in get_lock
return request_lock()
File “/ttlock_rest.py”, line 58, in request_lock
get_token()
File “/ttlock_rest.py”, line 34, in get_token
accessToken = response.json()[“access_token”]
KeyError: ‘access_token’
192.168.1.129 - - [31/Dec/2022 07:01:38] “GET /123 HTTP/1.1” 500 -
192.168.1.129 - - [31/Dec/2022 07:01:46] “GET /123/getstatus HTTP/1.1” 404 -
192.168.1.129 - - [31/Dec/2022 07:02:17] “GET /123/lock HTTP/1.1” 404 -

Any advice?
Thanks for your time.

Hi, i got this error when trying to pull the image

ERROR: no matching manifest for linux/amd64 in the manifest list 

Any advice?

You are running it for an AMD64 arch and the one I rebuilt is only for ARM Archs so you should use the original one from @stevendodd Docker. That one should work for you.

1 Like

yea, I can use the original one but unfortunately it can’t lock the door or give me the status of the lock :frowning:.

Hiya, I just purchased a smart lock based on TTLOCK, can I please confirm if I will need a gateway as a medium to connect between gateway and internet? Or can I use the bluetooth proxy from ESP32? thanks

2 Likes

Hiya, can you please share the steps that you’ve taken to get this working and do you use the gateway that your smartlock has provided or did you use ESP32 bluetooth proxy to communicate with it? Thanks

Hi, just wondering if you re able to help me as I’m stuck at this step as I’m getting error below. Thanks

print(‘Gateway ID and Gateway Lock quantity: {}, {}’.format(gateways[0].get(‘gatewayId’),gateways[0].get(‘lockNum’)))
Traceback (most recent call last):
File “”, line 1, in
IndexError: list index out of range

Have any advice or direction for exactly WHAT needs to be done in the Mosquito configuration? Your response here was the only one that helped me - I am now just stuck on what exactly to do in that particular add on… thanks in advance.

can anyone assist me with this error

I have tried with commas, without commas, with a space and without but i always end up with Error_code -3
it goes without saying the crendials are not correct :slight_smile:

Here is all in detail explained what you need to integrate in HA a TTlock!

2 Likes

Abit off subjet I’m looking for a programmer who can assist us (landlord) with building a system to manage tenants and access rights using TTLOCK and Akuvox API’s. Please PM me or send me an email to [email protected] if interested. Sorry but haven’t found any ttlock developers out there and hope can find them here

For anybody else having problem with “where do I find lockId value”?
(as it is required in the integration, but I haven’t found the clean explanation how to get it)

In order to see Your lock on API /v3/lock/list
API’s /v3//lock/initialize call require lockData which is not the same as lockId.

  1. In my case, I just registered regular normal (non-API) TTLock account, logged into TTLock app
  2. Added my lock using TTLock app and bluetooth
  3. Created API account (instructions are in this thread already); note: You register using /v3/user/register with (example) “sampleuser”, but get something “abcd_sampleuser” after API registration (“abcd” is a prefix for Your client app users)
  4. NOTE: go to lock settings and set “Remote unlock” to “on” (otherwise You won’t be able to unlock remotely via API calls)
  5. “Transfer lock” in TTLock app to my API accoun - as the receiver I put my API user “abcd_sampleuser”
  6. Get access token with /oauth2/token
  7. Call /v3/lock/list - now You should be able to see a transferred lock
  8. In the response You can find “lockId” and “lockData” - use it in next call
  9. Initialize lock /v3/lock/initialize (use “lockData” from previous step)

You can log-in to web-version of TTLock or use Android/iPhone version (use something like “abcd_sampleuser” and password (plain text, not MD5 version) You provided at API /v3/user/register call. Now some actions can be done via the application and not (sometimes difficult) API calls.

Note: the “transfer” step will move Your lock from TTLock account to Your API user account!

Disadvantages I found:

  • I was not able to add “Passcode” via the TTLock app (logged with create API user) - I received error like “no lock password” or something
  • … however, I was able to generate passcodes via API /v3/keyboardPwd/add (not pernament, but timed only)

PS:
Somebody put MD5 generation command (required to generate MD5 hash for new user), but it was invalid. If You are using Linux you can use:

echo -n "yourpassword" | md5sum

(note: “-n” parameter is to echo just plain text, without “new line” char at the end, which makes final MD5 checksum different (I bothered why I cannot login but it was wrong MD5 I was using)

I hope it will clarify some questions. Enjoy!

2 Likes

Note:

echo "password"

will add extra “new line” to the password string and thus make the final MD5 hash for different input than just your “plain text” password.
You should use -n parameter

echo -n "password" | md5

or

echo -n "password" | md5sum

I’ve started developing a custom integration for ttlock with the eventual goal of getting it upstreamed directly into Home Assistant.

Warning right now it’s pretty limited to locking and unlock locks, state isn’t reliably syncing back but I’ll keep chipping away at as I have time.

Would appreciate feedback, and welcome pull requests from anyone who wishes to contribute.


2 Likes

I’m not aware of any current BLE implementations that work locally.

I found a gateways via AliExpress
https://s.click.aliexpress.com/e/_DEPpClx

G2 if you want it to connect to your wifi, G3 if you want to plug it in via Ethernet

1 Like

Thank you for building this!

My pleasure! Let me know if its working for you

This is working well for me! Using a generic lock with model number stated as G200t. Only thing that bothers me is the delay. Have placed the gateway at the best spot possible. Having a delay of about 10 seconds on average after pressing unlock in HA. Any chance it could get better?

There’s very little that can be done about this if we’re using their cloud service since there are no local options with the gateway.

For me the delay is closer to 5s but even if it was 10s that’s not particularly problematic for me, I mostly just want the ability to lock/unlock so I don’t have much of an incentive to try building an esp32 BLE implementation (which is out of my skillset I think)

1 Like

Awesome, can’t wait to try it out. Just waiting on getting the app approved. I hope it doesn’t take too long.

1 Like