Switch command_line curl with parameters

Hi, i have a problem with switch and command_line with some parameters.
If i launch switch turn on and try to read a value from a sensor my command throw an exception.
My actual configuration is

switch:
  - platform: command_line
    switches:
      ipcam_motion_switch:
        command_on: 'curl -k "http://admin:[email protected]/cgi-bin/hi3510/param.cgi?cmd=setmdattr&-enable=1&-name=1&-x=0&-y=276&-w=1280&-h=444&-s={{ states.input_number.motion_sensibility.state }}"'
        command_off: some value
        command_state: some value
        value_template: '{{ value == "1" }}' 

i try all combinations with and without single / double apex…

if i put the same command in a shell_command it works:

shell_command:
  motion_ipcam_on: "curl -k http://admin:[email protected]/cgi-bin/hi3510/param.cgi?cmd=setmdattr&-enable=1&-name=1&-x=0&-y=276&-w=1280&-h=444&-s={{ states.input_number.motion_sensibility.state }}"

can you help me please?
thanks :wink:

1 Like

Sadly, you can’t use a template inside of the commands for command line switch. So it is passing the command as you’ve typed it which wont work.

But, since it’s a curl command as a switch, why not use a restful switch?

Otherwise, you can just make some shell_commands and make a template switch using those commands.

shell_command:
  switch_1_on: 'curl -k "http://admin:[email protected]/cgi-bin/hi3510/param.cgi?cmd=setmdattr&-enable=1&-name=1&-x=0&-y=276&-w=1280&-h=444&-s={{ states.input_number.motion_sensibility.state }}"'
  switch_1_off: some command
  switch_1_state: some command
switch:
  - platform: template
    switches:
      ipcam_motion_switch:
        turn_on:
          service: command_line.switch_1_on
        turn_off:
          service: command_line.switch_1_off

Only problem now is…the command_line won’t return the output for us…so not sure how to get the state.

I think the restful switch is the way to go.