Command_line switch SSH commands failing after upgrade to 107

After installing 0.107.0b0, my command_line switches executing SSH commands no longer work. I just receive a “command failed” message in the logs.

I’m using HA to control several Raspberry Pis connected to TVs throughout the house to turn them on and off on different events (motion, etc.) using CEC. This config has worked until 107:

  - platform: command_line
    switches:
        livingroomtv_power:
          command_on: 'ssh [email protected] -i id_rsa -o StrictHostKeyChecking=no ''echo on 0 | cec-client -s -d 1 && echo as | cec-client -s -d 1'''
          command_off: 'ssh [email protected] -i id_rsa -o StrictHostKeyChecking=no ''echo standby 0 | cec-client -s -d 1'''
          command_state: "tvstatus() { local RESULTS; RESULTS=$(ssh [email protected] -i id_rsa -o StrictHostKeyChecking=no \"echo pow 0 | cec-client -s -d 1 | grep -q 'power status: on'\"); echo $?; }; tvstatus"
          value_template: '{{ value == "0" }}'
          friendly_name: Living Room TV        

When I try to turn the switch on, this is the error I get in the logs:

[homeassistant.components.command_line.switch] Command failed: ssh [email protected] -i id_rsa -o StrictHostKeyChecking=no 'echo on 0 | cec-client -s -d 1 && echo as | cec-client -s -d 1'

I’ve tried altering the quotes in the command to use single instead of double quotes, since the documentation said that’s preferred, but it has no effect. Any ideas what could be causing this? It doesn’t look like the command_line integration code itself has changed in a couple of months, so I would think this has to be something about how the new 107 versions interact with it.

Thanks in advance for any help you can provide!

edit: Apologies, forgot which system I was checking - have the below on 106.6 not 107.

I’m not sure but I’ve similar commands that are working in 107, the quotes & ordering are different in mine, e.g. don’t quote the whole string.

So here’s a look if it helps:


- platform: command_line
  switches:
    tv_hdmi_switch:
      command_on: ssh -i /config/ssh/id_rsa -o StrictHostKeyChecking=no [email protected] 'echo "as" | cec-client -s'
      command_off: ssh -i /config/ssh/id_rsa -o StrictHostKeyChecking=no [email protected] 'echo "is" | cec-client -s'
      friendly_name: TV HDMI switch

Never seen that command_state trick before, I’ll have to give that a go, cheers!!

1 Like

Maybe related

1 Like

I wouldn’t think this would apply to my commands, since they’re just SSH and not using a path, but this is definitely interesting. Thank you!

Well, definitely note that it may stop working after an upgrade to 107. I just installed b3 and will test if anything has changed, but the release notes didn’t indicate that anything related was changing.

1 Like

Just confirmed that it’s the same behavior in 0.107.0b3.

I eventually figured this out with some help from this thread, where a user suggested appending 2> /config/command.log to the end of the ssh command in order to write the output from the command to a file. Doing so yielded this error:

Identity file id_rsa not accessible: No such file or directory.

I just had to update the path to the id_rsa file to include /config/, and everything works as it did before. So, @VDRainer was correct. Even though I wasn’t calling a script, I was still referring to the location of id_rsa, so the exact same issue applied. Thank you for your help! Also, just for reference, the config now looks like this:

command_on: "ssh [email protected] -i /config/id_rsa -o StrictHostKeyChecking=no 'echo on 0 | cec-client -s -d 1 && echo as | cec-client -s -d 1'"
2 Likes