Configuring Command Line sensor using YAML has moved. Consult the documentation to move your YAML configuration to integration key and restart Home Assistant to fix this issue

Can someone please assist. The GPU temp sensor as well as CPU Clock stopped working. Has the code changed:

command_line:
  - sensor:
      name: CPU Temp
      command: "cat /sys/class/thermal/thermal_zone0/temp"
      unit_of_measurement: "°C"
      value_template: "{{ value | multiply(0.001) | round(1) }}"
  - sensor:
      name: GPU Temp
      command: "/opt/vc/bin/vcgencmd measure_temp"
      unit_of_measurement: "°C"
      value_template: '{{ value | regex_findall_index("=([0-9]*\.[0-9]*)", 0) }}'
  - sensor:
      name: CPU Clock
      command: "/opt/vc/bin/vcgencmd measure_clock arm"
      unit_of_measurement: "MHz"
      value_template: '{{ value | regex_findall_index("=([0-9]*)", 0) | multiply(0.000001) | round(0) }}'

Thanks to everyone for the explanations on this thread. Perhaps I am obtuse, but I couldn’t make any sense digging around the docs and did not understand the error message at all. I kept searching for “integration key” with no good luck, since the message says to move to “integration key” and I was barking up the very wrong tree. The fix was relatively painless once I had a clear understanding of the issue. Again, thanks to everyone in this thread.

1 Like

Hello.
Same thing here with the same setup.
GPU Temperature and CPU Clock sensor templates fail.

Logger: homeassistant.components.command_line.utils
Source: components/command_line/utils.py:54
Integration: Command Line (documentation, issues)
First occurred: 20:24:25 (2 occurrences)
Last logged: 20:24:26

Command failed (with return code 127): /opt/vc/bin/vcgencmd measure_temp
Command failed (with return code 127): /opt/vc/bin/vcgencmd measure_clock arm
Logger: homeassistant.components.sensor
Source: helpers/template.py:1971
Integration: Sensor (documentation, issues)
First occurred: 20:24:26 (1 occurrences)
Last logged: 20:24:26

