Controlling lighting via a smartphone or voice assistant is no longer a fantasy - all you need to do is assemble WiFi switch Do it yourself. Such a project will cost 2-3 times less than ready-made solutions from Xiaomi or Sonoff, and the functionality can be adapted to your needs: from simply turning on a lamp to integration with Home Assistant or Google Home.
In this article you will find Current connection diagrams for 2026, taking into account the new ESP32-C6 and ESP8266-S3 modules, step-by-step instructions for flashing (including alternatives Tasmota And ESPHome), as well as solutions to common problems—from connection drops to router conflicts. We'll cover options for both experienced radio enthusiasts (soldering and MQTT setup) and beginners (ready-made boards from AliExpress).
1. Choosing Components: What to Buy for a WiFi Switch
The basis of the homemade switch is WiFi module And relayTheir choice determines operational stability, energy consumption, and compatibility with smart home systems. The following options are relevant in 2026:
- 📶 ESP8266 (NodeMCU, Wemos D1 Mini) — a budget option for simple tasks. It supports 2.4 GHz, but can be slow when there are many devices on the network.
- 🚀 ESP32 (ESP32-C3, ESP32-S3) — optimal for complex scenarios (for example, with motion sensors). Operates on 2.4 GHz and 5 GHz (in newer versions) and has more memory for firmware.
- ⚡ Ready-made Sonoff Basic or Shelly 1 boards — if you don't want to solder. They already contain relays and connectors, but require reflashing for full control.
For relays, select modules with opto-isolator (For example, Songle SRD-05VDC-SL-C) — they protect the microcontroller from power surges in the 220V network. The relay's power must exceed the lamp/device load by at least 30%. For example, a 10A relay is sufficient for a 100W LED strip, while a 2kW heater requires a 16A module.
| Component | Model/Type | Price (2026) | Where to buy |
|---|---|---|---|
| WiFi module | ESP32-C6-DevKit | 800–1200 ₽ | AliExpress, Chip and Dip |
| Relay | Songle SRD-05VDC (10A) | 150–300 ₽ | AliExpress, I'll take it! |
| power unit | 5V/1A (for ESP) | 100–200 ₽ | Any electronics store |
| Frame | 60mm flush-mounted box or 3D printing | 50–500 ₽ | Leroy Merlin, Thingiverse |
⚠️ Attention: If you choose ready-made devices (Sonoff, Shelly), check their compatibility with your router. Some models conflict with networks where802.11r (Fast Roaming)orWPA3-Enterprise.
2. Connection diagrams: from simple to complex
The scheme depends on whether you will be driving one lamp or several channels (for example, a chandelier with separate groups of lamps). Below are three proven circuits with pin assignments for ESP8266 And ESP32.
Scheme 1. Single-channel switch (ESP8266 + relay)
220V → Relay (NO) → Lamp → 220V (N)
ESP8266:
- GPIO5 → IN (relay)
- VIN → 5V (power supply)
- GND → GND
Scheme 2. Two-channel switch (ESP32 + 2 relays)
ESP32:
- GPIO18 → Relay 1 (IN)
- GPIO19 → Relay 2 (IN)
- 5V → VCC (relay and ESP)
- GND → GND
Scheme 3. Switch with button (for manual control)
ESP8266:
- GPIO4 → Button (with pull-up to 3.3V)
- GPIO5 → Relay (IN)
- When the button is pressed, the ESP sends a command to switch the relay
3. Firmware: Tasmota vs. ESPHome vs. Custom Logic
The firmware determines how you will control the switch: through MQTT, the manufacturer's cloud, or a local network. Let's consider three popular options:
- 🔧 Tasmota — universal firmware with a web interface. Supports Home Assistant, Google Home, AlexaDisadvantage: Requires manual configuration.
- 🏠 ESPHome - ideal for integration with Home AssistantAllows you to write configs in YAML, but is more difficult to set up for beginners.
- ☁️ Proprietary software (For Sonoff/Shelly) - simplicity, but dependence on the cloud and limited functionality.
To flash you will need:
- Download Tasmota or ESPHome from the official website.
- Connect ESP to computer via USB.
- IN Arduino IDE or PlatformIO select board (
ESP8266 NodeMCUorESP32 Dev Module). - Download firmware via
Tools → Burn Bootloader(if necessary) andSketch → Upload.
Download Arduino IDE or PlatformIO|
Install drivers for ESP|
Select the correct board in the settings|
Disable antivirus (may block download)|
Connect the ESP to USB 2.0 (USB 3.0 may cause errors)
-->
After flashing:
- Connect to an access point
tasmota-xxxxoresphome-web. - Enter your WiFi network details.
- Set up
MQTT(if you use Home Assistant) or cloud service.
⚠️ Attention: When flashing Sonoff Basic throughTX/RXthe pins need to be shortedGPIO0onGNDbefore applying power, otherwise the bootloader will not activate.
4. Smartphone setup: apps and integrations
After assembly and firmware installation, the switch needs to be connected to the control system. Let's consider three methods:
- 📱 eWeLink application (For Sonoff) is simple, but requires registration and works through the cloud. Supports voice commands for Alice's And Google Assistant.
- 🏡 Home Assistant — local management without the cloud. You need to add the device through
Integration → MQTTorESPHome. - 🗣️ Voice assistants - for this in the settings Tasmota turn on
Enable AlexaorEnable Google Home.
Example of setting in Home Assistant (For ESPHome):
Configuration fragment configuration.yaml
switch:
- platform: mqtt
Name: "Light in the Hallway"
command_topic: "cmnd/sonoff_power1/Power"
state_topic: "stat/sonoff_power1/POWER"
payload_on: "ON"
payload_off: "OFF"
For Tasmota use standard MQTT commands:
cmnd/<device>/Power ON- turn on;cmnd/<device>/Power OFF— turn off;cmnd/<device>/Status 10— status request (every 10 seconds).
5. Installation and assembly: safety rules
Before installing the switch in the electrical network Necessarily Disconnect the power at the panel and check for voltage with a voltage indicator. Even the low-voltage part (ESP and relay) must be isolated from 220V!
Step-by-step installation:
- Secure the board to the enclosure (socket box or junction box).
- Connect
phase (L)to one relay contact, andzero (N)- directly to the lamp. - Withdraw
relay output (NO)to the lamp. - Connect the 5V power supply to the ESP and the relay (if active).
Accommodation options:
- 🔌 Instead of a regular switch — If you're using the housing from an old switch, you'll need to run a 5V power cable inside the wall.
- 📦 In the junction box — if you don't want to damage your walls. Cons: you'll only have to control it from your smartphone.
- 🖥️ In a separate housing next to the lamp — for table lamps or garlands.
⚠️ Attention: If you are installing the switch in a bathroom or outdoors, use an enclosure with a protection class IP65 and sealed terminal blocks. ESP and relays are sensitive to moisture!
6. Troubleshooting: Why the WiFi Switch Doesn't Work
Typical malfunctions and how to fix them:
| Problem | Possible cause | Solution |
|---|---|---|
| Doesn't connect to WiFi | Incorrect password or incompatible network mode (e.g. 5 GHz only) | Check the SSID/password. Switch the router to wireless mode. 802.11b/g/n (2.4 GHz) |
| The lamp flickers or does not turn on | Weak contact in the relay or incorrect wiring diagram | Test the circuit with a multimeter. Check that the phase is going through the relay, not the neutral. |
| ESP reboots | Insufficient power supply (500mA block does not power the relay) | Use a 1A+ power supply or a 1000uF capacitor on the 5V line. |
| Doesn't respond to MQTT commands | Incorrect topic or the broker is not running |
Check the settings in configuration.yaml (Home Assistant) or in the console Tasmota |
If the switch operates erratically (for example, it switches off after 10 minutes), the cause may be:
- 🔋 Router energy saving mode — turn it off
WiFi Power Savein the settings; - 📶 Weak WiFi signal - install a repeater or use ESP with an external antenna;
- ⚡ Interference from other devices — change the WiFi channel to 1, 6 or 11 (manually).
How to check the quality of soldering?
Use a magnifying glass or your smartphone's macro lens to inspect the contacts. A good solder joint should be shiny, without cracks or solder snot. If the contact is dull or porous, resolder it with flux.
7. Advanced features: timers, sensors, voice control
The basic WiFi switch can be expanded with additional features:
- ⏰ Timers and schedules - V Tasmota configure via
Configuration → Timers. Example:0 8 1-5 ON(turn on at 8:00 on weekdays). - 👁️ Motion sensor — connect HC-SR501 to GPIO. B ESPHome add:
binary_sensor:- platform: gpio
pin: GPIO14
Name: "Movement in the Hallway" - 🌡️ Temperature control - use the sensor DHT22 and the rule is in Home Assistant:
automation:trigger:
platform: numeric_state
entity_id: sensor.temperature
above: 25
action:
service: switch.turn_on
entity_id: switch.ventilation
For voice control via Alice (Yandex) or Google Assistant:
- IN Tasmota turn on
Enable Alexain the settings. - In the assistant app, add the device via
Smart Home → Add Device. - Say: "Alice, turn on the light in the hallway" (the name must match
Friendly NameV Tasmota).
FAQ: Answers to frequently asked questions
Is it possible to make a WiFi switch without soldering?
Yes, if you use ready-made modules:
- Sonoff Basic - it's enough to flash through
USB-TTLadapter; - Shelly 1 - supports OTA updates (without physical connection);
- Ready-made boards with terminal blocks (for example, Wemos D1 Mini + relay-shield).
To connect to a 220V network, use terminal blocks Wago - they do not require soldering.
Which WiFi module is better: ESP8266 or ESP32?
The choice depends on the task:
- ESP8266 Cheaper and easier for beginners. Suitable for 1-2 relays.
- ESP32 needed if required:
- simultaneous control of 4+ relays;
- connection of sensors (temperature, illumination);
- operation in 5 GHz network (in new chip versions).
For most switches this is enough ESP8266, but if you plan to expand your smart home system, take it ESP32.
How to make a switch with a mechanical button?
Add a tact switch to the circuit, connected to a free GPIO. Example for ESPHome:
binary_sensor:- platform: gpio
pin:
number: GPIO0
mode: INPUT_PULLUP
inverted: true
name: "Mechanical button"
on_press:
then:
- switch.toggle: relay_1
IN Tasmota use the command SwitchMode1 3 (toggle mode) and bind the button to the GPIO in Configuration → Configure Module.
Why does my switch lose WiFi connection?
Common causes and solutions:
- Weak signal - install a repeater or move the router closer.
- Router overload - limit the number of connected devices or turn on
QoS. - IP conflict — in the ESP settings, set a static IP outside the router's DHCP pool.
- DNS issues - V Tasmota write down
DNS 8.8.8.8.
If the problem persists, check your router logs for authentication errors.
Is it possible to control the switch via the Internet (from another network)?summary>
Yes, but this requires one of the options:
- Cloud service — Tasmota supports MQTT brokers like CloudMQTT or HiveMQ;
- Port forwarding — Forward the port on the router
8080 on the switch IP (not secure without VPN!);
- VPN — set up WireGuard or OpenVPN on a router or Raspberry Pi;
- Home Assistant with remote access - through Nabu Casa or DuckDNS.
For security, use complex passwords and disable default access (admin/admin).
8080 on the switch IP (not secure without VPN!);admin/admin).