Trouble getting command_line to work

I am having trouble getting parsehub data into my HASS. I am scraping a website to get ocean water temp and have it successfully working in a browser using https://parsehub.com/api/v2/projects/ttFdME593WaD/last_ready_run/data?api_key=txYdHrLFC30h but cannot get it to work in HASS using command_line. Instead I get this error:
<Command failed (with return code 127): Curl -X GET “https://parsehub.com/api/v2/projects/ttFdME593WaD/last_ready_run/data?api_key=txYdHrLFC30h”>
any clues - I am sure it is something simple!

The curl command is lowercase.

thank you - I gave that a try and am now getting all this - hopefully an improvement!
`Logger: homeassistant.components.sensor
Source: helpers/entity_platform.py:599
integration: Sensor (documentation, issues)
First occurred: 06:27:16 (1 occurrences)
Last logged: 06:27:16

Error adding entity sensor.command_sensor for domain sensor with platform command_line
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/helpers/entity_platform.py”, line 599, in _async_add_entities
await coro
File “/usr/src/homeassistant/homeassistant/helpers/entity_platform.py”, line 918, in _async_add_entity
await entity.add_to_platform_finish()
File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 1367, in add_to_platform_finish
await self.async_added_to_hass()
File “/usr/src/homeassistant/homeassistant/components/command_line/sensor.py”, line 117, in async_added_to_hass
await self._update_entity_state()
File “/usr/src/homeassistant/homeassistant/components/command_line/sensor.py”, line 142, in _update_entity_state
await self._async_update()
File “/usr/src/homeassistant/homeassistant/components/command_line/sensor.py”, line 146, in _async_update
await self.data.async_update()
File “/usr/src/homeassistant/homeassistant/components/command_line/sensor.py”, line 248, in async_update
self.value = await async_check_output_or_log(command, self.timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/homeassistant/homeassistant/components/command_line/utils.py”, line 60, in async_check_output_or_log
return stdout.strip().decode(“utf-8”)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0x8b in position 1: invalid start byte`

Suggest to post a code for this command_line sensor.
Please follow rules for posting a code - place a code into triple backquotes.

command_line:
  - sensor:
      command: 'curl -X GET "https://parsehub.com/api/v2/projects/ttFdME593WaD/last_ready_run/data?api_key=txYdHrLFC30h" '
      name: surf_scrape
      unique_id: 8c080969-5c7f-4a60-216083f7f3a9
#      json_attributes
#          - selection1
#          - selection2
#          - selection3
#      value_template: "{{ value_json.surf }}"
      scan_interval: 60000
#      command_timeout: 120

note that I have disabled a number of settings which are deemed to be optional in an attempt to get it to work.

Have you tried calling this command manually?

it works in a browser. Is that what you mean?

No, I meant calling the command in cli

sorry cli?

console, command line, …
image
Ofc it is supposed to be ran in the OS where your HA is running (debian, hassos, …).

Your api call returns compressed data by default, not something that can be handled by HA.

use --compress for curl to unzip the response

curl --compressed "https://parsehub.com/api/v2/projects/ttFdME593WaD/last_ready_run/data?api_key=txYdHrLFC30h"

thank you - that was the problem - now working

regards

If you mark his answer as the solution it could help to more people

I have done that - thank you for telling me.

1 Like