I would like to be able to switch my Proxmox server on and off using a switch.
This is basically not a problem.
Switching on should work via WakeOnLan, switching off should be done via SSH.
I have created the following shell command for this purpose:
The problem is that the shutdown does not work. I get the error 255 back.
But I have already created SSH keys and imported them on the Proxmox server.
When I use the command:
ssh -i /config/.ssh/id_rsa -o StrictHostKeyChecking=no [email protected] “/sbin/shutdown -h now”
directly on the Home Assistant terminal and this works without any problems.
I assume the backtick at the end of the shell command is a c/p typo?
Note that the intermediary script step is unnecessary. you can call the shell_command directly form an action.
When you are in the terminal you are not in the same environment that HA runs in, HA runs within a docker container. So from your terminal session you need to use docker exec -it to get a shell session within the HA container. This will then be the same environment and you can test your command from the shell. This will tell you if the problem is the command (e.g. the ssh keys are not there).
I have found the solution.
I first had to install the SSH Community Addon.
From there I opened a shell in the homeassistant container and then recreated and copied the keys.
I know you’ve solved it in a somewhat opaque manner, but part of the issue could be that the connection terminates when you execute the shutdown. This is then seen as an abnormal situation by your SSH client. My workaround is to use a shell script with my SSH command in there, redirecting errors to /dev/null and returning a 0 status/exit code.