Wake on Lan - remote shutdown of a proxmox server

I’m trying get Wake on LAN working for the shutdown part at the bottom of here:

I’ve searched the forums and tried a lot of things but I can’t seem to solve this. I am pretty new to linux, so I’m hoping it’s an easy fix.

I have setup a user in proxmox that only has authority to sys.PowerManagement and sys.Audit for a user hass (PAM not pve user). Followed the instructions, and checked it over so many times I’m ready for help. I did change to shutdown, I don’t want to suspend. The killer, I can copy and paste this command in the hass terminal and it works, no password needed. It will start the shutdown process of the vm’s and containers and then shut the machine off. Perfect.

This is the command and I have tried single, double and no quotes around the actual command with no luck.

  turn_off_pve: "ssh [email protected] sudo /sbin/shutdown -h now" 

Here’s what I get in the log:

Logger: homeassistant.components.shell_command
Source: /usr/src/homeassistant/homeassistant/components/shell_command/init.py:117
Integration: Shell Command (documentation, issues)
First occurred: 3:13:57 PM (3 occurrences)
Last logged: 3:55:25 PM

Error running command: ssh [email protected] sudo /sbin/shutdown -h now, return code: 255
NoneType: None

Any help would be greatly appreciated. Thank you!

1 Like

You have to use -i to ssh to specify the key to use.
By default, ssh looks for it in ~/.ssh, which won’t work for the HA docker image. You’ll have to create and use a keypair in /config

1 Like

Chris, thank you for the reply! Please let me know if this is what you mean:

Copy ~/ .ssh/authorized_keys file to /config folder.

Also, I’m running HA on a VM in Proxmox (different server), not docker. Would that change anything?

Thank you.

Should be ~ /.ssh/id_rsa

HA always run in a docker container unless you use the “Core” installation method (plain python venv).
In your VM, it’s further encapsulated into HAOS.

I have modified my setup to point to the file directly as you suggested, thank you again. It’s in config/sshkeys/server1 (server1 is what I named the key file). I’m curious if double quotes vs single vs no quotes makes any difference. I’ve been assuming that it is double (") because of the WoL article listed above.

So this is the line in my configuration.yaml:

  turn_off_pve1: "ssh -i ~/config/ssh_keys/server1 [email protected] sudo /sbin/shutdown -h now"

I am still getting the same error. Any thoughts?

Here is a full sample

fetch_ha_image:  >
  ssh -i /config/ssh/id_rsa -4 -o ConnectTimeout=3 -o StrictHostKeyChecking=no [email protected] 'nohup /usr/bin/docker pull homeassistant/home-assistant:stable > /dev/null 2>&1 &'

Using the YAML “>” is useful because it simplifies quoting: You don’t have to on next line.
The single quote delimitates the command executed in the SSH shell.

I’m still getting the 255:

Logger: homeassistant.components.shell_command
Source: /usr/src/homeassistant/homeassistant/components/shell_command/init.py:117
Integration: Shell Command (documentation, issues)
First occurred: 11:18:28 AM (1 occurrences)
Last logged: 11:18:28 AM

Error running command: ssh -i ~/config/ssh_keys/server1 -o StrictHostKeyChecking=no [email protected] sudo shutdown -h now , return code: 255
NoneType: None

Here is the updated code:

shell_command:
  turn_off_pve1: >
    ssh -i ~/config/ssh_keys/server1 -o StrictHostKeyChecking=no [email protected] sudo /sbin/shutdown -h now

Do you see anything that would cause that error? I am still able to copy the entire “ssh -i…” command and paste it into the home assistant terminal and it shuts down the proxmox server, no password promted. This seems like it should be so close to working, but the error in home assistant is not very helpful…

As per my example, try

  turn_off_pve1: >
    ssh -i /config/ssh_keys/server1 -o StrictHostKeyChecking=no [email protected] 'sudo /sbin/shutdown -h now'

That did it! Wow, what a small change but adding the single quotes seems to have been the difference. I did remove the tilde too. Thank you so much for the help!