Question: more pleasant `shell_command` ssh?

  • Where is the constrained environment provided by shell_command documented?

    • It’s very confusing that your commands will work when you connect via the core-ssh module and run ssh ... manually, but the exact same command fails when run via HA’s shell_command definition/service… It’s all the confusion of your regular environment vs a cron job, but with less documentation and more latency…
  • How can you get shell_commands to use an SSH wrapper script? I tried to create /config/ssh_wrapper with all my repetative SSH options, but again, it works from the core-ssh command line, and fails via Home Assistant’s shell_commandcall service

  • How can you write a multi-line shell_command… YAML supports the >- syntax that should strip all of the intervening \n newlines and the trailing \n but that doesn’t work and even adding \ or \\ or \\\ it still won’t work…

  • How can you get shell_command driven ssh to read ~/.ssh/config?

Any of these would be fine… Just some sane way to reduce the repetition and increase the readability of shell commands…

Most importantly, how can you test the shell_command via HA without having to do a ha core restart which can take literally minutes if any of your integrations are slow.

Here’s are some of the ssh permutations that one user tried

shell_command:
  restart_pi: "ssh -l pi 192.168.1.74 'sudo reboot'"
  reboot_test: ssh -l [email protected] 'sudo reboot'
  test3: ssh -i /config/ssh/id_rsa -o 'StrictHostKeyChecking=no' [email protected] sudo reboot
  test4: ssh -i /config/ssh/id_rsa -o 'StrictHostKeyChecking=no' [email protected] "sudo reboot"
  test5: "ssh -i /config/ssh/id_rsa -o 'StrictHostKeyChecking=no' [email protected] sudo reboot"
  test6: "ssh -i 'StrictHostKeyChecking=no' [email protected] sudo reboot"
  test7: "ssh -i 'StrictHostKeyChecking=no' [email protected] 'sudo reboot'"
  test8: ssh -i /config/ssh/id_rsa -o StrictHostKeyChecking=no [email protected] 'sudo reboot'

My actual SSH commands are even worse, because I have autossh running a master channel in the background so my commands can be run with reduced latency:

shell_command:
  lights_off: ssh -i /config/ssh_keys/id_rsa -o 'StrictHostKeyChecking=no' -o ControlMaster=no -o ControlPath=/config/ssh_keys/ha.sock -p 999 '[email protected]' LightsOff.sh

However, if this could be written multi-line, especially when making changes to multiple lines…

shell_command:
  lights_off: >-
    ssh -i /config/ssh_keys/id_rsa 
      -o 'StrictHostKeyChecking=no'
      -o ControlMaster=no 
      -o ControlPath=/config/ssh_keys/ha.sock 
      -p 999 '[email protected]' LightsOff.sh