Command line yaml configuration has moved (what to do)

HI All,

After latest update (core 2023.6), I get a warning that command line yaml config has moved.
I’m talking about this part:

But, I don’t quite get it what I need to change ? I have below at the moment:

  - platform: command_line
    switches:
      sprinklers_middenvoor:
        command_on: "/usr/bin/curl -X GET 'http://192.168.0.4/io.cgi?DOA1=0'"
        command_off: "/usr/bin/curl -X GET 'http://192.168.0.4/io.cgi?DOI1=0'"
        command_state: "/usr/bin/curl -X GET 'http://192.168.0.4/io.cgi'"
        value_template: '{{ value[7] == "1" }}'
        friendly_name: Gazon voor
  - platform: command_line
    switches:
      sprinklers_bordersachter:
        command_on: "/usr/bin/curl -X GET 'http://192.168.0.4/io.cgi?DOA2=0'"
        command_off: "/usr/bin/curl -X GET 'http://192.168.0.4/io.cgi?DOI2=0'"
        command_state: "/usr/bin/curl -X GET 'http://192.168.0.4/io.cgi'"
        value_template: '{{ value[8] == "1" }}'
        friendly_name: Borders achter
  - platform: command_line
    switches:
      sprinkers_middenachter:
        command_on: "/usr/bin/curl -X GET 'http://192.168.0.4/io.cgi?DOA3=0'"
        command_off: "/usr/bin/curl -X GET 'http://192.168.0.4/io.cgi?DOI3=0'"
        command_state: "/usr/bin/curl -X GET 'http://192.168.0.4/io.cgi'"
        value_template: '{{ value[9] == "1" }}'
        friendly_name: Gazon achter
  - platform: command_line
    switches:
      sprinklers_bordersvoor:
        command_on: "/usr/bin/curl -X GET 'http://192.168.0.4/io.cgi?DOA4=0'"
        command_off: "/usr/bin/curl -X GET 'http://192.168.0.4/io.cgi?DOI4=0'"
        command_state: "/usr/bin/curl -X GET 'http://192.168.0.4/io.cgi'"
        value_template: '{{ value[10] == "1" }}'
        friendly_name: Borders voor
  - platform: command_line
    switches:
      beregening_hoofdkraan:
        command_on: "/usr/bin/curl -X GET 'http://192.168.0.4/io.cgi?DOA5=0'"
        command_off: "/usr/bin/curl -X GET 'http://192.168.0.4/io.cgi?DOI5=0'"
        command_state: "/usr/bin/curl -X GET 'http://192.168.0.4/io.cgi'"
        value_template: '{{ value[11] == "1" }}'
        friendly_name: Beregening Hoofdkraan

I struggled with this earlier today. Ended up moving command_line configuration into the configuration.yaml file from the breakout switches and sensor.yaml files where it was.
Here’s a Before and After example (parameters have been modified):

Before:

- platform: command_line
  switches:
    pihole:
      command_on: "curl -ks 'http://ip/admin/api.php?enable&auth=dbc2dc027bd85b845d3c749773501bd33ace6ac9f1ec77c8748f42af0e8d'"
      command_off: "curl -ks 'http://ip/admin/api.php?disable=300&auth=dbc2dc027bd85b845d3c749773501bd33ace6ac9f1ec77c8748f42af0e8d'"
      command_state: "curl -ks GET 'http://ip/admin/api.php'"
      value_template: "{{ value_json.status == 'enabled' }}"
      friendly_name: DNS Filter

After:

command_line:
  - switch:
      name: Adblock
      command_on: "curl -ks 'http://ip/admin/api.php?enable&auth=dbc2dc027bd85b845d3c749773501bd33ace6ac9f1ec77c8748f42af0e8d'"
      command_off: "curl -ks 'http://ip/admin/api.php?disable=300&auth=dbc2dc027bd85b845d3c749773501bd33ace6ac9f1ec77c8748f42af0e8d'"
      command_state: "curl -ks GET 'http://ip/admin/api.php'"
      value_template: "{{ value_json.status =
1 Like

I recommend to use command_lime: !include command_line.yaml in configuration.yaml and created the referenced file. So you can split them as well (like Switches, sensors, etc)

While HA accepted the new format, the switch didn’t work in the UI. I’m still working on it. Here’s another thread on this topic.

in that topic it seems solved, is it or should I hold ?

It’s likely a syntax issue in your configuration. “platform” is no longer supported.

Nevermind, it was an indent thing… Sigh…
I had to indent the code below -sensor:

Stupid mistake, but hey… I’m only human :wink:


Hi,
I am dealing with an equal challenge here.
I currently (still) use my IOWait sensor using the old format.

sensor:
  - platform: command_line
    name: CPU IO Wait
    command: top -b -n1 | grep ^CPU | awk '{printf("%.0f"), $10}'
    scan_interval: 3
    unit_of_measurement: '%'
    value_template: '{{ value }}'

If my interpretation of the documentation is correct, the new format should be this

command_line:
  - sensor:
    name: CPU IO Wait
    command: top -b -n1 | grep ^CPU | awk '{printf("%.0f"), $10}'
    scan_interval: 3
    unit_of_measurement: '%'
    value_template: '{{ value }}'

When I however do a check config, it returns:

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 'top -b -n1 | grep ^CPU | awk \'{printf("%.0f"), $10}\''
extra keys not allowed @ data['command_line'][0]['name']. Got 'CPU IO Wait'
extra keys not allowed @ data['command_line'][0]['scan_interval']. Got 3
extra keys not allowed @ data['command_line'][0]['unit_of_measurement']. Got '%'
extra keys not allowed @ data['command_line'][0]['value_template']. Got '{{ value }}'. (See /config/configuration.yaml, line 204).

Does anyone have any idea?
For the record, the old one works like a charm.

Try

command_line:
  - sensor:
      name: CPU IO Wait

This new structure is weird, that is why users are stuck.

1 Like

I found out just before you responded. But never the less, thanks!

Add following line to configuration.yaml:

command_line: !include include/command_line.yaml

Add following to command_line.yaml:

  - sensor:
      name: "CPU IO Wait"
      command: "top -b -n1 | grep ^CPU | awk ''{printf("%.0f"), $10}''"
      scan_interval: 3
      unit_of_measurement: '%'
      value_template: '{{ value }}'

Restart HA

2 Likes

I would not use THIS way for config splitting.
But surely it is better than stacking everything in 1 file.

?? You have a better way?

Do not split by domains, split by tasks

Thanks. So you do have a better way!

I did not realize that I could include a directory structure of YAML files, but I will seriously consider migrating my YAML files to this as my system grows.

(Unfortunately, I stopped reading at “Advanced Usage”)…

Thank You.

1 Like

How does this work for multiple sensors?

Do you put like:

command_line:
  - sensor:
      name: First One

  - sensor:
      name: Second One

Or is there some other syntax that is ambiguous from the examples? Putting one - sensor and then - command instead?

I have several like this that I need to migrate:

command_line:
  - binary_sensor:
      command: 'nslookup google.com 192.168.1.1 >> /dev/null && echo pass || echo fail'
      payload_on: pass
      payload_off: fail
      name: DNS Local Nameserver
      scan_interval: 10
      command_timeout: 10
      device_class: connectivity

I made an attempt but the first try also seemed to result in it saying “unknown” instead of “off” as expected.

Yes.
The new structure differs from a more known “template” structure.
Check this and some more my previous posts.
Some changes in HA are not very clever.