← Blogs· 1 min read

How I Taught My Homelab to Self-Heal with an ESP32

Learn how to protect your homelab from power outages using an ESP32

Power outages are a nightmare for servers, especially in a homelab. Unlike data centers, which have massive power backup systems, budget-friendly homelabs often rely solely on small UPS units. Residential areas also frequently experience unplanned power outages with little warning about when the power will return. It could be an hour or more.

Small UPS units are typically only designed to give a brief window of power to a PC, allowing it to turn off gracefully without data loss. However, homelabs present a special case since we are not sitting in front of the server all the time. We could be far away, sleeping, or busy with something else. If not mitigated properly, all of our homelab data could vanish due to an improper server shutdown.

Solution

graph TD
    subgraph Power_Outage [Power Outage]
        direction TD
        A[Power goes out] --> B[ESP32 turns off]
        B --> C[Server cannot<br>reach the ESP32]
        C --> D[Server shuts down]
    end

    subgraph Power_Restoration [Power Restoration]
        direction TD
        E[Power comes back] --> F[ESP32 turns on]
        F --> G[Send WoL magic packets<br>to all given IPs & MACs]
        G --> H[Server turns on]
    end

    classDef outage fill:#ffe6e6,stroke:#ff6666,stroke-width:2px,color:#000;
    classDef restore fill:#e6ffe6,stroke:#66ff66,stroke-width:2px,color:#000;

    class A,B,C,D outage;
    class E,F,G,H restore;

Setup

You will need the following:

  • Server
  • ESP32
  • UPS
  • Power

See the diagram below for how to set everything up. The yellow line represents the power cable.

Solution Solution

Code

Check the hilmoo/homelab-iot/wol GitHub repository for the code.

esc