Wake on Lan - switch status not working [SOLVED]

Hi Brian, did you see Skullys post #2 about network discovery?

1 Like

Hi@brianjking
Maybe you have to enable WOL in the BIOS first

One of my systems will only wake from a complete shutdown and another will only wake from hibernate. Try different sleep states to see if that is the case.

@outrun – I’ve already enabled it in the BIOS.

@Skully @Cgtobi – What do you mean network discovery?

@norien – I’ve wondered about this as well. I’m pretty sure I’ve tried both hibernation and complete shutdown, however, no go as of yet. Will try again and see what I can figure out.

@brianjking, Network Discovery just underneath This PC had to be turned on for me to get a status of my machines in the front end.

With regards to WoL, do you have magic packet on in the adapter settings and Windows 10 fast startup turned off?

I’ve had it working on two different machines now doing the same.

I tried to investigate a little what might cause the switch not showing the correct status but I can’t replicate whatever HA is doing internally.

I wrote a little python script to ping the host the way HA does it but I only get what I expect, which doesn’t help really.

import platform
import subprocess as sp

DEFAULT_PING_TIMEOUT = 1
hosts = ('foo', '192.168.1.100', 'foo.local.')

for host in hosts:
    ping_cmd = 'ping -c 1 -W {} {}'.format(
                DEFAULT_PING_TIMEOUT, host)

    status = sp.getstatusoutput(ping_cmd)[0]
    print(host, status)
1 Like

May not be the answer you want but I had this issue a number of builds ago, a simple fresh install worked for me.

As the feature is not uber important to me I’d rather track down how it’s not working than simply hiding it by starting from scratch. WOL works, which is most important to me. I just wonder why the status is wrong.

1 Like

Well I have an interesting story. Originally I had my home assistant installed with allinone on a raspberry pi and I had 3 different wol switches working flawless.

Today I finished migration of my home assistant to a dedicated Ubuntu server in virtualenv and all 3 no longer report state on. The switches are working to power on the system’s but I am unable to use the off portion now as it won’t actually show they are on.

Maybe this has something to do with Ubuntu?

I had the same problem, and for me it was the PATH problem, I had to write the hole path inside the python files, instead of ping, /usr/bin/ping

1 Like

Interesting, but the script in this post works fine without the path (for me at least). How is it for you @norien?

1 Like

I dont even know how to begin to run that yet haha. I certainly will try it out if I knew how.

Could you elaborate a little? Which files should I be looking for. my ping is sitting in, /bin/ping - so not sure if it’s different due to being a newer ubuntu server install?

Just in case, I opened an an issue on github about this problem.

@norien simply log into your ha instance with your ha user (eg. hass) and execute which ping. This will probably give you something like /bin/ping. As long as /bin is in your PATH environment variable (check with export | grep PATH) everything should be fine.

Besides, as my little script shows, it has most likely nothing to do with the PATH variable in my opinion.

2 Likes

Here

  • /srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/switch/wake_on_lan.py

  • /srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/device_tracker/nmap_tracker.py
    And every time I update too.

1 Like

I found the problem. :smile:

@pblgomez made me think about the whole environment variable setup a bit more and after a few guesses and test scripts I found that the virtual environment within the systemd service was missing a few paths.
So here is the fix, edit your systemd service and add :/usr/bin to the line starting with Environment=PATH="$VIRTUAL_ENV/bin:.

e.g.

Environment=PATH="$VIRTUAL_ENV/bin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/usr/bin:/sbin:/bin:$PATH"

Than simply sudo systemctl daemon-reload and restart home assistant or reboot.

2 Likes

Thanks, better than my solution

Works flawless for me too! This right here is why Home Assistant is #1. This community truly kicks ass!

Just for anyone who is very new to linux in general like myself the path to the systemd file for me on Ubuntu Server 16.10 with the VIRTUALENV Install is

/etc/systemd/system/[email protected]

I was able to edit the file by with notepad++ via WinSCP.

So damn happy this is fixed thanks again everyone!

1 Like

I couldn’t agree more!

@norien just dug a little deeper and it seems the proper fix is an even simpler systemd service.

It can most likely be stripped down to this:

[Unit]
Description=Home Assistant
After=network.target

[Service]
Type=simple
User=%i
ExecStart=/srv/homeassistant/bin/hass -c "/home/%i/.homeassistant"

[Install]
WantedBy=multi-user.target