Wake On Lan

Your raspberry runs linux, so the command should be for the linux terminal. This command shuts down a windows pc. Give it a try :wink:

Tried it but its asking for password and when i give the password it says user not found. When i created same username and password in pi it worked. But for different username and password I was able to get this command below to work

net rpc shutdown -f -C ‘message’ -U username%pass -I ipaddress

But i am unable to make it work after entering this command under shell command. I want to try SSH into my PI and use this command. But its running hassio and not allowing me to run this command. SO i want to know how get this command to work in Rpi running Hassio

I am pretty sure the username and the password you need to use, is the one in the windows PC…
If you dont have a password setup on your windows PC, then you must enable it for the shutdown to work.
You have to go to the control panel and then accounts and setup a password for your administrator account. Otherwise the PC will not shutdown.

Please note that “mac_address” is no longer valid, now it’s only “mac: XX:XX:XX:XX:XX:XX”

I am turning off my windows PCs using additional software.
I use this http://www.airytec.com/en/switch-off/get.aspx and enable the webserver option.
Then I use a curl command like this in a shellcommand:

shutdown_z801: 'curl -k http://192.168.0.150:8000/?action=System.Shutdown'

Using the method described here is more elegant but I was unaware of it when I started using this and it works really fine.

If you are using your windows pc without a password so you don’t have to enter it every time it boots you can just make windows auto login - this is what I do.

1 Like

If you want to shut down a windows pc from Home Assistant, you can simply use the RPC Shutdown add-on from the addon store (https://github.com/home-assistant/hassio-addons/blob/ffc5886cabf121646f824f5aee955da1348ccfbb/rpc_shutdown/README.md).

It works flawlessly and integrates well with the wake-on-lan switch (https://www.home-assistant.io/integrations/wake_on_lan#switch). You do not need any additional software or service running on the remote PC. It is much cleaner.

I’ve just reinstalled homeassiant image, moving away from building my own on top of raspbian and i am again running into this problem.

I copied the same code that still works from my old sd card, but when i add it in the configuration.yaml file, i no longer see my computers in the switch node. It has my light switches but not my computers, i used the config checker and it was fine.

What am i doing wrong?

I don’t need to shutdown, just need wol.

Is it better to have wol configured in configurations.yaml or switches.yaml ??

And can anyone explain me why i can´t use name: pc_name ?? Because everythime i try to set the pc name (name: pc_name) the configuration gets error…

ex:
switch:

  • platform: wake_on_lan
    name: “pc_name”
    mac: “mac”
    host: “ip”’

Hi, thanks to all the prior posts, I was able to get HA to turn on my Windows 10 PC using wol and integrate that in Harmony by mimicking a Hue switch. However, I’m not able to turn off the PC using the RPC Shutdown Addon. What I notice is that when I turn on the PC using the switch, the switch stays in the “on” position for a few seconds and then goes back to “off”. The PC, however, remains on. Has anyone else experienced this behavior?

Thank you!

Sorry for the prior post…my issue was the PC I was trying to turn off defaulted to “Public” network and when I changed it to “Private”, the shutdown is working.

Also, I realize the reason why the Hue switch went back to “off” was because until the PC is fully booted and seen on the LAN, the toggle switch stays “off”, once its network is up and running, the toggle switch moves to “on”.

All I can say is wow! This is so incredible!

Hi Hammer,

Switch acts the same for me. Also when the computer is booted, it flips back to off.
Can you share what you put in the script?

Also how did you managed to do the shutdown?

This method requires you to store your login credentials in plaintext, and even though random users shouldn’t have access to the config at all, it’s just generally considered bad practice.

Personally I use this tiny open-source C# utility that allows you to send web requests to shutdown, sleep, etc. Similar to the one above, but not so proprietary.

I also run it as a service meaning I can execute these commands even when the computer is locked or no users are logged in.

Hello All,
I have a different integration that has worked for me very well In old ST Webcore. .Called Sleep On lan
I would like some help/input/thoughts on the syntax on HA.

I set up switch in my config as below but the off portion of the switch does not work.
I want to call the wake on lan again when tur_off is called and send mac address.
any assistance is appreciated

switch:
  - platform: wake_on_lan
    mac: 'xx:xx:xx:xx:xx:xx'
    name: "PC Power On"
    turn_off:
  - platform: wake_on_lan
    mac: 'xx:xx:xx:xx:xx:xx'

Hi Guys,

I am playing with wake_on_lan and I ran into issues. My switch looks like this:

switch:
  - platform: wake_on_lan
    name: device
    mac: 2D:8C:xx:xx:xx
    broadcast_address: 172.x.x.x
    host: 172.x.x.x

And I get: Incorrect MAC address format

Error is:

2021-11-09 03:09:33 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [2974724448] Incorrect MAC address format
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 185, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1495, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1530, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 213, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 667, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 863, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 704, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 915, in async_turn_on
    await self.hass.async_add_executor_job(ft.partial(self.turn_on, **kwargs))
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/wake_on_lan/switch.py", line 133, in turn_on
    wakeonlan.send_magic_packet(self._mac_address, **service_kwargs)
  File "/usr/local/lib/python3.9/site-packages/wakeonlan.py", line 52, in send_magic_packet
    packets = [create_magic_packet(mac) for mac in macs]
  File "/usr/local/lib/python3.9/site-packages/wakeonlan.py", line 52, in <listcomp>
    packets = [create_magic_packet(mac) for mac in macs]
  File "/usr/local/lib/python3.9/site-packages/wakeonlan.py", line 31, in create_magic_packet
    raise ValueError("Incorrect MAC address format")
ValueError: Incorrect MAC address format

What does it want from me?

The MAC address is a 12 digit hexadecimal number that is most often displayed with a colon or hypen separating every two digits (an octet).
Based on your switch, you have only 5 octet instead of 6.

mac: 2D:8C:xx:xx:xx

must be 2D:8C:xx:xx:xx:xx

Facepalm
I was copying the MAC from routers webpage, I guess it was an issue with selecting the string.
Thank you very much for your attention

I was running into similar issues as other people in this thread, but what fixed it for me wasn’t in this thread yet. I actually needed to change settings on my windows PC that I wanted to wake on lan.

So here was my solution.

First
I needed to change my network from public to private. This allowed the switch to see if my computer was on. If you open up cmd prompt and try to ping your computer (ping 192.168.1.xxx), you should be getting a reply

Second
I needed to editing my network adapter’s settings to allow for wake on lan.

Hope this helps!