Command line integration- new config with 2023.06 update

I’ve been using the command_line integration to check the up/down status of the xbox and playstation. Now with the recent change, I can’t seem to get it working again. My old config is as follows:

switch:
  - platform: command_line
    switches:
      playstation4:
        command_on: "echo on"
        command_off: "echo off"
        command_state: "nc -z -w 5 192.168.50.52 9295"
        friendly_name: Playstation 4
      xboxone:
        command_on: "echo_on"
        command_off: "echo off"
        command_state: "nc -z -w 5 192.168.50.240 2869"
        friendly_name: XBOX One

Per the new instructions, the configuration should now be:
command_line:

command_line:
  - switch:
      name: Playstation4
      command_on: "echo on"
      command_off: "echo off"
      command_state: nc -z -w 5 192.168.50.52 9295
  - switch: 
      name: XboxOne
      command_on: "echo on"
      command_off: "echo off"
      command_state: nc -z -w 5 192.168.50.240 2869

Problem is, there’s no “playstation4” or “xboxOne” entity (ignore my case) when configuring this way. So I’ve tried to change it to a binary_sensor instead, but still can’t find the sensor.

command_line: 
  binary_sensor: 
    command: 'nc -z -w 192.168.50.52 9295 > /dev/null 2>&1 && echo success || echo fail'
    device_class: connectivity
    payload_on: "success"
    payload_off: "fail"
    scan_interval: 10

Finally, I AM able to set up ICMP sensor and ping the system, but I can’t specify a port with ping. I can only do that with nc, telnet, or nmap, and I’d rather just continue using nc.

Can anyone help? I’m stuck.

This is correct, assuming it is in your configuration.yaml file:

Did you restart Home Assistant after making the changes?

A yaml reload is not sufficient.

This is not correct:

Should be:

command_line: 
  - binary_sensor: 

There would have been errors associated with this in Settings → System → Logs.

Sigh. I only did a yaml reload.

Figured that was satisfactory. I was pretty confident the config was right but couldn’t figure out why the entity was never created. Now I feel like a dolt.

1 Like

Now that the command line integration has been set up a yaml reload should be sufficient after making future changes.

1 Like

Something I should have checked first before posting here. I feel like such a n00b. Thank you for the direction, everything working like it should be.

Has anyone an idea, how to migrate this correctly? For all sensors, I use include in configuration.yaml

sensor: !include_dir_list sensors/

Therefore, my sensor yaml looks like this

platform: command_line
name: proc_state
command: "ls /config/switches/state/proc* | awk -F '/' '{print $5}'"
scan_interval: 60
unique_id: command_line.sensor_proc_state

Reading the documentation gives me no idea, how I have to migrate this correctly from platform to integration.
Thanks for any help.

For example, add this to your configuration.yaml:

command_line: !include command_line.yaml

Create a file in your config dir named command_line.yaml
And put this in it:

- sensor:
    name: proc_state
    command: "ls /config/switches/state/proc* | awk -F '/' '{print $5}'"
    scan_interval: 60
    unique_id: command_line.sensor_proc_state

If you have more than one you have to add - sensor before each of them

1 Like

This configuration ends up in this error, while validating

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 "ls /config/switches/state/proc* | awk -F '/' '{print $5}'"
extra keys not allowed @ data['command_line'][0]['name']. Got 'proc_state'
extra keys not allowed @ data['command_line'][0]['scan_interval']. Got 60
extra keys not allowed @ data['command_line'][0]['unique_id']. Got 'command_line.sensor_proc_state'. (See /config/configuration.yaml, line 49).

… but I got it … there was a problem with the indent

- sensor:
    name: proc_state
    command: "ls /config/switches/state/proc* | awk -F '/' '{print $5}'"
    scan_interval: 60
    unique_id: command_line.sensor_proc_state

i had the same problem

i configure that in the new style, but it doesnt work. Can someone help me?

Old:

switch:
- platform: command_line
  switches:
  playstation:
        value_template: >
          {% if value == 'AWAKE' %}
            true
          {% elif value == 'STANDBY' %}
            false
          {% else %}
            Unknown
          {% endif %}
        command_state: ssh -i /config/ssh/id_rsa -o StrictHostKeyChecking=no [email protected] 'playactor check --host-name PS5-511 | jq -r ".status"'
        command_on: ssh -i /config/ssh/id_rsa -o StrictHostKeyChecking=no [email protected] 'playactor wake --host-name PS5-511'
        command_off: ssh -i /config/ssh/id_rsa -o StrictHostKeyChecking=no [email protected] 'playactor standby --host-name PS5-511'
        friendly_name: Playstation 5

new:


command_line:
  - switch:
      name: Playstation5
      playstation:
        value_template: >
          {% if value == 'AWAKE' %}
            true
          {% elif value == 'STANDBY' %}
            false
          {% else %}
            Unknown
          {% endif %}
      command_state: ssh -i /config/ssh/id_rsa -o StrictHostKeyChecking=no [email protected] 'playactor check --host-name PS5-511 | jq -r ".status"'
      command_on: ssh -i /config/ssh/id_rsa -o StrictHostKeyChecking=no [email protected] 'playactor wake --host-name PS5-511'
      command_off: ssh -i /config/ssh/id_rsa -o StrictHostKeyChecking=no [email protected] 'playactor standby --host-name PS5-511'