user13642: I have a Wemos D1 mini that's connected to a pc with usb, I want to be able to sleep the pc and wake it up programmatically. 
Is there a way to do this? Like sending a simulated sleep keyboard button press?
Maybe I can send a wake up on lan command from the Wemos since they both are connected to the same router, but I'm still more interested in sending a sleep command. 
I found this but it's old and it looks like they don't really have a way to do it.

user10394: Sleep
If this is a Windows PC and you can write a WIN32 C++ program then you can look at the WH_KEYBOARD_LL() function and use that to inject the "sleep key", but I'm not sure the "sleep key" isn't an OEM key which might make things difficult.
You could also look at sending a remote command (shutdown) over the network, but you'd have some hefty protocols to implement.  Unless you had a service on your PC that listened to the serial connection and waited for the device to send a sleep command to it over that and converted it into a system call.  The same will work with a Linux Daemon.
Wake Up
You can get Windows (don't know about Linux) to let a USB device wake it up, but I don't know if you could get a Arduino/ESP to send the correct signals.
Like The great Majenko says WoLAN is an option, but difficult to achieve.
My preferred option would be to splice a wire into the power button of the PC in parallel (so you can still use the button) and control that with a relay.  That should give you a Wifi enabled power switch, but you need to check how the switch works and mimic it properly.  I would try it with an old, almost dead, worthless PC first if I was you.

user41738: The hardware interface would be the easiest like others were saying.
Here is a project someone else shared that does that.
https://www.hackster.io/zvonko-bockaj/wemos-esp8266-remote-pc-switch-062c7a
The wake-on-lan part is easy and here is some code for that.
https://github.com/koen-github/WakeOnLan-ESP8266
I'm also interested in sending some kind of RPC call to a system (linux/windows/mac) via wifi to initiate a shutdown.  If I find a solution I will post it here.
UPDATE: I found a Sleep-On-Lan project that should work.  You can use the same code above for the ESP8266 but just reverse the MAC Address of the system you want to shutdown.
https://github.com/SR-G/sleep-on-lan
You will need to run this as a service on the system you intend to put to sleep.  There is a windows and linux version.  They didn't mention mac but I bet it will compile and run on a mac too.  :)
I hope this helps.  I will probably use this myself in the future.

13642: <p>I have a Wemos D1 mini that's connected to a pc with usb, I want to be able to sleep the pc and wake it up programmatically. </p>

<p>Is there a way to do this? Like sending a simulated sleep keyboard button press?</p>

<p>Maybe I can send a wake up on lan command from the Wemos since they both are connected to the same router, but I'm still more interested in sending a sleep command. </p>

<p>I found <a href="http://forum.arduino.cc/index.php?topic=15656.0" rel="nofollow noreferrer">this</a> but it's old and it looks like they don't really have a way to do it.</p>
 10394: <p><strong>Sleep</strong></p>

<p>If this is a Windows PC and you can write a WIN32 C++ program then you can look at the <code>WH_KEYBOARD_LL()</code> function and use that to inject the "sleep key", but I'm not sure the "sleep key" isn't an OEM key which might make things difficult.</p>

<p>You could also look at sending a remote command (shutdown) over the network, but you'd have some hefty protocols to implement.  Unless you had a service on your PC that listened to the serial connection and waited for the device to send a sleep command to it over that and converted it into a system call.  The same will work with a Linux Daemon.</p>

<p><strong>Wake Up</strong></p>

<p>You can get Windows (don't know about Linux) to let a USB device wake it up, but I don't know if you could get a Arduino/ESP to send the correct signals.</p>

<p>Like The great Majenko says WoLAN is an option, but difficult to achieve.</p>

<p>My preferred option would be to splice a wire into the power button of the PC in parallel (so you can still use the button) and control that with a relay.  That should give you a Wifi enabled power switch, but you need to check how the switch works and mimic it properly.  I would try it with an old, almost dead, worthless PC first if I was you.</p>
 41738: <p>The hardware interface would be the easiest like others were saying.
Here is a project someone else shared that does that.</p>

<p><a href="https://www.hackster.io/zvonko-bockaj/wemos-esp8266-remote-pc-switch-062c7a" rel="nofollow noreferrer">https://www.hackster.io/zvonko-bockaj/wemos-esp8266-remote-pc-switch-062c7a</a></p>

<p>The wake-on-lan part is easy and here is some code for that.</p>

<p><a href="https://github.com/koen-github/WakeOnLan-ESP8266" rel="nofollow noreferrer">https://github.com/koen-github/WakeOnLan-ESP8266</a></p>

<p>I'm also interested in sending some kind of RPC call to a system (linux/windows/mac) via wifi to initiate a shutdown.  If I find a solution I will post it here.</p>

<p>UPDATE: I found a Sleep-On-Lan project that should work.  You can use the same code above for the ESP8266 but just reverse the MAC Address of the system you want to shutdown.</p>

<p><a href="https://github.com/SR-G/sleep-on-lan" rel="nofollow noreferrer">https://github.com/SR-G/sleep-on-lan</a></p>

<p>You will need to run this as a service on the system you intend to put to sleep.  There is a windows and linux version.  They didn't mention mac but I bet it will compile and run on a mac too.  :)</p>

<p>I hope this helps.  I will probably use this myself in the future.</p>
