Have my Wemos do something when my PC is shutdown or asleep

Hi All,

I hope I'm in the right thread/forum.
I've got a Wemos D1 mini, a PC and a Raspberry Pi at home and I want my Wemos to turn off the LED strip connected to it when my PC shuts down or goes asleep and I want my Wemos to turn on the LED strip when my PC powers on or wakes up.

I've already programmed the Wemos, so all I need to do is send a command via the network from my PC or RPi that the LED strip can be powered on or off.

My first idea for doing this was having my RPi ping my PC and send a power on/off command to the Wemos whenever it can't ping it anymore. But I want it to work within a second, so this would mean pinging my PC every second. For this I wanted to make a script that pings for 60 seconds, which would then be executed by a cronjob every minute given that it really takes 60 seconds all together.

My second idea was to add a command to my shutdown and sleep command, seeing as I only turn off my PC via the command line, and a @reboot command to my crontab. And then have my RPi ping my PC every minute via a cronjob as a fallback.

The best solution to me would be some sort of low latency, low impact network connection from my PC to my RPi where a command will be executed the moment the connection is not available anymore. But I'm not sure something like that exists for me, a google search didn't reveal much.

Any help/advice would be greatly appreciated.

Why not have the PC send a message, "Just woke up" or "Going to sleep", when it shuts down or reboots? There is no reason to constantly bug the PC with "Are you awake?".

That is one of my ideas. But I’m wondering if there is another way I could do it. But I guess having my PC send messages and maybe pinging once a minute is the best way go about this.

PaulS' suggestion of having the PC tell you what it's doing is probably the best solution.

However, unless your network bandwidth is really poor, pinging once a second is not likely to cause any issues - it's just annoyingly inefficient. If that bothers you, would it really be so bad if the LEDs didn't come of for two seconds, five?

Then I will go with that suggestion. I guess I was just wondering if maybe someone else had some kind of brilliant solution that I didn't think of.

Thank you both for your help!