Completely puzzled! Shell yaml

Hi all,

I have the following two entries in my shell.yaml file:

unifi_outside_ap_led_off: >- 
  ssh -i /config/.ssh/id_rsa -o StrictHostKeyChecking=no [email protected] echo 0 >/proc/gpio/led_pattern
    && sed -i '/mgmt.led_pattern_override/d' /etc/persistent/cfg/mgmt 
    && echo mgmt.led_pattern_override=0 >> /etc/persistent/cfg/mgmt

unifi_outside_ap_led_on: >- 
  ssh -i /config/.ssh/id_rsa -o StrictHostKeyChecking=no [email protected] echo 0 >/proc/gpio/led_pattern
    && sed -i '/mgmt.led_pattern_override/d' /etc/persistent/cfg/mgmt 
    && echo mgmt.led_pattern_override=0 >> /etc/persistent/cfg/mgmt

As you can see they are both identical (except for the name of the commands).

Can someone please tell me why when I run them via the Developer page the first shell command runs ok but the second on doesn’t and produces the following error:

2021-11-23 17:39:42 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: `ssh -i /config/.ssh/id_rsa -o StrictHostKeyChecking=no [email protected] echo 0 >/proc/gpio/led_pattern
  && sed -i '/mgmt.led_pattern_override/d' /etc/persistent/cfg/mgmt 
  && echo mgmt.led_pattern_override=0 >> /etc/persistent/cfg/mgmt`, return code: 2
NoneType: None

I have tried swapping their order and retyping the one that’s erroring.

I’m stumped!!

how are you including the shell.yaml?

With a specific include to the file (shell_command: !include shell.yaml)

I have other entries/commands in the shell yaml file and they work ok.

I’ve got it working, but I don’t know what was causing it not to work, all I can assume is it’s something weird/internal to HA?

I changed the line to a single line and put double quotes around the whole set of commands:

ssh -i /config/.ssh/id_rsa -o StrictHostKeyChecking=no [email protected] "echo 0 >/proc/gpio/led_pattern && sed -i '/mgmt.led_pattern_override/d' /etc/persistent/cfg/mgmt && echo mgmt.led_pattern_override=0 >> /etc/persistent/cfg/mgmt"

Splitting it over multiple lines with double quotes at the beginning and end still didn’t work. It had to be a single line (a single line without the double quotes didn’t work either)

Weird how the “off” command works on multiple lines and no double quotes, but the on needs the double quotes and to be a single line.

Marking this as the solution looks bad to me. It is nothing more then a workaround.