家庭助理:Command_line&休息开关

发布于 2025-01-18 09:30:47 字数 531 浏览 3 评论 0原文

我试图通过 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 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:

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 ) }}"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

阳光下的泡沫是彩色的 2025-01-25 09:30:47

我使用rest_command模板锁集成来完成此工作。

注意:这只是我的代码片段,我相信您可以填写空白,我还使用门传感器并从 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 }}

然后创建锁:

lock:
  - platform: template
    name: myLock
    optimistic: true
    lock:
      service: rest_command.lock
    unlock:
      service: rest_command.unlock

I got this working using the rest_command and template lock integration.

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.

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文