Sign inSign up

stevendodd/ttlock

By stevendodd

•Updated about 4 years ago

A restful API for TT lock for home assistant integration; handles access tokens and dates

Image
1

2.5K

stevendodd/ttlock repository overview

A restful API for TT lock; handles access tokens and dates https://github.com/stevendodd/ttlock-docker⁠

  1. Create an application https://open.ttlock.com/manager⁠
  2. Register a user in the application - returns a prefixed user that you can add to your lock
curl --location -g --request POST 'https://api.ttlock.com/v3/user/register' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'clientId=your id' \
--data-urlencode 'clientSecret=your secret' \
--data-urlencode 'username=lockuser' \
--data-urlencode 'password=your application users password md5 hashed' \
--data-urlencode 'date=1650909361599'

https://currentmillis.com⁠ - get the current date

echo "password" | md5 - md5 hash password

  1. Add your new prefixed user to your lock in the TT lock app
  2. Create a Docker container
docker run \
-e CLIENTID='your id' \
-e CLIENTSECRET='your secret' \
-e LOCKID='your lock id' \
-e USER='your prefixed application user' \
-e PASSWORD='your application users password md5 hashed' \
-p 5000:5000 stevendodd/ttlock
  1. Add the following sensor and rest command to configuration.yaml in home assistant
rest:
  - scan_interval: 60
    resource: http://192.168.1.162:8125/123
    sensor:
      - name: "Front Door"
        value_template: "OK"
        json_attributes:
          - "autoLockTime"
          - "electricQuantity"
          - "firmwareRevision"
          - "hardwareRevision"
          - "lockAlias"
          - "modelNum"
          - "passageMode"
          - "passageModeAutoUnlock"
          - "soundVolume"
          - "tamperAlert"
  - scan_interval: 5
    resource_template: http://192.168.1.162:8125/123/users
    sensor:
      - name: "Front Door unlock name"
        value_template: '{{ value_json.list[0].username }}'
      - name: "Front Door unlock date"
        value_template: '{{ (value_json.list[0].lockDate | int / 1000) | timestamp_custom("%a, %d %b %Y %H:%M") }}'
rest_command:
  unlock_door:
    url: "http://192.168.1.162:8125/123/unlock"
    method: get

https://community.home-assistant.io/t/ttlock-integration-with-ha/211244/26⁠

Tag summary

Content type

Image

Digest

sha256:551b57c8c…

Size

47.8 MB

Last updated

about 4 years ago

docker pull stevendodd/ttlock