Command Line YAML configuration has moved error

Since I upgraded last I have the following message regarding a change to how command line switch entities are done, however I cant seem to find documentation of the new way to define them. They still work, presumably in future they won’t .This is the error:

Command Line YAML configuration has moved
This stops working in version 2023.8.0. Please address before upgrading.
Configuring Command Line `switch` using YAML has moved.
Consult the documentation to move your YAML configuration to integration key and restart Home Assistant to fix this issue.

I tried moving the switches to a separate switches.yaml, but this does not help. Here is an example of my config that triggers the new error:

switch 1:
  - platform: command line 
    switches:
    motionstatefrontgarden:
    friendly_name: 'Front Garden Camera Motion Detection'
    command_on: 'curl --user admin: -d "chkmove deton....." 
    command off: 'curl --user admin: -d "chkmove deton....."
    command state: 'curl --user admin: -d "chkmove detstate......"
    value template: '{{value == "1" }}'

Anyone got an idea how the new formatting works?

Version:

Home Assistant 2023.6.0b4
Supervisor 2023.06.0
Operating System 10.2

Thanks

4 Likes

Here’s a link to the 2023.6.0 beta version of the documentation for the Command Line integration.

Release Candidate - Command Line

The new configuration format for a switch will be like this:

The main difference is that any entity related to the Command Line integration will now be defined under the command_line: key.

7 Likes

Hi Taras,

Thanks for that, the warning error has disappeared now. Only problem is, one switch seems to work on its own, but If I add any more of them, only the last switch in the configuration shows up in homeassistant, is there a separator I’m missing, I’ve tried both of the below and I get the same behaviour:

I had added the -switch: separator for multiple entities, but not done a full restart, only a reload. Below works perfectly now for multiple switches.

command line:  
  - switch:
    name: motionstatefrontgarden:
    command_on: 'curl --user admin: -d "chkmove deton..." 
    command off: 'curl --user admin: -d "chkmove deton..."
    command state: 'curl --user admin: -d "chkmove detstate..."
    value template: '{{value == "1" }}'

  - switch:
    name: motionstatebackgarden:
    command_on: 'curl --user admin: -d "chkmove deton..." 
    command off: 'curl --user admin: -d "chkmove deton..."
    command state: 'curl --user admin: -d "chkmove detstate..."
    value template: '{{value == "1" }}'

Thanks Again

1 Like

I’m getting a similar issue:

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 help ?

The solution is already in this post :slightly_smiling_face:

You can also read more about it here and see an example, under “Command line”:

I read the documentation and made the changes based on how I read it. But, it did not work for me. Below is the YAML code I ended up with. I had to comment out the CPU Temp code to get it to say a restart would be OK. Can anyone help me get the right YAML code?

sensor:
  - platform: systemmonitor
    resources:
      - type: processor_use
      #- type: processor_temperature # Does not work
      - type: memory_free
      - type: disk_use_percent
        arg: /
      - type: disk_use
      - type: disk_free
      - type: throughput_network_in
        arg: enp1s0
      - type: throughput_network_out
        arg: enp1s0
  # CPU Temp
#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(2)  }}'

Same problem here.

The system cannot restart because the configuration is not valid: Invalid config for [switch]: required key not provided @ data[‘platform’]. Got None. (See /config/configuration.yaml, line 11).

switch.yaml:

  command_line:

# Interruptores relays en comedor
    - switch:
        command_on: ./gpio/gpio01 && touch /config/pin/1
        command_off: ./gpio/gpio00 && rm /config/pin/1
        command_state: cat /config/pin/1
        name: Velador comedor

    - switch:        
        command_on: ./gpio/gpio11 && touch /config/pin/2
        command_off: ./gpio/gpio10 && rm /config/pin/2
        command_state: cat /config/pin/2
        name: Bar

configuration.yaml:


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

# Text to speech
tts:
  - platform: google_translate

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
switch: !include switch.yaml

stream:

1 Like

I’m getting the same.
From how I read it, the documentation is written if the sensor/switch/cover is in the configuration.yaml, but it doesn’t have an example of the formatting if it’s called in it’s own file.

configuration.yaml:

.....
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
sensor: !include sensors.yaml
binary_sensor: !include binary_sensors.yaml
template: !include templates.yaml
homeassistant: !include customize.yaml

sensors.yaml

- platform: 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(2)  }}"

error reported via Developer Tools validaton:

