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

No.

The template sensor and command line sensor integrations are two unrelated things and there is no need to convert from one to the other. You do not need to do this.

1 Like

Thank you. I’m not working with home assistant on a daily basis and since I got a message that sensors had to be transferred to command_line I wanted to convert these too :grinning_face_with_smiling_eyes: :grinning_face_with_smiling_eyes:

My two cents here. The solutions mentioned earlier are correct, but difficult to implement for people that are not experts in the YAML setup.

So I had this in my configuration.yaml:


group: !include groups.yaml
template: !include templates.yaml
input_boolean: !include inputs.yaml
automation: !include automations.yaml
influxdb: !include influxdb.yaml
sensor: !include sensors.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

and in my sensors.yaml I had this:

#
# CPU Temperatuur
#
- platform: command_line
  name: CPU Temperature
  command: "cat /sys/class/thermal/thermal_zone0/temp"
  unit_of_measurement: "°C"
  value_template: "{{ value | multiply(0.001) | round(1) }}"


  #
  # CPU Bezetting
  #
- platform: command_line
  name: CPU Load
  command: "top -n1 | awk '/Cpu\\(s\\):/{print $2}'"
  unit_of_measurement: "%"
  value_template: "{{ value | multiply(1) | round(1) }}"

This was the code that will be deprecated in August.

Here’s what I did:
in configuraion.yaml I added one line at the bottom:

command_line: !include cmdline.yaml

then I added a new file called cmdline.yaml that contained:

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

  #
  # CPU Bezetting
  #
- sensor:
    name: CPU Load
    command: "top -n1 | awk '/Cpu\\(s\\):/{print $2}'"
    unit_of_measurement: "%"
    value_template: "{{ value | multiply(1) | round(1) }}"

That’s all, check yaml, the restart Home Assistant and it works!
Hope this helps! :slight_smile:

4 Likes

This is easy enough to “fix” but the requirement of this change is fabulously asinine. “Sensor” is a fundamental domain to the structure of Home Assistant. “Command_Line” has never been. It’s just a platform to create sensor.

Everyone with any sort of meaningful tree structure to their yaml now will be needing to put a sensor in their base config.yaml OR make a new file called something like command_line.yaml.

Can you write alternative for this sensors?

- platform: template
  sensors:
    count_lights_on:
      friendly_name: "# Lights on"
      unit_of_measurement: "on"
      value_template: "{{ states.light | selectattr('state', 'eq', 'on') | list | count }}"

- platform: template
  sensors:
    count_all_devices:
      friendly_name: "# All devices"
      value_template: "{{ states | list | count }}"

Again, no. They are not command line sensors.

Only command line sensors (platform: command_line ) need to be updated.

I actually agree on the ‘why’

I’ve a splitt’ed config in order to group stuff, and now my sensors and switches all over the place again :thinking:

Yes, this is the problem of an ever developing environment. Something is getting deprecated every now and than which creates unnecessary trouble and kills a lot of time to fix. HA developers should consider creating a migration tool that can make all this upgrading process lot easier… Otherwise things are getting frustrating with every update and are forcing me to quit HA.

1 Like

Has something changed with Python 3.11 regarding commands?
This does not get any data anymore under 2023.6:

command_line:
  - sensor:
      command: python3 -c "import requests; print(requests.get('http://xxx/file').text)"
      name: sensorname
      scan_interval: 600
      json_attributes:
        - attr1   
        - attr2
        - attr3
        - attr4

Or do I have to point that the file is json?

.json()['info']['data'])

It reads once after reboot and then nothing…
Best, JR

@tom_l this has helped clarifying for me as wel… Yet still I get this error on start-up, while my configuration.yaml does not have a command line item (command: …) and (as far as I could see) also none of the files in the !include (see screenshot below).
Would you know where I could further look into to avoid the error message?

Screenshot 2023-06-11 at 14.06.46

You are looking for - platform: command_line that is what needs replacing.

that helped! I checked again the !include .yaml files and found one more - platform: command_line and updated that. Now error message is gone at HA restart.
Appreciate your patience in this thread!

I completely agree. I have hundreds of command line sensors. I will die of old age before I convert everything.

Can you be a little more specific ?
I have my sensors defined in configuration.yaml with - platform : command_line already, but still get the warning message.
What exactly should I do?

Thank you in advance!

Then you need to change them to the format shown in the example here: Command Line - Home Assistant

# Example configuration.yaml entry
command_line:
  - sensor:
      command: SENSOR_COMMAND
  - sensor:
      command_2: SENSOR_COMMAND
  - sensor:
      another_command: SENSOR_COMMAND

Indeed.

I get that the devs will find better ways of doing things or need to re-arrange code as time goes by, which inevitably leads to deprecations, but is it really too much to ask to even just provide a link to the relevant documentation when the error appears?

“Consult the documentation to move your YAML configuration to integration key and restart Home Assistant to fix this issue.” tells me almost nothing about what’s actually needed to resolve the problem. A migration tool may not be easy to code as everyone will have their own way of organising their config YAML but a direct link to the docs explaining the change, with some worked examples of what’s needed to fix it, shouldn’t be difficult.

4 Likes

There are some big hints:

image

Not to mention the breaking changes in the release notes which you should read before updating.

A link to the docs would be nice though.

1 Like

Tried like this, configuration file says is OK, but when I want to restart HA I get faults about another utility_matter.
It is better to make these command sensors in another file and just to include it ?

It’s personal preference. Splitting the config can help you keep things organised if you have a lot of command line entities.

Sounds like you may have a configuration issue. Show your config from command_line: to and including utility_meter:

I’ve sent you my conf file in an message