DIY: Build Your Own Smart Plug Using ESP32 and Tasmota
Step-by-step DIY project to create a smart plug using an ESP32 module and Tasmota firmware. Hardware list, wiring, flashing, and safety notes included.
DIY: Build Your Own Smart Plug Using ESP32 and Tasmota
Building your own smart plug is a rewarding project for those who want full control over device behavior and privacy. This guide covers selecting hardware, wiring a relay and current sensor, flashing Tasmota firmware, and integrating the finished device with Home Assistant. Safety is paramount when dealing with mains power—if you are not comfortable with AC wiring, consult a licensed electrician.
What you need
- ESP32 development board or ESP8266 (ESP32 recommended)
- Relay module rated for mains voltage with an appropriate safety margin
- Current sensor such as SCT-013 or built-in energy monitoring supporting AC measurement
- Enclosure rated for mains use
- Soldering tools, insulated wiring, and a small breadboard or PCB
Safety first
Work on mains wiring only with power disconnected. Use insulated tools and keep all high-voltage connections inside the enclosure with strain relief. Ensure the relay is rated for the maximum load and add a fuse for extra protection. If you are uncertain at any point, stop and ask an expert.
Wiring overview
Basic wiring involves breaking the hot line of the AC input through the relay contacts, while the neutral line remains continuous. The current sensor is placed around the hot or neutral depending on the sensor type. The ESP32 is powered via a small isolated power supply or a mains-to-5V regulator with proper isolation.
- Connect mains hot to relay COM, and relay NO to the device hot lead.
- Connect neutrals directly together.
- Attach the current sensor around the hot conductor and wire its output to the ADC input on the ESP32 through a burden resistor and appropriate level shifting.
- Power the ESP32 from a regulated 5V supply with adequate mains isolation.
Flashing Tasmota
Tasmota provides a configurable firmware that supports many sensors, relays, and MQTT. To flash Tasmota:
- Install the Tasmota binary or use the web-based Tasmota tool to compile a custom firmware with your module settings.
- Flash via USB-to-serial adapter or OTA if the module already runs a compatible bootloader.
- Configure WiFi credentials and MQTT broker details in the web UI after the device boots.
Calibration and configuration
Once Tasmota is running, configure the GPIO pins for the relay and ADC. Use the web console to capture raw ADC readings and apply calibration constants derived from a reference meter. For SCT-013 sensors you may need to implement the burden resistor calculations and filter the readings in software.
Integrating with Home Assistant
Enable MQTT discovery in Home Assistant and configure the Tasmota device to publish to your broker. When configured correctly, the smart plug will appear automatically with switch and sensor entities. Create automations and energy dashboards as you would for any other smart plug.
Advantages and trade-offs
DIY smart plugs offer maximum privacy, firmware control, and lower long-term costs. However, they require effort, time, and technical skills. There is liability if something fails due to a wiring or design mistake, so weigh benefits against potential risks.
Final thoughts
For hobbyists and power users, making your own smart plug can be educational and practical. Stick to safety guidelines, use quality components, and test thoroughly before putting a device into daily use. With the right approach you gain a secure, local-first device tailored to your exact needs.