WOL (Wake on Lan) shutdown and Mac OS X

Hello everyone, I’m having some trouble with the config of the WOL shutdown for an iMac.
This is my config:

  • platform: wake_on_lan
    mac_address: “XX-XX-XX-XX-XX”
    name: “iMac”
    service: shell_command.mac_off`

and in my shell_commands.yaml I have:
mac_off: ssh [email protected] sudo shutdown -h now

I’ve configured the system, where HA is running, to access the iMac without password, following this guide: http://www.linuxproblem.org/art_9.html, everything seems working fine.
I can successfully access my mac without using a password and if run ssh [email protected] sudo shutdown -h now from shell the mac turn off, on the contrary if I toggle off the switch from HA nothing happens. What could I check? I didn’t find anything inside home-assistant.log :sweat:


Try adding something like “touch it-worked” to your ssh command, so you can be sure that part works ok.

thanks @magicus, I modified the command in: mac_off: ssh [email protected] sudo shutdown -h now; touch it-worked and it is not working, no file is created. Maybe this is related to the fact that I’m running HA in a virtual environment…

Are you sure you are testing under the same user as HA is running under?

Try adding the path to ssh (/usr/bin/ssh on some platforms, use which ssh to check on your HA server)

Bingo! That was the problem! I did the procedure for the SSH login without password for the wrong user :sweat_smile:
Thanks a lot!!

Could you post your final configuration?

I used the configuration that you can see in my first post. The only difference is that I repeated the procedure for the SSH login without password under the HA user.

In my shell_command.yaml i have a shutdown script to turn off my iMac:
turn_off_imac: 'ssh [email protected] sudo /sbin/shutdown -h now'
Unfortunately it isn’t working. When executing this command I get:
sudo: no tty present and no askpass program specified

What am I missing?

  • I created a public and private key on my HA with ssh-keygen and no password
  • I can login to my mac from ssh via HA commandline with ssh [email protected] without using a password
  • in configuration.yaml there are two lines for importing the shell command and the switch: shell_command: !include shell_command.yaml and switch: !include switches.yaml
  • In switches.yaml i have the following code:

- platform: wake_on_lan
mac_address: "xx-xx-xx-xx-xx-xx"
name: "imac"
host: ""
service: shell_command.turn_off_imac

Any help, tips, suggestions to fix this issue are welcome.

I found a partial solution to the error:
sudo: no tty present and no askpass program specified
See here.

The shutdown command will execute from command line now. No sudo error as above :slight_smile:
The switch however doesn’t work
I’m starting to think that the Hassio virtual environment doesn’t allow commands at all due to command-line restrictions. :frowning: Can anyone verify that?

sudo: no tty present and no askpass program specified

Fixed this by adding the correct user to /etc/sudoers…

But the switch isn’t working for me neither.


in the last days i tried to get a switch working so i can turn off my iMac with Home Assistant. I also would like to shutdown other Pi’s in my network. One is running Volumio2 (a mediaplayer) and the other one Rasplex.
Unfortunately, i didn’t get the switch working, but i can turn my mac off with the Terminal-Addon and the command in the following config. (i don’t need command_on yet)

Here is my config:

  platform: command_line
      command_on: "switch_command on kitchen"
      command_off: "ssh [email protected] 'shutdown -h now'"
      command_on: "switch_command on kitchen"
      command_off: "ssh [email protected] 'shutdown -h now'"

This is what i did already:

  1. Followed this tutorial: SSH login without password to connect without a PW.
  2. Added “PermitRootLogin yes” into “/etc/ssh/ssh_config” (NOT sshd_config as it was described in another thread. there was no file sshd_config…)
  3. Tried variations of the command_off-command (with or without " or ’ )

Thus, these are my questions:
Is there anyone who already got a switch working?
@asp What did you do exactly? What is the HA user? Isn’t it root?
Is it better to do this with a WOL-Switch instead of command_line?

Thanks in advance!

Is there anyone who already got a switch working?

My switch is working in my enviroment

What did you do exactly? What is the HA user? Isn’t it root?

I was using Home Assistant inside a virtual enviroment, so I had to do the procedure using the homeassisant user that I created for that installation.

Is it better to do this with a WOL-Switch instead of command_line?

I don’t know why, but I wasn’t able to make the WOL-Switch working.

Found this tutorial on how to use SSH on Hass.IO to control other devices: A thorough guide on controlling anything SSH with Homeassistants’s Hass.io

Everything I wanted is working as expected. I am putting my Mac to sleep/standby using the Wake On Lan switch. Here is my setup:

      - service: shell_command.macbook__standby

  macbook__standby: ssh -i /config/ssh/id_rsa -o StrictHostKeyChecking=no [email protected] 'pmset sleepnow'

  - platform: wake_on_lan
    name: WoL  Macbook Switch
    mac_address: !secret switch__wol__macbook_mac_address
    host: !secret switch__wol__macbook_host
      service: script.macbook__standby ## could be "shell_command.macbook__standby" if you don't want to create a script

To shutdown the Mac immediately, you have to change pmset sleepnow to shutdown -h now. Shutting down the Mac after (for example) 5 minutes would be: sudo shutdown -h +5


Error running command: ssh -i /config/ssh/id_rsa -o StrictHostKeyChecking=no [email protected] 'pmset sleepnow', return code: 255

this is the error I’m getting

Hi @Jakesa

I’m not sure if it helps - I wrote a lot that night… But somewhere in the post you probably can find a hint how I made the error 255 go away.


1 Like