Blackout load control: mini-PC + Zigbee + ESP32

A mini-PC with Home Assistant, a Zigbee USB stick and an ESP32 battery sensor switch heavy appliances off when the inverter battery runs low.

Level: Advanced Board: ESP32 DevKit V1 (WROOM-32) Smart home

⚠ Safety

Heavy appliances must be switched by a rated contactor or a certified smart relay, not by hobby boards.

What you need

Buy the parts kit · Estimated total: $181.50

ESP32 DevKit V1 (30 pin, WROOM-32) × 1
$4.00
Buy at AliExpress Buy at Amazon.com
Relay module 1-channel 5V (opto-isolated) × 1
$1.50
Buy at AliExpress Buy at Amazon.com
Budget mini-PC Intel N100 (8 GB / 256 GB) × 1
$130.00
Buy at AliExpress Buy at Amazon.com
Zigbee USB coordinator (CC2652 / ZBDongle) × 1
$22.00
Buy at AliExpress Buy at Amazon.com
USB SSD 120-240 GB + SATA-USB adapter × 1
$20.00
Buy at AliExpress Buy at Amazon.com
USB charger 5V 2A × 1
$4.00
Buy at AliExpress Buy at Amazon.com
🇺🇦 Ukraine🌍 Other countries

Ukraine: we buy and sell these parts ourselves, order them on this site.

Some links are affiliate links: we may earn a commission at no extra cost to you.

Wiring

ModuleModule pinESP32 pinNote
Relay INsignalGPIO26active LOW, dry-contact control only
Zigbee USB stickUSBmini-PC USB (use an extension cable)away from USB 3 ports

Libraries

Arduino IDE → Tools → Manage Libraries, then install:

  • PubSubClient

Code

minipc-zigbee-load-control.ino
#include <WiFi.h>

const char* WIFI_SSID = "YOUR_WIFI";
const char* WIFI_PASS = "YOUR_PASSWORD";

bool connectWiFi(uint32_t timeoutMs = 20000) {
  WiFi.mode(WIFI_STA);
  WiFi.begin(WIFI_SSID, WIFI_PASS);
  uint32_t t0 = millis();
  while (WiFi.status() != WL_CONNECTED && millis() - t0 < timeoutMs) {
    delay(250);
    Serial.print(".");
  }
  Serial.println();
  if (WiFi.status() == WL_CONNECTED) {
    Serial.print("IP: ");
    Serial.println(WiFi.localIP());
    return true;
  }
  return false;
}
#include <PubSubClient.h>

const char* MQTT_HOST = "192.168.1.10";   // IP of your Raspberry Pi / mini-PC
const uint16_t MQTT_PORT = 1883;
const char* MQTT_USER = "esp32";
const char* MQTT_PASS = "mqtt-password";

WiFiClient netClient;
PubSubClient mqtt(netClient);

bool mqttConnect(const char* clientId) {
  mqtt.setServer(MQTT_HOST, MQTT_PORT);
  uint32_t t0 = millis();
  while (!mqtt.connected() && millis() - t0 < 10000) {
    if (mqtt.connect(clientId, MQTT_USER, MQTT_PASS)) return true;
    delay(500);
  }
  return mqtt.connected();
}
const int PIN_RELAY = 26;      // active LOW
void onMsg(char* topic, byte* p, unsigned int len) {
  String m; for (unsigned i = 0; i < len; i++) m += (char)p[i];
  bool on = (m == "ON");
  digitalWrite(PIN_RELAY, on ? LOW : HIGH);
  mqtt.publish("home/load1/state", on ? "ON" : "OFF", true);
}
void setup() {
  pinMode(PIN_RELAY, OUTPUT); digitalWrite(PIN_RELAY, HIGH);
  Serial.begin(115200);
  connectWiFi();
  mqtt.setCallback(onMsg);
  if (mqttConnect("esp32-load1")) mqtt.subscribe("home/load1/set");
}
void loop() {
  if (!mqtt.connected() && mqttConnect("esp32-load1")) mqtt.subscribe("home/load1/set");
  mqtt.loop();
}
ha-configuration.yaml
mqtt:
  switch:
    - name: "Load 1"
      command_topic: "home/load1/set"
      state_topic: "home/load1/state"
      payload_on: "ON"
      payload_off: "OFF"
      retain: true
ha-automation.yaml
alias: Shed load at night tariff end
trigger:
  - platform: time
    at: "07:00:00"
action:
  - service: switch.turn_off
    target: { entity_id: switch.load_1 }

Flash a ready firmware from the browser Paste your error into the AI Error Doctor

Build tips

  • Create a Home Assistant automation with a 2-minute delay and hysteresis to avoid flapping.
  • Keep the hub on a UPS so automations keep running during outages.

ESP32, Arduino and mini-PC: who does what

← ← All projects

Related ideas

⚠ Caution

Switch only low-voltage loads yourself. For mains loads use a certified isolated module in a box or call an electrician.

Router reboot when the internet dies

Pings a few addresses and, if the connection is really gone, power-cycles the router through a relay, with limits so it never reboot-loops.

  • Board ESP32-C3 SuperMini
  • Level ●●○ Intermediate
  • Build time 1–2 h
Pick parts / kit
⚠ Caution

Switch only low-voltage loads yourself. For mains loads use a certified isolated module in a box or call an electrician.

Smart watering timer

Waters plants by soil moisture or schedule with a 12 V pump and sends a notice when the tank is empty.

  • Board ESP32 DevKit V1 (WROOM-32)
  • Level ●●○ Intermediate
  • Build time 2–3 h
Pick parts / kit
⛔ High risk

Never replace the boiler's own safety thermostat or overheat protection. The ESP32 is only an extra controller; use a certified relay and a fuse.

Boiler thermostat

Holds the temperature of a boiler or heating loop with DS18B20 probes and a relay on the boiler's thermostat input.

  • Board ESP32 DevKit V1 (WROOM-32)
  • Level ●●○ Intermediate
  • Build time 2–3 h
Pick parts / kit

Comments

No comments yet. Share your experience or ask a question.

Comments are moderated.