Toggling the Power Button of a Desktop Computer

I think I want to get into ESPHome, but I don’t have a soldering iron and stuff like that. Because I am often connecting to my computer remotely, I was thinking of finding a way to add a relay to the power button, so I can turn my Computer on / put to hibernate based on triggering the power button. I have already set up my computer to go to hibernate, when I press the button, but I would need to somehow be able to trigger it through Home Assistant.
What is an easy way to get into ESPHome, when I don’t have a soldering iron? (living in a student dorm)
I already have a breadboard with a relay and some wires. Could that be useful?

The ESP32 should ideally be powered by some headers inside the computer even, when it is off.

You can use jumper wires.
If you don’t want to cut or solder any wires, you can connect the computer’s power button to an esp gpio and connect 2 jumper wires between the relay and the motherboard. The only problem is that you will need the esp to be always on, to turn on the computer using the physical button.

This code is old, and at the time esphome didn’t support buttons (I think)

switch:
  - platform: gpio
    pin: 13
    id: rele_pc

  - platform: template
    name: "Ligar PC"
    turn_on_action:
      - switch.turn_on: rele_pc
      - delay: 1s
      - switch.turn_off: rele_pc

Add a binary sensor to work with the physical button

Is it ok to use an ESP32-S2 variant or is it not recommended? On the esphome.io page it says, that it is still in development. Does it work for such a simple method?

I never used the s2. But I believe you won’t have any problems, since the code will be very simple.

If your PC is on a wired connection you can use WOL (Wake-On-LAN) to start it up from hibernation, maybe even when it’s powered down - depending on how the power switch actually starts the machine; I think there might even be a WLAN version of this now, although when I tried it a few years ago it was highly dependent on the kind of WLAN hardware the machine used and definitely not very reliable.

Take a look at the BIOS settings first, you might have to enable WOL in there before it works.

I don’t know if this is Christopher’s case, but at least in my case, if the machine is turned off and there is a power outage, it is no longer possible to send a WOL packet to wake up the machine (after power restoration of course).
If it is on, some bios have an option to restore the last state.
So the method using esp is more reliable.

I have my PCs connected with power monitoring smart plugs. I have an automation that detects when the power of the PC is <10W for 10s to detect it is shutdown and then the smart plug is turned off. To turn the PC back on, I just turn on the smart plug. You have to enable Power on after power loss in the PC BIOS.