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

Getting this error after upgrade:

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.

This is my sensors.yaml:

  • platform: template
    sensors:
    battery_level:
    friendly_name: Battery Level
    value_template: >-
    {% set batterylevel = (states(‘sensor.solaredge_battery1_state_of_charge’)|float +
    states(‘sensor.solaredge_battery2_state_of_charge’)|float) / 2 %}
    {{ ‘{:.1f}’.format(batterylevel) }}
    unit_of_measurement: “%”

    battery_power:
    friendly_name: Battery Power Total
    value_template: >-
    {% set batterypower = (states(‘sensor.solaredge_battery1_power’)|float +
    states(‘sensor.solaredge_battery2_power’)|float) %}
    {{ ‘{:.0f}’.format(batterypower) }}
    unit_of_measurement: “W”

    battery_power_negative:
    friendly_name: Battery Negative
    value_template: >-
    {% set batterypowerneg = -1 * (states(‘sensor.solaredge_battery1_power’)|float +
    states(‘sensor.solaredge_battery2_power’)|float) |float(0) %}
    {{ ‘{:.0f}’.format(batterypowerneg) }}
    unit_of_measurement: “W”

    grid_power_negative:
    friendly_name: Grid Negative
    value_template: >-
    {% set gridneg = -1 * states(‘sensor.solaredge_m1_ac_power’) |float(0) %}
    {{ ‘{:.0f}’.format(gridneg) }}
    unit_of_measurement: “W”

    total_power:
    friendly_name: Solar Generation
    value_template: >-
    {% if states(‘sensor.solaredge_battery1_status’) == ‘Discharging’ %}
    {% set totalpower = ((states(‘sensor.solaredge_battery1_power’)|float +
    states(‘sensor.solaredge_battery2_power’)|float) + states(‘sensor.solaredge_dc_power’)|float) %}
    {{ ‘{:.1f}’.format(totalpower) }}
    {% else %}
    {% set totalpower = (states(‘sensor.solaredge_battery1_power’)|float +
    states(‘sensor.solaredge_battery2_power’)|float + states(‘sensor.solaredge_dc_power’)|float) %}
    {{ ‘{:.1f}’.format(totalpower) }}
    {% endif %}
    unit_of_measurement: “W”

    house_cons:
    friendly_name: House Consumption
    value_template: >-
    {% if states(‘sensor.solaredge_m1_ac_power’)|float > 1 %}
    {% set housecons = states(‘sensor.solaredge_ac_power’)|float -
    states(‘sensor.solaredge_m1_ac_power’)|float %}
    {{ ‘{:.0f}’.format(housecons) }}
    {% else %}
    {% set housecons = states(‘sensor.solaredge_ac_power’)|float %}
    {{ ‘{:.0f}’.format(housecons) }}
    {% endif %}
    unit_of_measurement: “W”

    energy_grid_import:
    friendly_name: Grid Import Energy Sensor
    value_template: >-
    {% if states(‘sensor.solaredge_m1_ac_power’)|float < 0 %}
    {% set energygridimport = states(‘sensor.solaredge_m1_ac_power’)|float |abs %}
    {{ ‘{:.1f}’.format(energygridimport) }}
    {% else %}
    {% set energygridimport = 0 %}
    {{ ‘{:.1f}’.format(energygridimport) }}
    {% endif %}
    unit_of_measurement: “W”

    energy_grid_import_new:
    friendly_name: Grid Import Energy Sensor New
    value_template: >-
    {% if states(‘sensor.solaredge_m1_ac_power’)|float > 0 %}
    {% set energygridimportnew = 0 %}
    {{ ‘{:.1f}’.format(energygridimportnew) }}
    {% else %}
    {% set energygridimportnew = states(‘sensor.solaredge_m1_ac_power’)|float |abs %}
    {{ ‘{:.1f}’.format(energygridimportnew) }}
    {% endif %}
    unit_of_measurement: “W”

    energy_grid_export:
    friendly_name: Grid Export Energy Sensor
    value_template: >-
    {% if states(‘sensor.solaredge_m1_ac_power’)|float > 0 %}
    {% set energygridexport = states(‘sensor.solaredge_m1_ac_power’)|float %}
    {{ ‘{:.1f}’.format(energygridexport) }}
    {% else %}
    {% set energygridexport = 0 %}
    {{ ‘{:.1f}’.format(energygridexport) }}
    {% endif %}
    unit_of_measurement: “W”

    energy_grid_export_new:
    friendly_name: Grid Export Energy Sensor
    value_template: >-
    {% if states(‘sensor.solaredge_m1_ac_power’)|float > 0 %}
    {% set energygridexportnew = states(‘sensor.solaredge_m1_ac_power’)|float %}
    {{ ‘{:.1f}’.format(energygridexportnew) }}
    {% else %}
    {% set energygridexportnew = 0 %}
    {{ ‘{:.1f}’.format(energygridexportnew) }}
    {% endif %}
    unit_of_measurement: “W”

    energy_battery_charge:
    friendly_name: Battery Charge
    value_template: >-
    {% if states(‘sensor.battery_power’)|float > 0 %}
    {% set batterycharge = states(‘sensor.battery_power’)|float %}
    {{ ‘{:.1f}’.format(batterycharge) }}
    {% else %}
    {% set batterycharge = 0 %}
    {{ ‘{:.1f}’.format(batterycharge) }}
    {% endif %}
    unit_of_measurement: “W”

    energy_battery_discharge:
    friendly_name: Battery Discharge
    value_template: >-
    {% if states(‘sensor.battery_power’)|float < 0 %}
    {% set batterydischarge = states(‘sensor.battery_power’)|float |abs %}
    {{ ‘{:.1f}’.format(batterydischarge) }}
    {% else %}
    {% set batterydischarge = 0 %}
    {{ ‘{:.1f}’.format(batterydischarge) }}
    {% endif %}
    unit_of_measurement: “W”

  • 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(2) }}’

