Integrating sensor values into a curl statement

i have the following in my Yaml file

switch:

  • platform: command_line
    switches:
    output:
    command_on: ‘curl -d d=“20210620” -d t=“17:10” -d v4=“555” -d v2=“666” -H “X-Apikey: 1f1930efacf444444c3b563a9dbbca3f9749999” -H “X-Id:99999” http://website/status.jsp
    value_template: ‘{{ value == “1” }}’
    friendly_name: output

which works perfectly, however I need to replace the values for v4 (555) and v2 (666) with values from entities.

I have scoured the net and this forum but have been unable to find a solution.

Any help to a newbie to the fantastic homeassistant greatly appreciated.

Welcome to the forum.

There is an example of template use in the command line sensor documents, https://www.home-assistant.io/integrations/sensor.command_line/#usage-of-templating-in-command

Also please have a read of point 11 here.

Thanks for your reply,

I had already looked there, but after you reply I looked more closely and realised the problem was actually the lack of single quotes around the variables, inserting two single quotes around the variable function solved the problem.

However I now have another problem, the following sensor is sending data without being ( as far as I can tell) triggered.

 - platform: command_line
   name: upload
   command: "curl -d  d=''{{ states('sensor.time_formatted' ) }}'' -d t=''{{ states('sensor.time' ) }}'' -d  v4=''{{ states('sensor.value' ) }}''  -d  v2='676' -H 'key: 1f1930efacf7c1bababababab9dbbca3f97493d5' -H  'SystemId:12345' http://web.address/status.jsp"     

I have tried doing this with the command line switch instead

switch:
  - platform: command_line
    switches:
      output_upload:
        command_on: "curl -d  d=''{{ states('sensor.time_formatted' ) }}'' -d t=''{{ states('sensor.time' ) }}'' -d  v4=''{{ states('sensor.value' ) }}''  -d  v2='676' -H 'key: 1f1930efacf7c1bababababab9dbbca3f97493d5' -H  'SystemId:12345' http://web.address/status.jsp"   
        value_template: '{{ value == "1" }}'

But I get the following error

2021-06-22 13:50:02 ERROR (SyncWorker_2) [homeassistant.components.command_line] Command failed: curl -d d=’’{{ states(‘sensor.time_formatted’ ) }}’’ -d t=’’{{ states(‘sensor.time’ ) }}’’ -d v4=’’{{ states(‘sensor.value’ ) }}’’ -d v2=‘676’ -H ‘key: 1f1930efacf7c1bababababab9dbbca3f97493d5’ -H ‘SystemId:12345’ http://web.address/status.jsp"
2021-06-22 13:50:02 ERROR (SyncWorker_2) [homeassistant.components.command_line.switch] Command failed: curl -d d=’’{{ states(‘sensor.time_formatted’ ) }}’’ -d t=’’{{ states(‘sensor.time’ ) }}’’ -d v4=’’{{ states(‘sensor.value’ ) }}’’ -d v2=‘676’ -H ‘key: 1f1930efacf7c1bababababab9dbbca3f97493d5’ -H ‘SystemId:12345’ http://web.address/status.jsp"

It is exactly the same curl command in both examples, I am totally confused!

Neither command in the sensor nor command_on in the switch support templating according to the docs.

image

image

You might be able to use shell_command instead: