Wake on Lan - switch status not working [SOLVED]

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

This helped me.

Would be great if you typed, where to aply this fix. I am facing the same issue with the switch tracking myself and from what you typed I can’t figure out what to do at all. I have Home Assistant OS and the srv directory is empty for some reason.

Ok, now its somehow working. Only changed the mac address format to xx-xx-xx and then back to xx:xx:xx and its ok.

hi there,

just following up on this solution, does this work for the latest HA? I seem to have the same problem and running the “ps -p 1 -o comm=” fails from within HA to return any reference to systemd.

Do I need to SSH into the RPI that HA is running on it and configure from there ?

The above was run from the terminal app from within HA.

Thanks!

Im in dockerized environment so not sure if I can apply the same solution - however I’m facing the same issue… the switch is off while my Mac is on.

For those of you who are on Windows and can’t get the switch state after adding the “host” parameter in your config, make sure you can ping your pc from another pc in the network. If you can’t, in Windows firewall advanced settings, enable inbound rule “File and Printer Sharing (Echo Request – ICMPv4 – In)”.

4 Likes

that fixed it, thanks :sunny:

Only if someone need it with windows 11:
Go to “Control Pannel” → “System and Security” → “Windows Defender Firewall” → "Allow an app or feature through Windows Defender Firewall "
And there check “File and Printer Sharing” (There are 2 line similar. Check the first one. NOT the “…SMBDirect”).
If you use a Private network check only the first column (private) otherwise check the second column (public).
[You can check both but maybe it is better if you set your network in private and check only private]

Thanks to puncake for the solution!

I was searching the internet for the solution for days! I suspected it was a firewall rule that needed to be setup. Thanks!