Level: Advanced Board: ESP32 DevKit V1 (WROOM-32) Smart home
⚠ SafetyHeavy 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
Relay module 1-channel 5V (opto-isolated) × 1
$1.50
Budget mini-PC Intel N100 (8 GB / 256 GB) × 1
$130.00
Zigbee USB coordinator (CC2652 / ZBDongle) × 1
$22.00
USB SSD 120-240 GB + SATA-USB adapter × 1
$20.00
USB charger 5V 2A × 1
$4.00
Some links are affiliate links: we may earn a commission at no extra cost to you.
Libraries
Arduino IDE → Tools → Manage Libraries, then install:
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
⚠ CautionSwitch only low-voltage loads yourself. For mains loads use a certified isolated module in a box or call an electrician.
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.
⚠ CautionSwitch only low-voltage loads yourself. For mains loads use a certified isolated module in a box or call an electrician.
Waters plants by soil moisture or schedule with a 12 V pump and sends a notice when the tank is empty.
⛔ High riskNever replace the boiler's own safety thermostat or overheat protection. The ESP32 is only an extra controller; use a certified relay and a fuse.
Holds the temperature of a boiler or heating loop with DS18B20 probes and a relay on the boiler's thermostat input.
Comments
No comments yet. Share your experience or ask a question.