Ttlock support

Hi
Would it be possible to integrate ttlock with homeassistant

http://open.ttlock.com.cn/doc/userGuide

Thanks!
wanball

Hi any progress on that?

Interested in this too. There are lots of ttlock smart locks on AliExpress. Only thing holding me back is integration with Hassio.
Anyone can point me to example integration to give me a head start in trying this?

Im interested too!

and i’m interested too!!

Im interested too!

I am interested too. any updates?

I also have 5 TTLock devices here and would like an integration for those!

Haven’t tried it. Hopefully someone can white a guide to get it up and running

Yes it’s working, I wanted the author to make the first publication since it was his work. but @botts couldn’t hold it :smile:

Add this https://github.com/tonyldo/tonyldo-hassio-addons to your Hassio addons and install the TTLock.

Besides TTLock locks you also need to have the G2 Gateway Wifi (the link is in one of the comments above) and you need to create a account and application at TTLock site https://open.ttlock.com/reg

From there you have to follow this guide https://github.com/tonyldo/ttlockio and create a application, this will take a few days/weeks to be approved but once it’s approved it should give you app_id and app_secret.

Once you have those you can create your new user account, this is explained at the ttlockio step 4. and get the AccessToken at explained at step 6

When all above is done, remove all your locks and gateways from your current account in TTLock (Android or iPhone app) logout and login with your new created account.

Add all your locks and gateways to this new account and head back to the TTLock addon installed and fix the config with data obtained in step6 and your MQTT details and run the addon.

If all went good all your door locks are now added to HA via auto discovery.

1 Like

:zipper_mouth_face: hopefully the exposure will get more people involved in the project. all credit goes to Antonio! Great Dev who has been very responsive to questions.

1 Like

there isn’t much to it now, we can add the rest of the API to have it on HA but the main lock and unlock is working.

The gateway has a ESP12, I have tried flashing Tasmota but didnt manage to get anything from it and went back to stock firmware…
I have been reading the esp trying to decode the protocol, i have a tasmota nodemcu connected to it and i can already see the messages on the console once I can make sense of it i should be able to reflash tasmota and make it work (fingers crossed)

1 Like

Ive noticed in the logs that it checks and tries to add any new locks every 3 minutes (I think)

2020-07-30 22:13:44 - [INFO] ttlock_adapter: Lock 12346 mqtt client already created..

Im not sure if this is necessary maybe this can be a call service request instead?

Thoughts?

Do you know what Bluetooth module it uses to communicate with the lock? and how this interfaces with the esp?

Thank u for help me with this… Lets improve the add-on with new features.

1 Like

Hey Antonio, Great work have my lock setup as below

1 Like

The ttlock API returned a error for multiple request in a short period of time… The TTlock API doc’s doesn’t say anythinhg about how long is this period. The threads sleeps 1 min to avoid this kind of error for every request at TTlock API Cloud.

Great, Thanks for the info!

When the 1 min passes, how many API request is it making?

Could I suggest that the battery query time be reduced as it not critical minute by minute

and decrease the lock/unlock query time (or make these user defined) or to query after x time from unlock trigger?

The Query time for Battery and lock State are 1 min per lock… but at the first time when the lock was created on HASS this time can be more longer. I will fix that.

Here is a guide I put together I hope it is of use to someone, not comprehensive but a starting point

Getting access to the TTlock API for use with Home Assistant TTlock2MQTT addon

Step 1

Go to: https://open.sciener.com/reg or https://open.ttlock.com/reg

Register an account

Once Logged in Select ‘Create Application’
image

Fill in the text fields as below
The Application URL and Redirect URL just need to be a valid URL
(If you use duckdns for Home Assistant point the application to that)
You must Upload an Application Icon that is approx 90px * 90px
https://img.icons8.com/ios/100/000000/door-handle.png Download this if you like
image

Once your Application is created, it will show as under review

image

Select View to get you app_id and app_secret which you will need for creating a user and logging into the TTLock application to setup your gateway and locks (if you have already registered your gateway and locks with another account you can transfer them to the new account via the TTlock App on your phone)

image

Step 2
Install the following Application to make POST calls to the API to create your new users and set a password (Password need to be in MD5 hash format)


Open Advanced Rest Client and select POST from the Method Drop Down and paste the below into the request URL field
https://api.ttlock.com/v3/user/register? 

Then Select the ‘Body Tab’ and paste the following

clientId=YOUR_APP_CLIENT_ID&clientSecret=YOUR_APP_CLIENTSECRET&username=NEW_NAME_FOR_YOUR_USER&password=NEW_PASS_FOR_YOUR_USER&date=CURRENTMILLIS

image

Then under the Body Content Type Drop down,

Select application/x-www-form-urlencoded 

Then under the ‘Editor View’ select ‘Form Data’

This will give you a form layout to enter the parameters such as clientId username, etc easily.

Please note: the password need to be in MD5 hash format – use the below website to enter your password and get a result in MD5 format to paste into the password parameter field of the Request
https://www.md5online.org/
image

Once you have filled this is and hit ‘Send’ you should then get a result at the bottom of the screen similar to the below

{
"username": "APPNAME_USERNAME"
}

Update Request URL by pasting

https://api.ttlock.com/oauth2/token?

Then Select Raw Input from the Editor View and paste the following

client_id=YOUR_APP_CLIENT_ID&client_secret=YOUR_APP_CLIENTSECRET&username=NAME_FOR_YOUR_USER_CREATE_ON_LAST_STEP&password=NEW_PASS_FOR_YOUR_USER_CREATE_ON_LAST_STEP&grant_type=password&redirect_uri=https://yourdomain.com

Again you can then Select Form data from the Editor View so you can enter your parameters to get your token.
image

Once you have filled this is and hit Send you should get a result at the bottom of the screen

{
"access_token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"uid": xxxxxx,
"refresh_token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"openid": xxxxxxxxxx,
"scope": "user,key,room",
"token_type": "Bearer",
"expires_in": 7776000
}

Step 3

Now login with your new username and password in the TTlock app and add your gateway and locks (if you have already registered your gateway and locks with another account you can transfer them to the new account via the TTlock App on your phone)

Step 4

Using all the information you have gathered
Install the TTlock2Mqtt by adding the url listed in the link to your Supervisor Add-on Store in home assistant by clicking the three vertical dots in the rigth upper corner. Then follow the configuration instructions.

1 Like