[英]Home Assistant: Command_line & REST Switch
I am trying to unlock my door through HA, it's a straightforward HTTPS link but in the last variable of the link "date=" we need to assign the current date, which I think is the one that is causing issues with my below code:我正在尝试通过 HA 解锁我的门,这是一个简单的 HTTPS 链接,但在链接“date =”的最后一个变量中,我们需要分配当前日期,我认为这是导致以下代码出现问题的日期:
switch:
- platform: command_line
switches:
home_door_four:
command_on: "curl -k https://api.ttlock.com/v3/lock/unlock?clientId=xxxxx&accessToken=xxxxx&lockId=xxxxx&date={{ (now().timestamp() | int * 1000 ) }}"
command_off: "curl -k https://api.ttlock.com/v3/lock/lock?clientId=xxxxx&accessToken=xxxxx&lockId=xxxxx&date={{ (now().timestamp() | int * 1000 ) }}"
I got this working using the rest_command and template lock integration.我使用rest_command和模板锁集成来完成这项工作。
NB: This is just a snippet of my code, I'm sure you can fill in the blanks, I also use a door sensor and also get the lock status from the API.注意:这只是我的代码片段,我相信你可以填写空白,我也使用门传感器并从 API 获取锁定状态。
rest_command:
unlock:
method: POST
content_type: "application/x-www-form-urlencoded"
url: >
https://api.ttlock.com/v3/lock/unlock?clientId=xxxxxxx&accessToken=xxxxxxx&lockId=xxxxxxx&date={{ as_timestamp(now()) | int * 1000 }}
Then create the lock:然后创建锁:
lock:
- platform: template
name: myLock
optimistic: true
lock:
service: rest_command.lock
unlock:
service: rest_command.unlock
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.