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:

  - platform: command_line
        command_on: "curl -k{{ (now().timestamp() | int * 1000 ) }}"
        command_off: "curl -k{{ (now().timestamp() | int * 1000 ) }}"

command_on and command_off do not support templates.

You could create two shell commands (that do support templates) and use them as the turn_on and turn_off actions in a template switch.

1 Like

Could you explain more, or is there any way to get the currentmillis without using formula?

No, you have to use a template. Which the command line swtich does not support. So…

Create two shell commands. Use the curl commands you already have.

  home_door_four_on: "curl -k{{ (now().timestamp() | int * 1000 ) }}"
  home_door_four_off: "curl -k{{ (now().timestamp() | int * 1000 ) }}"

Test if these work by calling them in the Developer Tools / Services page. If they do work then create your template switch using the shell commands:

  - platform: template
          service: shell_command.home_door_four_on
          service: shell_command.home_door_four_off

If you can get state feedback from the switch with a command you can add that to the switch too. Read the page I linked to.

1 Like