Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ docker run \
```
rest:
- scan_interval: 60
resource: http://192.168.1.162:8125/123
resource: http://192.168.1.100:5000/123
sensor:
- name: "Front Door"
- name: "Front Door Lock"
value_template: "OK"
json_attributes:
- "autoLockTime"
Expand All @@ -56,8 +56,33 @@ rest:
- "passageModeAutoUnlock"
- "soundVolume"
- "tamperAlert"

- scan_interval: 60
resource: http://192.168.1.100:5000/123/getstatus
sensor:
- name: "Front Door ttlock Status"
value_template: "{{ value_json.state }}"
unique_id: frontdoor_ttlock_status
json_attributes:
- "sensorState"
- "state"


rest_command:
unlock_door:
url: "http://192.168.1.162:8125/123/unlock"
unlock_front_door:
url: "http://192.168.1.100:5000/123/unlock"
method: get
lock_front_door:
url: "http://192.168.1.100:5000/123/lock"
method: get
```

lock:
- platform: template
name: Front Door
value_template: "{{ state_attr('sensor.frontdoor_ttlock_status', 'state') | int(0) != 1 }}"
optimistic: true
lock:
- service: rest_command.lock_front_door
unlock:
- service: rest_command.unlock_front_door
```
18 changes: 17 additions & 1 deletion ttlock_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ def handle_unlock(lock):
if response.status_code == 200:
return(response.json())

def handle_lock(lock):
get_token()
data = {"clientId": clientId,
"accessToken": accessToken,
"lockId": lock,
"date": current_milli_time()
}

response = requests.post("https://euapi.ttlock.com/v3/lock/lock", data)

if response.status_code == 200:
return(response.json())

def request_lock(lock):
get_token()
Expand All @@ -78,6 +90,10 @@ def hello():
def unlock(lock):
return handle_unlock(lock)

@app.route("/<lock>/lock",methods = ['POST', 'GET'])
def lock(lock):
return handle_lock(lock)

@app.route("/<lock>/users",methods = ['GET'])
def users(lock):
return handle_users(lock)
Expand All @@ -88,4 +104,4 @@ def get_lock(lock):

@app.route("/<lock>/getstatus",methods = ['GET'])
def get_lockStatus(lock):
return request_lockStatus(lock)
return request_lockStatus(lock)