Would greatly appreciate any help to get it working am quite new to HA.

1 Like

I believe that the command line sensor may be tripping you up here.

I think it should now be:

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

See here for updated layout: https://www.home-assistant.io/integrations/command_line/#cpu-temperature

7 Likes

this has me stumped as well - I have the following in my sensors.yaml, which I think per the documentation is correct? Yet I’m getting the same error as Jas is

- 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) }}'

- platform: template
  sensors:
    disk_total:
      value_template: "{{ ( states('sensor.disk_use')|float + states('sensor.disk_free')|float )| round (1) }}"

- platform: command_line
  name: Host Operating System
  command: 'curl http://supervisor/host/info -H "Authorization: Bearer $(printenv SUPERVISOR_TOKEN)" | jq ''.data.operating_system'' | sed ''s/"//g'''

- platform: command_line
  name: Supervisor Updates
  command: 'curl http://supervisor/supervisor/info -H "Authorization: Bearer $(printenv SUPERVISOR_TOKEN)" | jq ''{"newest_version":.data.version_latest,"current_version":.data.version,"update_available":.data.update_available,"addons":[.data.addons[] | select(.update_available)]}'''
  value_template: "{{ value_json.addons | length }}"
  unit_of_measurement: pending update(s)
  json_attributes:
  - update_available
  - newest_version
  - current_version
  - addons

Same here. This is in my sensor.yaml file:

# update the lastest ABC News Podcast
- platform: command_line
  name: Latest ABC News Bulletin
  scan_interval: 3600 # Every hour
  command: curl -k -s https://www.abc.net.au/feeds/101858056/podcast.xml | grep -E -o 'https?://[^"]+mp3' | uniq | head -n 1

Maybe I need quotes around the command: element.

No that is not correct. You have to move all your command line sensors.

configuration.yaml

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

  - sensor:
      name: Host Operating System
      command: 'curl http://supervisor/host/info -H "Authorization: Bearer $(printenv SUPERVISOR_TOKEN)" | jq ''.data.operating_system'' | sed ''s/"//g'''

  - sensor:
      name: Supervisor Updates
      command: 'curl http://supervisor/supervisor/info -H "Authorization: Bearer $(printenv SUPERVISOR_TOKEN)" | jq ''{"newest_version":.data.version_latest,"current_version":.data.version,"update_available":.data.update_available,"addons":[.data.addons[] | select(.update_available)]}'''
      value_template: "{{ value_json.addons | length }}"
      unit_of_measurement: pending update(s)
      json_attributes:
        - update_available
        - newest_version
        - current_version
        - addons

