SSH script to NAS not working anymore - Response 255

Hi, I used to send my NAS to sleep mode, using an SSH script that I placed in the configuration.yaml. About 2 years ago it kind of stopped working, if I execute the script now I only get the response 255 in the logs. If I connect to the terminal directly and execute the script, everything works completele fine.

Hardware used:

  • HomeAssistant in a ProxmoxVM (didnt work on Raspi either)
  • QNAP TS251A
  • Terminal and SSH addon

I did create a SSH key on the HomeAssistant, so the login works without entering credentials. That also works just fine in the terminal.

The configuration:

shell_command:
  turn_off_nas110: 'ssh [email protected] "echo mem > /sys/power/state 2>/dev/null"'
  service: shell_command.turn_off_nas110
  name: Sleep NAS110

I used to execute the script via a lovelace button, that calls the script as entity. The response I get when I call the script:

2022-06-03 21:17:00 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: `ssh [email protected] "echo mem > /sys/power/state 2>/dev/null"`, return code: 255
NoneType: None

Any ideas on this? Would be super handy to get the NAS to sleep from HA again.

I’m not entirely sure how that used to work tbh. The fact that it works in the ssh addon doesn’t really tell you anything since HA is in a different docker container with a different home directory that won’t have the keys.

Either way follow that guide and you’ll get it working.

1 Like

Thats exactly what I thought during setup, but however it worked. I just had a quick look at your guide, looks good to me. Ill test that and report with the result.

Quick update, huge thanks for your guide. Works perfect now, the code is as follows

ssh -o UserKnownHostsFile=/config/.ssh/known_hosts [email protected] -i /config/.ssh/id_rsa "echo mem > /sys/power/state 2>/dev/null"

2 Likes