Disappearing Quotation Marks on Command Line Sensor

Hello again Home Assistant’s :slightly_smiling_face:

I’m having a problem with a command_line sensor in that the command contains quotation marks around a web address and when the command is parsed by Home Assistant, the quotation marks are removed causing the command to fail.

I am running the latest version of Hassio and Home assistant and have successfully been able to run the command ( with quotation marks ) on the Hassio command line.
When the command is run on the Hassio command line without quotation marks, it fails.

I have a very similar command_line sensor, also with quotation marks around a web address, but when the address is parsed, the quotation marks are NOT removed.

I have tried every combination of single / double / no quotation marks I can think of, but they are always removed.

First the working sensor from sensors. yaml

# This one works and quotes remain after being parsed by HA

command: 'curl -k --silent "http://192.168.1.7:88/get_status.cgi?user=xxx&pwd=xxx" | grep alarm | cut -b 18'

and the corresponding entry in the .log file

2018-12-24 19:37:36 INFO (SyncWorker_7) [homeassistant.components.sensor.command_line] Running command: curl -k --silent "http://192.168.1.7:88/get_status.cgi?user=xxx&pwd=xxx" | grep alarm | cut -b 18

Note how in the above log entry the double quotes REMAIN around the web address.

Now the sensor that doesnt work from sensors.yaml

# This one doesn't work due to quotes being removed when parsed

command: 'curl -k --silent "https://pvoutput.org/service/r2/getstatistic.jsp?key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&sid=xxxxx&df={{(states.input_datetime.bill_date_from.attributes.year)}}{{(states.input_datetime.bill_date_from.attributes.month)}}{{(states.input_datetime.bill_date_from.attributes.day)}}&dt={{(states.input_datetime.bill_date_to.attributes.year)}}{{(states.input_datetime.bill_date_to.attributes.month)}}{{(states.input_datetime.bill_date_to.attributes.day)}}&crdr=1&c=1"'

and the corresponding entry in the .log file. The templating is parsed correctly.

2018-12-24 19:45:57 INFO (SyncWorker_7) [homeassistant.components.sensor.command_line] Running command: curl -k --silent https://pvoutput.org/service/r2/getstatistic.jsp?key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&sid=xxxxxx&df=20181121&dt=2019220&crdr=1&c=1

Note how in the above log entry the double quotes are REMOVED around the web address casuing the command to fail.

Can anyone suggest why the quotes are being removed, or better yet, suggest what I’m doing wrong here.

:christmas_tree:TIA :christmas_tree:

i also had issues, i had to escape the quotes with a slash, see my command here :

living_on: "curl -k POST -H \"Authorization: Bearer XXX\" -d '{\"state\": \"on\",\"attributes\": {\"assumed_state\": true,\"friendly_name\": \"Living\",\"icon\": \"mdi:power-socket-eu\"}}' https://127.0.0.1:8123/api/states/switch.living_sc"

2 Likes

I appreciate the help, unfortunately escaping the quotes made no difference.

The edited sensors.yaml

command: 'curl -k --silent \"https://pvoutput.org/service/r2/getstatistic.jsp?key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&sid=xxxxx&df={{(states.input_datetime.bill_date_from.attributes.year)}}{{(states.input_datetime.bill_date_from.attributes.month)}}{{(states.input_datetime.bill_date_from.attributes.day)}}&dt={{(states.input_datetime.bill_date_to.attributes.year)}}{{(states.input_datetime.bill_date_to.attributes.month)}}{{(states.input_datetime.bill_date_to.attributes.day)}}&crdr=1&c=1\"'

The log below show quotes still missing.

2018-12-25 00:58:37 INFO (SyncWorker_7) [homeassistant.components.sensor.command_line] Running command: curl -k --silent https://pvoutput.org/service/r2/getstatistic.jsp?key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&sid=xxxxx&df=20181121&dt=2019220&crdr=1&c=1

My command start with a double quote, your a single, maybe that helps?

Actually, what doesn’t help is being tired :laughing:
What I didn’t do was refresh the .log file and wait the 600sec for the sensor to scan.

Escaping the quotes has fixed the issue. Reads correctly in the log and more importantly, the sensor returns the correct values.

Thankyou @pergola.fabio !!

Hehe, happy holidays

Hello,

I think I have the same problem but after searching for a long time I can’t get it to work.
This is the sensor that isn’t working:

  - platform: command_line
    name: AFV
    command: curl -k -sS https://FIRST_PART_URL/{{ states.input_select.afv_channel.state }}/SEC_PART_URL | awk -v RS=',' '1' | awk '{gsub(/\"|\[|\]/,"")}1' | awk '!/\_/'
    scan_interval: 15

The log:

Command failed: curl -k -sS https://FIRST_PART_URL/EBBU_CTR/SEC_PART_URL | awk -v RS=, 1 | awk {gsub(/\"|\[|\]/,"")}1 | awk !/\_/

When I create a command_line sensor without the input_select it works. Like this:

  - platform: command_line
    name: EBBU_CTR
    command: curl -k https://FIRST_PART_URL/EBBU_CTR/SEC_PART_URL | awk -v RS=',' '1' | awk '{gsub(/\"|\[|\]/,"")}1' | awk '!/\_/'
    scan_interval: 15

Any Idea?

Thx

Erik