Tokimeki.Memorial

Note: This website contains almost no TokiMemo content.
In fact, this picture is the only reference at this point.

I made a thing! Wifi controlled PC Power Button

Post 00035 | April 8th 2023

As regular readers may know by now, I have been fetishising reducing my power consumption. One of greatest power hogs was my home server. Most of the time it barely did anything, but I didn't want to turn it off in case i needed it to do something. Of course, I could use Wake on LAN to be able to power it on remotely. I've never really had much luck with it to be honest. Sure, it works most of the time, but most of the time isn't the same as all of the time and you can sure that it would always be most inconvenient time where it wouldn't work. So instead I'd just leave it on.

Well, now I have found a solution to the problem in the shape of a little home-made IoT device. Using a D1 Mini, a wifi-enabled microcontroller, and a relay, I am able to simulate a press on the power button. The D1 Mini runs Tasmota which is an open source IoT firmware that works wonderfully with Home Assistant, so I am able to not only switch on my PC remotely, but also automate its power state. As an added bonus, the D1 Mini also reads the voltage of the PCs power LED, so Home Assistant is able to see if the PC is on or not. It is also remarkably cheap, roughly costing €10 in components.

So, how does it work?

The D1 Mini simulates a button press. An ordinary button has two pins that, when the button is pressed, are bridged, shorting a circuit. You are able to perform the same action electronically using a relay. A relay has five points. Two of them are connected to coil while the other three are used for switching. Two of these pins are already bridged, but if you apply current to the two pins connected to the coil, electromagnetism will disconnect the two points and instead bridge the third with a satisfying click. The clicking you hear whenever you use the turn indicators in your car is a relay activating and deactivating.

That's the logic behind it, but to be honest, you won't be needing it. The relay we'll be using comes on a shield, or a pre-made circuit board that you can solder straight to the D1 Mini. The D1 Mini will then deal with powering the coil while the other the points that are used for switching are available via screw terminals.

Setting up the D1 Mini

The first thing you need to decide is weather or not you want to buy a ready-made board or assemble your own. There are pre-flashed Tasmota relays available on eBay but I decided to assemble my own as I already had the parts on hand. I used a D1 Mini and a relay shield which is a small circuit with a relay on it. I soldered the two together with the included headers and BAM, I havd a relay sandwich. Finally, I hooked it up to a PC and visited https://tasmota.github.io/install in a Chromium-based browser (Chrome, Edge etc.) to flash Tasmota onto it.

No matter if you went the DIY or the ready-made route, you'll need to connect your device to your local wifi and configure it with Home Assistant. The device will automatically create its own network if it isn't able to find one to connect to. Connect to this network and a website will pop up where you can help it connect to your real network. It is also on this website you'll set up MQTT which allows it to speak with Home Assistant. Also, if you made your own device, you need to head into "Configuration" → "Configure Module" to tell Tasmota that you have a relay hooked up to it.


Set D1 to Relay 1 and A0 as ADC input. The latter one will be hooked up to the PCs power LED pins to check if the PC is powered on or not. Click Save when finished and head back to the front page. Click the Toggle button to test the relay - You should be able to hear a satisfying click.

Hooking it up to your PC

When that's done, it's time to hook it up to the PC. Here's a rough wiring diagram:

There are two ways of powering the D1 Mini: The easy way would be from the USB port. You can use a phone charger or, if your PC has a USB port that supplies power when when its turned off, you can use that. Alternatively, as shown in the diagram you can connect the 5V and GND pads directly to the ATX power connector. As for actually connecting your wires to the ATX connector, you can splice into the cable (or an extension cable if you want something less destructive) or solder on the underside of the motherboard.

As for the connections to the front panel, I have initially used some female Dupont extension cables. I soldered or screwed the male end to the relay board, while I connected the female end to the front panel headers as you normally would. However, as I would still like to be able to use the PC's actual power button, I bought some front panel splitters from Aliexpress, but they haven't arrived yet.

The last hurdle before we can put the side panel back on is to find somewhere to safely mount our device. In this example above I have attached it to the chipset heat sink with double-sided tape. Another option I haven't tried would be to glue a magnet to the device to hang it anywhere in a case. However, if you go this route, make sure to keep the magnet as far away from the relay as possible as the magnet might interfere with it.

Home Assistant

Great, that was the hard part. Now we only need make Home Assistant work with our contraption. Assuming we've already configured MQTT to make Home Assistant see the device, we still have two things we need to do.

Firstly, we need to crate a script to simulate a button press. Essentially, we need make a script that turns on the relay, waits a little while before turning the relay off again:

You might want to create two scripts. A normal one with 500 millisecond delay and one with a 5000 millisecond delay for a long press, in case you ever need to force shutdown the PC.

The seconds thing we need to do in Home Assistant is make an power indicator. The signal from A0 is a value from 0 to 1024, with 1024 being 3.3V which is a standard voltage for a LED. However, from my testing it would seem like the voltage the motherboard outputs to the power LED vary greatly, with some only reaching a value of 50. Rather than remembering that for instance 64 means on, we are going to create a helper sensor that periodically checks the A0 value and translates it to an on or off value. Go to Settings → Devices & Services → Helpers to create a helper. We'll be wanting a threshold sensor.


"Name" is the name you want for the helper. Input sensor is the relay's ANALOG A0. In this case, A0 reads around 510 when powered on, so I have set 500 as the upper limit. This value is probably different on your PC. Keep the other values at default.

And there you have it. Home Assistant can now see if the PC is powered on or not, and press its power button. How you choose to use these functions is up to you. You can add buttons to your dashboard or use them in automations. Bear in mind that the helper sensor only updates once every couple of minutes which may complicate any attempts at automation. In these cases it might be wiser to for your automation to check the value of A0 instead of the value of the helper.

Anyway, that's basically it! I've been using these relays for a couple of months now in three different PCs and they have all worked perfectly. I realise this looks like a big botch job and that there are more professional solutions out there such as the PiKVM. However, this does exactly what I need it to do, cost a fraction of the cost and uses very little power. I've already earned back the money I paid for them, so all in all, it has been a good investment.