[Solved] Wake on Lan Switch off Remote Computer

Hi. I searched for a simulair topic with my problem but no luck.

When I’m away from home I use HA to switch on my media server computer to watch some content. When im finished watching I like to switch my media server computer off via the Wake on Lan Switch.

This is my code in the configuration.yaml

# Wake on Lan Server 
switch:
    - platform: wake_on_lan
      mac: xx:xx:xx:xx:xx:xx
     
      turn_off:
        service: shell_command.turn_off

shell_command:
        turn_off: ssh -p 2022 [email protected] sudo shutdown -h now

The command itself works when I do it via the terminal, the remote computer shuts down.

When I change the last command like this below, no changes.

shell_command:
        turn_off: "ssh -p 2022 [email protected] sudo shutdown -h now"

Does anyone has an idea what’s going wrong, Or what’s wrong, no error messages in HA

Thanks

When you use ssh to 192.168.2.20
command sudo shutdown -h now asks you password.
Is that right?

Hi.

No, it’s setup on the server to work without the password.

The ssh command as written works directly from the terminal.

Try with a script , i.e
switch: call-service
script-turn_on

make sure the script is executed in the terminal “context” , and not in your frontend

Or just follow this excellent documentation

That excellent document i followed to the letter, with no success.

And your other advice, i have to figure out how to do that.

I tried to run the command via developer and system and it returned with an error message about the key for authentication.

Apparently something has changed. When time, I’m going to sort that out.

Strange, when i do the command correctly in the terminal it’s working, but via developer - systems then I got host key verification fault.

Solved. Found this on this forum. Did what it said.

Not sure of docker exec -it homeassistant bash the main solution was, but putting the
path for the known_hosts and the key in the command did the trick.

So this is my command now ssh -o UserKnownHostsFile=/config/.ssh/known_hosts -p 2022 [email protected] -i /config/.ssh/id_ed25519 sudo shutdown -h now

where user is my username and the xxx.xxx.xxx.xxx is my ip address of my HA server.