Invalid config for [sensor.command_line]:
[sensor] is an invalid option for [sensor.command_line].
Check: sensor.command_line->sensor. (See ?, line ?)
  • Addendum
    Moving it to configuration.yaml in the following format fixed it for now.
    Would still like to move it back to sensors.yaml at some point to keep it all in order.
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(2)  }}"
4 Likes

I’m getting the same error, but in switch.yaml. I want to keep everything in switch.yaml, not having to move it into configuration.yaml.

2 Likes

I think we are going to have to have a command_line.yaml. But I am not sure how this works with sensors.

I tried the YAML above and get the following 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_zone0/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(2) }}'. (See /config/configuration.yaml, line 36).

Can I put all sensors under the command_line? Even if they do not have command lines?

Not possible.

All entities based on the Command Line integration must now be defined under the new command_line: key.

If you wish, you can create a separate file containing the configurations of all Command Line entities.

Not working here.

I solved my issue. When I copied the YAML to the new structure I had the indentation wrong. Even worse I kept typing it that way. I just fixed the indentation and it works.

1 Like

What is the correct format for MQTT sensors, like this

command_line:
   mqtt:
       sensor:
           - name: "Garage Temp Sensor"
              state_topic: "garage/sensor/temperature"
              unit_of_measurement: "°C"
              device_class: "temperature"
1 Like

While various solutions have been mentioned, I would like to present mine.

I changed the following configuration.yaml line:

switch: !include switches.yaml

into:

command_line: !include command_line.yaml

and removing the old switches.yaml file for now.

The content of the new command_line.yaml is as followed:

- switch:
    unique_id: tuinverlichting_gevel
    name: Tuinverlichting Gevel
    command_on: <REDACTED>
    command_off: <REDACTED>
- switch:
    unique_id: tuinverlichting_overkapping
    name: Tuinverlichting Overkapping
    command_on: <REDACTED>
    command_off: <REDACTED>

Took me a few goes this morning too, but for reference:

configuration.yaml:

command_line: !include devices/command_line.yaml

devices/command_line.yaml:

- sensor:
    name: Bin Days
    command: "python3  blah blah blah"
    scan_interval : 315360000
    command_timeout: 600
    # device_class: timestamp
    value_template: > 
     {{ now() }}
    json_attributes:
     - nextbintype
     - nextbindate
     - black
     - green
     - brown
     - next_black
     - next_green
     - next_brown

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

As always, fussy about indentation and use of “arrays” (or not, in this case)

3 Likes

I have multiple switch entities (switch.http_tasmota_switch1, etc.)

switch.yaml

  - platform: command_line
    switches:
      http_tasmota_switch1:
        command_on:  /usr/bin/curl -s -m 5 -X POST 'http://192.168.0.51/cm?cmnd=Power%20On'
        command_off: /usr/bin/curl -s -m 5 -X POST 'http://192.168.0.51/cm?cmnd=Power%20Off'
        command_state: /usr/bin/curl -s -m 5 -X GET  'http://192.168.0.51/cm?cmnd=Power' || echo -n {\"POWER\":\"OFF\"}
        value_template: '{{value_json.POWER == "ON" }}'
        friendly_name: "Http_Tasmota 1"

image

I added in configuration.yaml

command_line: !include command_line.yaml

Created command_line.yaml and modified formatting

- switch:
    http_tasmota_switch1:
    command_on: /usr/bin/curl -s -m 5 -X POST 'http://192.168.0.52/cm?cmnd=Power%20On'
    command_off: /usr/bin/curl -s -m 5 -X POST 'http://192.168.0.52/cm?cmnd=Power%20Off'
    command_state: /usr/bin/curl -s -m 5 -X GET  'http://192.168.0.52/cm?cmnd=Power' || echo -n {\"POWER\":\"OFF\"}
    value_template: '{{value_json.POWER == "ON" }}'
    friendly_name: "Http_Tasmota 1"

I’m still getting the error

Configuration invalid!
Invalid config for [command_line]: [http_tasmota_switch1] is an invalid option for [command_line]. Check: command_line->command_line->0->switch->http_tasmota_switch1.

Any suggestions…

where you have http_tasmota_switch
change to
name: http_tasmota_switch1

1 Like

Already done. The issue now is with http_tasmota_switch1 as it is a invalid option for command_line. This all worked perfectly before in switch.yaml.

Invalid config for [command_line]: [http_tasmota_switch1] is an invalid option for [command_line]. Check: command_line->command_line->0->switch->http_tasmota_switch1.```