{"id":352,"date":"2018-06-27T12:49:42","date_gmt":"2018-06-27T16:49:42","guid":{"rendered":"http:\/\/www.thesmarthomehookup.com\/test_install\/?p=352"},"modified":"2023-04-24T15:47:27","modified_gmt":"2023-04-24T19:47:27","slug":"10-remote-computer-power-management-for-your-smart-home","status":"publish","type":"post","link":"http:\/\/www.thesmarthomehookup.com\/test_install\/10-remote-computer-power-management-for-your-smart-home\/","title":{"rendered":"$10 Remote Computer Power Management For Your Smart Home"},"content":{"rendered":"<p><iframe width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/1JrcQ0s55JU\" frameborder=\"0\" allow=\"autoplay; encrypted-media\" allowfullscreen=\"\"><\/iframe><\/p>\n<p><strong>Computer control via Nodemcu<\/strong><\/p>\n<p>Today on the hookup we\u2019re 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.&nbsp; We\u2019re also going to throw in some temperature and humidity monitoring for good measure.<\/p>\n<p>My wife\u2019s computer sits hidden on top of this murphy bed completely out of sight.&nbsp; This is a great solution if we want to keep the computer powered on all of the time, but there\u2019s no good way to turn it on without standing on top of a chair and pressing the power button.&nbsp; And since she doesn\u2019t use this computer every day it seems like a bit of a waste to keep it on all the time.<\/p>\n<p>My original solution to this problem was to use the Wake on LAN functionality of most ethernet controllers.&nbsp; 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.&nbsp; 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.&nbsp; I even have restore state on power loss enabled in the bios, but the computer inexplicably is off once or twice a month\u2026&nbsp; Who knows.<\/p>\n<p>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.&nbsp; If you watched my video on the DIY pool controller, this is the same concept.&nbsp; Ranthaan used a USB port to monitor power, but I\u2019m going to use the computer\u2019s powerLED as an indicator for whether the computer is on or not.<\/p>\n<p>Here\u2019s our wiring diagram.&nbsp; I\u2019m just going to splice into the existing wires so the manual power button stays functional.&nbsp;&nbsp;&nbsp; First of all, I decided to use a wemos D1 mini for this, but any ESP8266 based chip would work.&nbsp; My decision to use the D1 mini was based on the fact that it doesn\u2019t come with pre-soldered header pins so it\u2019s easier to use them without a prototype board.&nbsp; To monitor the state of the computer I\u2019m 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.&nbsp; 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\u2019s perfect for the 3.3v GPIO pins on the D1 Mini.<\/p>\n<p>To handle the virtual button press I\u2019m going to wire D5 to the positive side of our optoisolator, and I\u2019ll connect the other side to ground using a small 150 ohm resistor to limit the current.&nbsp; On the switch side of my optoisolator I need to determine wire is positive voltage and which one is ground.&nbsp; I\u2019m going to use a multimeter to make sure, but they are marked power button + and power button \u2013 on the motherboard.&nbsp; I want to hook up my positive wire to the collector and my negative wire to the emitter.&nbsp; Because this device has such a small number of components I\u2019m just going to hot glue the optoisolator to the back of the d1 mini instead of putting it on a prototype board.&nbsp; I\u2019ll also put some hot glue on the wires to give them a little strain relief.<\/p>\n<p>While I\u2019m at it I\u2019m 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.&nbsp; The DHT sensor group is handy because they are one wire sensors, meaning you hook up power, ground, and then a single data pin.<\/p>\n<p>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.&nbsp; If it gets the message OFF while the LED state is on it will do the same.&nbsp; If it gets an off message with the LED state off, or an on message with the LED state off it won\u2019t do anything, because that means that the computer is already in the correct state.&nbsp; 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.<\/p>\n<p>Every 30 seconds this getTemp function will run and send out the current temperature reading and current humidity reading via mqtt.<\/p>\n<p>To set this up in home assistant we\u2019ll add a couple of entries to the configuration.yaml file.&nbsp; My first entry will be for the computer switch.&nbsp; 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\u2019ll also set up two sensors for the DHT11, in my case I\u2019m going to call them guest room temperature and guest room humidity.<\/p>\n<p>All that\u2019s left to do is test it, lets go plug it in.&nbsp; Lets check on the temperature and humidity in the room first, looks about right.&nbsp; 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.&nbsp; Perfect.<\/p>\n<p>I\u2019m going to leave my D1 mini all exposed like this just sitting on top of the murphy bed, because that\u2019s the style I\u2019ve already got going up there\u2026 but if you would rather have a nice case I\u2019ve included a few good 3d printed options in the description below.&nbsp; Of course all of the parts you need to make this project are included down in the description.&nbsp; Remember that using those amazon links helps me earn money to buy stuff for future projects on this channel.&nbsp; If you enjoyed this video, please consider subscribing, and as always, thanks for watching the hookup.<\/p>\n<h3>Links<\/h3>\n<p>Project parts list from amazon:<br \/>\nWemos D1 Mini: <a href=\"https:\/\/amzn.to\/2MoEn9m\">https:\/\/amzn.to\/2MoEn9m<\/a><br \/>\nOptoisolators: <a href=\"https:\/\/amzn.to\/2sJ8Iab\">https:\/\/amzn.to\/2sJ8Iab<\/a><br \/>\nResistors: <a href=\"https:\/\/amzn.to\/2J67k8c\">https:\/\/amzn.to\/2J67k8c<\/a><br \/>\nDHT11: <a href=\"https:\/\/amzn.to\/2KrgMnE\">https:\/\/amzn.to\/2KrgMnE<\/a><\/p>\n<p>UK Affiliate Link: <a href=\"https:\/\/amzn.to\/2IytdMD\">https:\/\/amzn.to\/2IytdMD<\/a><\/p>\n<p>Schematics:<br \/>\nSingle Optoisolator: <a href=\"https:\/\/github.com\/thehookup\/MQTT_Computer_Power\/blob\/master\/schematic.JPG\">https:\/\/github.com\/thehookup\/MQTT_Computer_Power\/blob\/master\/schematic.JPG<\/a><br \/>\nCompletely Isolated (2 Optoisolators): <a href=\"https:\/\/github.com\/thehookup\/MQTT_Computer_Power\/blob\/master\/Schematic%20with%20opto.JPG\">https:\/\/github.com\/thehookup\/MQTT_Computer_Power\/blob\/master\/Schematic%20with%20opto.JPG<\/a><\/p>\n<p>Essentials:<br \/>\nHook Up Wire: <a href=\"https:\/\/amzn.to\/2JsDtuF\">https:\/\/amzn.to\/2JsDtuF<\/a><br \/>\nSoldering Iron: <a href=\"https:\/\/amzn.to\/2JuTQa6\">https:\/\/amzn.to\/2JuTQa6<\/a><br \/>\nWire Cutters: <a href=\"https:\/\/amzn.to\/2Ls4Imr\">https:\/\/amzn.to\/2Ls4Imr<\/a><\/p>\n<p>Arduino code: <a href=\"https:\/\/github.com\/thehookup\/MQTT_Computer_Power\/blob\/master\/ComputerControl_CONFIGURE.ino\">https:\/\/github.com\/thehookup\/MQTT_Computer_Power\/blob\/master\/ComputerControl_CONFIGURE.ino<\/a><br \/>\nArduino based configuration yaml: <a href=\"https:\/\/github.com\/thehookup\/MQTT_Computer_Power\/blob\/master\/computer_control.yaml\">https:\/\/github.com\/thehookup\/MQTT_Computer_Power\/blob\/master\/computer_control.yaml<\/a><\/p>\n<p>3d Printed D1 Mini Case: <a href=\"https:\/\/www.thingiverse.com\/thing:2221272\">https:\/\/www.thingiverse.com\/thing:2221272<\/a><\/p>\n<p>Follow me on Twitter: @TheHookUp1<br \/>\nSupport my channel:<br \/>\nPatreon:&nbsp;<a href=\"https:\/\/www.patreon.com\/thehookup\">https:\/\/www.patreon.com\/thehookup<\/a><\/p>\n<p>Music by www.BenSound.com<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Computer control via Nodemcu Today on the hookup we\u2019re 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.&nbsp; We\u2019re also going to throw in some temperature and humidity monitoring for good measure. My wife\u2019s computer sits hidden on top [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":2606,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-352","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-projects"],"acf":[],"mb":[],"mfb_rest_fields":["title","gutenberg_elementor_mode"],"_links":{"self":[{"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/posts\/352","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/comments?post=352"}],"version-history":[{"count":4,"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/posts\/352\/revisions"}],"predecessor-version":[{"id":2361,"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/posts\/352\/revisions\/2361"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/media\/2606"}],"wp:attachment":[{"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/media?parent=352"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/categories?post=352"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/tags?post=352"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}