$10 Remote Computer Power Management For Your Smart HomeJune 27, 2018
Computer control via Nodemcu
Today on the hookup we’re going to build a sensor that monitors the status of a computer and enables remote power on and shut down with a Wemos D1 Mini. We’re also going to throw in some temperature and humidity monitoring for good measure.
My wife’s computer sits hidden on top of this murphy bed completely out of sight. This is a great solution if we want to keep the computer powered on all of the time, but there’s no good way to turn it on without standing on top of a chair and pressing the power button. And since she doesn’t use this computer every day it seems like a bit of a waste to keep it on all the time.
My original solution to this problem was to use the Wake on LAN functionality of most ethernet controllers. Home assistant even has a wake on lan switch that monitors the state of the computer and allows it shows the correct status on the switch and it works great. The problem with that is that wake on lan only works from sleep or hibernate on Windows 10, and if the power goes out or even flickers this computer will be all the way off, which means still having to climb on top of a chair to turn the thing back on. I even have restore state on power loss enabled in the bios, but the computer inexplicably is off once or twice a month… Who knows.
Last week there was a post on the home assistant subreddit by user Ranthaan where he used optoisolators to do a virtual button press on his PC and this seemed like a better solution to my power problem than using wake on lan. If you watched my video on the DIY pool controller, this is the same concept. Ranthaan used a USB port to monitor power, but I’m going to use the computer’s powerLED as an indicator for whether the computer is on or not.
Here’s our wiring diagram. I’m just going to splice into the existing wires so the manual power button stays functional. First of all, I decided to use a wemos D1 mini for this, but any ESP8266 based chip would work. My decision to use the D1 mini was based on the fact that it doesn’t come with pre-soldered header pins so it’s easier to use them without a prototype board. To monitor the state of the computer I’m going to wire D-0 to the powerLED+ and powerLED- to the ground on the wemos D1 mini so our power LED and microcontroller share a common ground. You could also use an optoisolator here to keep your D1 mini completely separated from your PC, but I checked the voltage on the LED and it was only 3.2V, so that’s perfect for the 3.3v GPIO pins on the D1 Mini.
To handle the virtual button press I’m going to wire D5 to the positive side of our optoisolator, and I’ll connect the other side to ground using a small 150 ohm resistor to limit the current. On the switch side of my optoisolator I need to determine wire is positive voltage and which one is ground. I’m going to use a multimeter to make sure, but they are marked power button + and power button – on the motherboard. I want to hook up my positive wire to the collector and my negative wire to the emitter. Because this device has such a small number of components I’m just going to hot glue the optoisolator to the back of the d1 mini instead of putting it on a prototype board. I’ll also put some hot glue on the wires to give them a little strain relief.
While I’m at it I’m going to throw one of these DHT11 sensors on there to get humidity and temperature readings for the guest room, this will be useful for setting sleeping temperatures when we have house guests. The DHT sensor group is handy because they are one wire sensors, meaning you hook up power, ground, and then a single data pin.
My code is going to watch the mqtt topic commands/PC and if it gets a message of ON while the LED state is off it will write pin D1 high for 1 second to simulate a button press. If it gets the message OFF while the LED state is on it will do the same. If it gets an off message with the LED state off, or an on message with the LED state off it won’t do anything, because that means that the computer is already in the correct state. The sensor will also report any changes in the LED state to a the mqtt topic state/PC so my home assistant instance will always report the correct state of the computer.
Every 30 seconds this getTemp function will run and send out the current temperature reading and current humidity reading via mqtt.
To set this up in home assistant we’ll add a couple of entries to the configuration.yaml file. My first entry will be for the computer switch. This will be an mqtt switch with a command topic of command/PC, and a state topic of state/PC, the on payload will be ON and the off payload will be OFF. We’ll also set up two sensors for the DHT11, in my case I’m going to call them guest room temperature and guest room humidity.
All that’s left to do is test it, lets go plug it in. Lets check on the temperature and humidity in the room first, looks about right. And here we can see that home assistant reports the state of the computer correctly, and lets see what happens when we flip the switch. Perfect.
I’m going to leave my D1 mini all exposed like this just sitting on top of the murphy bed, because that’s the style I’ve already got going up there… but if you would rather have a nice case I’ve included a few good 3d printed options in the description below. Of course all of the parts you need to make this project are included down in the description. Remember that using those amazon links helps me earn money to buy stuff for future projects on this channel. If you enjoyed this video, please consider subscribing, and as always, thanks for watching the hookup.
UK Affiliate Link: https://amzn.to/2IytdMD
Single Optoisolator: https://github.com/thehookup/MQTT_Computer_Power/blob/master/schematic.JPG
Completely Isolated (2 Optoisolators): https://github.com/thehookup/MQTT_Computer_Power/blob/master/Schematic%20with%20opto.JPG
Arduino code: https://github.com/thehookup/MQTT_Computer_Power/blob/master/ComputerControl_CONFIGURE.ino
Arduino based configuration yaml: https://github.com/thehookup/MQTT_Computer_Power/blob/master/computer_control.yaml
3d Printed D1 Mini Case: https://www.thingiverse.com/thing:2221272
Follow me on Twitter: @TheHookUp1
Support my channel:
Music by www.BenSound.com