Mains 220–230 V can kill. Work with the power off, use certified isolated modules in an enclosure, fuse the line, and ask a qualified electrician if you are not sure.
Local rules that do not depend on the cloud
A mini-PC with Home Assistant and a Zigbee USB dongle is a small, quiet, always-on controller, and automations run on it even without internet. The ESP32-C6 can join the Zigbee network as a router or an end device and switch a load through a relay.
Zigbee is picky about its radio neighbours
Plug the dongle on a short USB extension cable, away from USB 3 ports and SSDs, which produce noise in the 2.4 GHz band.
Pick a Zigbee channel that does not overlap your Wi-Fi: with Wi-Fi on channels 1, 6 and 11, the Zigbee channels 15, 20 and 25 are the usual choices.
Mains-powered devices act as routers and strengthen the mesh; battery ones do not.
Check the current status of the Zigbee support for the C6 in the Arduino-ESP32 or ESP-IDF version you use before you plan around it, because this area changes quickly. A typical mini-PC draws several watts when idle, so a small UPS keeps it running for many hours.
Components
ESP32-C6 DevKitC-1
Relay module 1-channel 5V (opto-isolated)
Budget mini-PC Intel N100 (8 GB / 256 GB)
Zigbee USB coordinator (CC2652 / ZBDongle)
USB SSD 120-240 GB + SATA-USB adapter
USB charger 5V 2A
Wiring
Module
Module pin
ESP32 pin
Note
Relay IN
signal
GPIO26
active LOW, dry-contact control only
Zigbee USB stick
USB
mini-PC USB (use an extension cable)
away from USB 3 ports
Libraries
PubSubClient
Code
#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();
}
Comments
No comments yet. Share your experience or ask a question.