Error adding entities for domain sensor with platform command_line
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 471, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 749, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 849, in add_to_platform_finish
    await self.async_added_to_hass()
  File "/usr/src/homeassistant/homeassistant/components/command_line/sensor.py", line 139, in async_added_to_hass
    await self._update_entity_state(None)
  File "/usr/src/homeassistant/homeassistant/components/command_line/sensor.py", line 163, in _update_entity_state
    await self._async_update()
  File "/usr/src/homeassistant/homeassistant/components/command_line/sensor.py", line 193, in _async_update
    self._value_template.async_render_with_possible_json_value(
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 735, in async_render_with_possible_json_value
    return _render_with_context(self.template, compiled, **variables).strip()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2179, in _render_with_context
    return template.render(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/jinja2/environment.py", line 1301, in render
    self.environment.handle_exception()
  File "/usr/local/lib/python3.11/site-packages/jinja2/environment.py", line 936, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<template>", line 1, in top-level template code
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1971, in regex_findall_index
    return regex_findall(value, find, ignorecase)[index]
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
IndexError: list index out of range

Logger: homeassistant.components.sensor
Source: components/sensor/__init__.py:585
Integration: Sensor (documentation, issues)
First occurred: 20:24:26 (2 occurrences)
Last logged: 20:24:26

Error adding entities for domain sensor with platform command_line
Error while setting up command_line platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 583, in state
    numerical_value = float(value)  # type:ignore[arg-type]
                      ^^^^^^^^^^^^
ValueError: could not convert string to float: 'None'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 471, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 749, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 849, in add_to_platform_finish
    await self.async_added_to_hass()
  File "/usr/src/homeassistant/homeassistant/components/command_line/sensor.py", line 139, in async_added_to_hass
    await self._update_entity_state(None)
  File "/usr/src/homeassistant/homeassistant/components/command_line/sensor.py", line 163, in _update_entity_state
    await self._async_update()
  File "/usr/src/homeassistant/homeassistant/components/command_line/sensor.py", line 201, in _async_update
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 590, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 654, in _async_write_ha_state
    state = self._stringify_state(available)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 596, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 585, in state
    raise ValueError(
ValueError: Sensor sensor.gpu_temperature has device class 'None', state class 'None' unit '°C' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: 'None' (<class 'str'>)

Regards!!!

This is also bothering me about Home Assistant…
Something is running and working for years, and suddenly you have to re-arange and change everything you’ve collected during the years.

This is not editing just 3 lines annymore.

And in the meanwhile I went from few clear files where everything was aranged that belonged together to a file database with all different shortcuts and references.
I’m beginning to hate updating HASS…

And there’s no much of information found in the warning itself considering the problem.
“we’re going to change and break functionalities, good luck finding out and repairing it”

5 Likes

The size of this thread alone suggests that “big hints” weren’t really enough.

Lets face it, not everyone reads the release notes and/or breaking change list. It’s also very easy to miss a part that calls out something that may impact you. This change in particular even states “this is currently not yet a breaking change” and although I agree nothing has actually broken yet, the warning message that appears in the UI after the update could certainly make it a lot clearer as to what it’s referring to.

Why not include a link to the relevant section of the release notes as an obvious starting point, instead of just “consult the documentation”?

6 Likes

Wanted to share my 2 cents on the command-line sensor migration, especially for people who have integrated Grafana into Lovelace.

The only reliably way I found integrating Grafana dashboards into Lovelace is by doing a command line curl to an image render of the dashboard, and then using the image in a camera. Why not embed the iframe you might ask, the problem is the headers that I use for authentication, that I can’t pass along in the url.

sensor:
  - platform: command_line
    name: "Download Temperature"
    command: curl -s -H "Authorization:Bearer ##AuthToken##" "http://##IP##:4000/render/d-solo/iM3nzjKnz/home?orgId=1&panelId=2&from=now-6h&to=now&width=500&height=250&tz=Europe%2FAmsterdam" > /config/downloads/temperature.tmp && cp /config/downloads/temperature.tmp /config/downloads/temperature.png
    scan_interval: 300
camera:
  - platform: local_file
    name: Grafana Temperature
    file_path: /config/downloads/temperature.png

Looking at the guide, I came up with the below, which seemed to have worked but didn’t…

command_line:
  - binary_sensor:
      name: "Download Temperature"
      command: 'curl -s -H "Authorization:Bearer ##AuthToken##" "http://##IP##:4000/render/d-solo/iM3nzjKnz/home?orgId=1&panelId=2&from=now-6h&to=now&width=500&height=250&tz=Europe%2FAmsterdam" > /config/downloads/temperature.tmp && cp /config/downloads/temperature.tmp /config/downloads/temperature.png'
      scan_interval: 300

While the curl part succeeds, the copy part after the && was failing (for all but the first in line).
image

I tried a few things and what worked was adding the command_timeout:

  - binary_sensor:
      name: "Download Temperature"
      command: 'curl -s -H "Authorization:Bearer ##Token##" "http://##IP##:4000/render/d-solo/iM3nzjKnz/home?orgId=1&panelId=2&from=now-6h&to=now&width=500&height=250&tz=Europe%2FAmsterdam" > /config/downloads/temperature.tmp && cp /config/downloads/temperature.tmp /config/downloads/temperature.png'
      command_timeout: 150
      scan_interval: 300

One downside I seem to observe is that, all commands are executed at the same time, instead of what I recall being staggered one after another. Given the rendering of the graphs are CPU heavy and takes a few seconds, calling multiples of them might choke the system a bit. Will keep a close eye.

check indentation

I am struggling with this for some reason. I added the command_line: !include command_line.yaml to my configuration.yaml file and then created the comman_line.yaml with the following contents but I am getting a error.

Logger: homeassistant.setup
Source: setup.py:252
First occurred: 12:55:08 AM (1 occurrences)
Last logged: 12:55:08 AM

Setup failed for command_line: No setup or config entry setup function defined.

contents of configuration.yaml:

# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

# Text to speech
tts:
  - platform: google_translate

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
binary_sensor: !include binary_sensor.yaml
command_line: !include command_line.yaml

# Raspberry Pi output
switch:
  - platform: rpi_gpio
    switches:
      - port: 26
        name: "Ducted Heating Control 26"
        unique_id: "ducted_heating_control_rpgio_26"

and the contents of the command_line.yaml

                                                              
- sensor:
    name: "CPU Temp"
    command: "cat /sys/class/thermal/thermal_zone0/temp"
    unit_of_measurement: "°C"
    value_template: '{{ value | multiply(0.001) | round(2) }}'

Not sure what I am doing wrong? FYI I want to expand this later to ssh to another Pi to get its CPU temp.

Try:

- sensor:
    name: CPU Temp
    command: cat /sys/class/thermal/thermal_zone0/temp
    unit_of_measurement: "°C"
    value_template: "{{ value | multiply(0.001) | round(2) }}"

This is what I use in config:

command_line:
  - sensor:
      name: CPU Temperature
      command: cat /sys/class/thermal/thermal_zone2/temp
      unit_of_measurement: "°C"
      value_template: "{{ value | multiply(0.001) | round(2) }}"

No bueno, I even commented out the include command_line and plonked it straight into the configuration.yaml file but I still get the same error. Contents now in configuration.yaml:

# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

# Text to speech
tts:
  - platform: google_translate

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
binary_sensor: !include binary_sensor.yaml
#command_line: !include command_line.yaml

command_line:
  - sensor:
      name: CPU Temperature
      command: cat /sys/class/thermal/thermal_zone2/temp
      unit_of_measurement: "°C"
      value_template: "{{ value | multiply(0.001) | round(2) }}"

# Raspberry Pi output
switch:
  - platform: rpi_gpio
    switches:
      - port: 26
        name: "Ducted Heating Control 26"
        unique_id: "ducted_heating_control_rpgio_26"

Did you restart Home Assistant after making the changes or just attempt to reload YAML?

A restart is required.

Also what version of Home Assistant core are you on?

Running in Docker. I did the restart (not just reload YAML, I have issues with just doing that from before so I always do a restart now) from inside the UI but as another check I also restarted the PI. Same issue. I can run the command no problems from inside the docker.

Version: Home Assistant 2023.5.4
Frontend 20230503.3 - latest

The command_line integration update was released in v 2023.6

Worked. Thanks Tom.

what is the format if you have command line sensors but they are in the packages folder in command_line.yaml

command_line:
  - sensor:
      scan_interval: 5
      name: Enclosure Temperature
      command: "curl 'http://192.168.1.146/plugin/enclosure/inputs/1?apikey=******'"
      unit_of_measurement: "°C"
      value_template: "{{value_json['temp_sensor_temp'] }}"

  - sensor:
      scan_interval: 5
      name: Enclosure Humidity
      command: "curl 'http://192.168.1.146/plugin/enclosure/inputs/1?apikey=******'"
      unit_of_measurement: "°C"
      value_template: "{{value_json['temp_sensor_humidity'] }}"

This doesnt work.

I still could not come up with a solution to this error. In my configuration.yaml I have a list like this:

template:
  - sensor:
      - name: "TV Power Consumption"
        unit_of_measurement: 'kW'
        state: >
          {{ (states("sensor.tv_energy")) | float / 10000 | round(5) }}       
        device_class: power

and

sensor:
  - platform: integration
    name: TV Energy Consumption
    source: sensor.tv_power_consumption
    method: left

I tried moving these to command_line.yaml without any luck. With the platform I get an error saying that platform is not supported, while for the template I get a generic error.

Neither of those are using the command_line sensor platform. They do not need to be moved.

Only things that include:

  - platform: command_line

need to be changed.

Not template, not Riemann sum, nothing other than command_line integrations.

1 Like

/Flame ON
I just don’t get why anyone thinks “hints” are documentation.

This thread is evidence of a disaster.
The “error” message needs
a) To be much clearer about what has changed
b) To provide a link (short bit.ly link or similar if required) to clear documentation
c) Of What has changed and how to migration from was to what should

Writing code is not doing the job. The job is only done when it is clearly documented and the users can find the documentation.

I hand wrote all my YAML, but I don’t work in HA from one month to the next.
I’m having to wade though this discussion, to try and understand what has changed because hints are not enough. Link to clear documentation required.
/Off

3 Likes

You are right. I thought the warning was really cryptic. “Command Line YAML configuration has moved” doesn’t mean anything to me. I thought that some YAML had been moved elsewhere. The “…move your YAML configuration to integration key…” is mystifying in the extreme. What does that even mean?

I don’t think this was well handled.

lol “big hints”.
Stuff like this is why I can’t recommend HA to my friends. I don’t want them to hate me.