You can use an include if you want. e.g.

command_line: !include command_line.yaml

Then everything above, except the first line “command_line:” goes in command_line.yaml instead of configuration.yaml

Note: you no longer need that last sensor. It is all provided by the supervisor integration.

16 Likes

I am getting same thing as OP. When i tried creating a command_line.yaml and add it to the config yaml i get this error

Configuration invalid!

Invalid config for [command_line]: expected a dictionary for dictionary value @ data[‘command_line’][0][‘sensor’]. Got None extra keys not allowed @ data[‘command_line’][0][‘command’]. Got ‘cat /sys/class/thermal/thermal_zone2/temp’ extra keys not allowed @ data[‘command_line’][0][‘name’]. Got ‘CPU Temp’ extra keys not allowed @ data[‘command_line’][0][‘unit_of_measurement’]. Got ‘°C’ extra keys not allowed @ data[‘command_line’][0][‘value_template’]. Got ‘{{ value | multiply(0.001) | round(1) }}’. (See /config/configuration.yaml, line 19).

if i add the command back into my sensors.yaml atm it all works fine still…

1 Like

samo samo with my configurations…

extra keys not allowed @ data['command_line'][0]['command']. Got 'cat /sys/class/thermal/thermal_zone0/temp'
extra keys not allowed @ data['command_line'][0]['name']. Got 'CPU Temperature'
extra keys not allowed @ data['command_line'][0]['unit_of_measurement']. Got '°C'
extra keys not allowed @ data['command_line'][0]['value_template']. Got '{{ value | multiply(0.001) | round(1) }}'. (See /config/configuration.yaml, line 220).

The command line syntax describes that you should use prover indentation. In the cpu example for instance move every line after sensor 2 spaces to the right

2 Likes

Thanks I updated my post.

1 Like

awesome that did it… thanks

yeap it worked, I only put 2 more spaces after sensor line and it worked.

I have a question.

I have the sensors in a yaml file in the packages folder still written with the old format.

Do I need to move them to a dedicated file like the example one (command_line.yaml)?
or is it enough to rewrite them in the modern format?

eg.

# my old format
sensor:
  - platform: command_line
    name: Supervisor updates
    command: 'curl http://supervisor/supervisor/info -H "Authorization: Bearer $(printenv ............
    etc....

# on new format 
command_line:
  - sensor:
      name: Supervisor updates
      command: 'curl http://supervisor/supervisor/info -H "Authorization: Bearer $(printenv ............
      etc.....
3 Likes

Should be enough to rewrite them as you have done in your example. However… I don’t know if anyone tested packages during the beta trial. Let us know how it goes.

1 Like

if I tried earlier I would have saved a question, however yes with the new format everything works even in the packages.

you always learn something.

1 Like

Sorry but I am confused…

I moved the (still working) following code from “configuration.yaml” (this morning aftet the update I was getting the warning about new format):

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

to this new code into the new created file “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)  }}'

but the CPU temp sensor doesn’t work anymore…

What’s wrong?

Can anyone help me with converting my sensors into the right format

- platform: template
  sensors:
      persons_at_home:
        friendly_name: 'People At Home'
        value_template: >
          {{states.person|selectattr('state', '==', 'home')|list|count}}
- platform: template
  sensors:
      radiators_on:
        friendly_name: 'Radiators On'
        value_template: >
          {{ [states.input_boolean.master_bedroom_radiator, states.input_boolean.office_radiator, states.input_boolean.living_room_radiator, states.input_boolean.kitchen_radiator, states.input_boolean.dinning_room_radiator]| selectattr('state', '==', 'on') | list | count }}

Why does everything have to change all the time?
You have invested a lot of time to arrange certain things well and thoughtfully and then you can reinvent everything again

14 Likes

thanks Tom - worked like a charm :slight_smile:

try this for the temp sensor in command_line.yaml

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

Thanks… will try soon

But… should i put the 1st line (command_line) or not?

# on new format

command_line:   <- this one???
  - sensor:
 xxxxxxx