Detect PC on or asleep with no companion app

Hey folks, I’ve been trying to set an automation to detect that I’ve turned off the PC and then proceed to turn off the power plug to completely cut power from it even on idle.

I’ve so far managed to use the ping integration to detect that the PC disconnected and then I move on checking if the power readings from the socket are small enough that the PC is not running (<10W). (I even conditioned only start pinging when the socket is on, which is nice).

However, if the OS sleeps, the power usage is very similar to powered off in Idle (varies from 1W to 3W). So there’s the possibility the automation will trigger during sleep as it doesn’t reply to ICMP while sleeping.

Disclaimer that I know that there’s some companion apps like HASS agent, IOT link and others that could capture the shutdown, but as I dual-boot into both Windows and Linux and there’s no single app that works for both and setup is not straightforward (like requiring add-ons) I would rather try to keep things simple and not depend on the host applications.

Something that might be worth looking at:

You can use task scheduler to run a script using the sleep event ID.

Reading, it looks like it needs to run pretty quickly or it won’t finish in the time between the event triggering and the OS going to sleep. That said, you should be able to write a very short script to call a webhook to HA.

I would setup an input_boolean for sleep, write the automation to toggle it on when triggered, and have the PC hit the webhook trigger for the script.

1 Like

You should be able to customize the power saving plan to not turn off the Ethernet card, then icmp will continue to work.

or ditch linux/windows by virtualization of windows/linux?

In my case it’s wifi. I’ve tried to disable the power off plan on it, but icmp still doesn’t work. It’s probably a bit difficult with Wifi, I guess.