logo elektroda
logo elektroda
X
logo elektroda

ESP8266 and Tasmota - controlling the WiFi relay step by step

p.kaczmarek2 26781 57

TL;DR LABEL_AI_GENERATED

  • Builds a Sonoff-style WiFi relay using ESP8266-01, a 5V supply, a 5V relay, and Tasmota firmware for local Internet or LAN control.
  • Programs the ESP8266 with esptool.py, flashes tasmota.bin, then configures WiFi, module pins, and relay control through Tasmota’s web interface.
  • Measured consumption reached 140mA at 5V with the relay on and 70mA with it off, varying with WiFi traffic.
  • Controls the relay from the Tasmota Control phone app over HTTP without MQTT or a cloud broker, using the device’s IP or hostname.
  • DHCP can change the device’s IP, so a static address is recommended; the circuit also contains dangerous mains voltages and needs a proper enclosure.
AI summary based on the discussion. May contain errors.
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
Listen:
  • #31 21923174
    inot
    Level 38  
    Posts: 3619
    Help: 449
    Rate: 818
    How do the LEDs on the USB converter react when an attempt is made to transmit data or when power is supplied to the ESP module?
  • ADVERTISEMENT
  • #32 21923381
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14770
    Help: 659
    Rate: 12913
    What is the error shown by esptool?
    Helpful post? Buy me a coffee.
  • #33 21923490
    Blisk
    Level 9  
    Posts: 51
    >>21923174 When I connect it with no 3.3V red light is on and middle blue, when I connect 3.3V than middle blue is off and third blue is blinking and than I get error no connection

    Added after 44 [seconds]:

    >>21923381 error is connection time out
  • ADVERTISEMENT
  • #34 21923547
    inot
    Level 38  
    Posts: 3619
    Help: 449
    Rate: 818
    >>21923381
    I meant the LEDs on the USB adapter (marked with a circle).
    Red USB-to-TTL module with USB-A plug and header pins labeled RXD, TXD, GND, +5V
  • #35 21923580
    Blisk
    Level 9  
    Posts: 51
    >>21923547 I meant that too, one red and 2 blue.
    when I disconnect 3.3v middle blue is light when I connect 3.3V middle blue is gone and last blue is blinking. after that I get connection time out.
  • #36 21924364
    inot
    Level 38  
    Posts: 3619
    Help: 449
    Rate: 818
    >>21923547 It follows from this that the ESP8266 is not transmitting any information. If possible, it would be worth measuring the signals using an oscilloscope.
  • #37 21924367
    Blisk
    Level 9  
    Posts: 51
    >>21924364 you mean TX and RX? I will meassure that
  • #38 21924371
    inot
    Level 38  
    Posts: 3619
    Help: 449
    Rate: 818
    Blisk wrote:
    you mean TX and RX?

    Yes.
  • GPIO0 grounded for ESP8266 flashing mode

    #39 21927150
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14770
    Help: 659
    Rate: 12913
    I've got a device from @Blisk to diagnose and it flashes just fine.

    I've soldered a tiny wire to short GPIO0 to ground to put ESP in the flasher mode.

    I used 5V pin on the board, because board has LDO 3.3V on it, so it powers ESP correctly from 3.3 V.
    ESP8266 and Tasmota - controlling the WiFi relay step by step ESP8266 and Tasmota - controlling the WiFi relay step by step ESP8266 and Tasmota - controlling the WiFi relay step by step ESP8266 and Tasmota - controlling the WiFi relay step by step Relay module with blue Songle 12V relay and ESP-01 board, held in a hand Two electronic boards: a Songle 12V relay module and a smaller pin header module on a white surface

    Windows cmd.exe screenshot: esptool.py reading ESP8266 flash via COM3, 45% progress

    I will attempt to flash Tasmota next.
    Helpful post? Buy me a coffee.
  • #40 21927179
    inot
    Level 38  
    Posts: 3619
    Help: 449
    Rate: 818
    >>21927150
    As shown in the last attachment, communication with the ESP8266 is working, so it is difficult to understand why the original poster was unable to achieve this result.
  • ADVERTISEMENT
  • UART-controlled relay uses programming lines

    #41 21927216
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14770
    Help: 659
    Rate: 12913
    Ah, I just realized what was wrong. This module has a relay that is controlled via UART, which uses same lines that are used for programming. It worked for me , because I removed the jumpers upfront.
    ESP8266 and Tasmota - controlling the WiFi relay step by step

    Close-up of a PCB with a relay and buttons; two small black jumper caps lie beside it.

    Added after 1 [minutes]:

    Yes! I can see it on his image as well:
    Relay module on a wooden desk with connected wires and red handwritten annotations

    That solves it...

    Added after 1 [minutes]:

    https://tasmota.github.io/docs/devices/LC-Tec...-Relay/#lc-technology-wifi-relay-single-relay
    Quote:
    LC Technology WiFi Relay - Single Relay~
    The LC Technology relay devices use GPIO1 and GPIO3 for the serial communications used to control the relays. You do not need to specify these in the template. SerialSend uses these standard serial communications GPIO by default.
    Helpful post? Buy me a coffee.
  • Flashing Tasmota on ESP8266 relay module fails

    #42 21927946
    Blisk
    Level 9  
    Posts: 51
    inot wrote:
    >>21927150
    As shown in the last attachment, communication with the ESP8266 is working, so it is difficult to understand why the original poster was unable to achieve this result.

    I tried to flash it with that module mounted on relay or just module and nothing worked, I hope there is a way to upload tasmota. tasmota didn't connect with it.
    I even don't know how to use it withouth flasihn it, so I contacted seller and he give me some manuals which still don't know how.
    https://www.aliexpress.com/item/4001094436563...der_detail.order_detail_item.4.41cd126aGeHOu1
  • #43 21928006
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14770
    Help: 659
    Rate: 12913
    It's as I said - you need to remove the two jumpers. Do you have any more pieces at hand, besides the one you sent me? You can remove them and try.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #44 21928154
    Blisk
    Level 9  
    Posts: 51
    >>21928006 I have another module with 2 relays I will try and post pictures here
  • #45 21928193
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14770
    Help: 659
    Rate: 12913
    Please remove 2 jumpers (RX and TX jumpers) and try flashing it. First do flash read, ok? Flash backup.
    Helpful post? Buy me a coffee.
  • #46 21928281
    Blisk
    Level 9  
    Posts: 51
    >>21928193 Do I need to GPIO0 to ground and than flash it or not?
    Just TX, RX, GND and 5V
  • #47 21928293
    inot
    Level 38  
    Posts: 3619
    Help: 449
    Rate: 818
    Connect GPIO0 to ground only when flashing. You can first check if the ESP responds when the jumpers are removed.
  • #48 21928327
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14770
    Help: 659
    Rate: 12913
    Yes, connecting GPIO0 to ground is required to put ESP in the flasher mode. It's just as I shown in the previous post with the device you've sent to me:
    ESP8266 and Tasmota - controlling the WiFi relay step by step
    Helpful post? Buy me a coffee.
  • #49 21928595
    Blisk
    Level 9  
    Posts: 51
    >>21928327 how did you download firmware from board?
    I manage to upload tasmota on a relay module, I tried 5 times and at last it uploads
  • #50 21928752
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14770
    Help: 659
    Rate: 12913
    I usually use esptoo to make a 2MB (or depending on flash size) backup of ESP8266:
    
    esptool.py read_flash 0x00000 0x200000 backup.bin
    
    Helpful post? Buy me a coffee.
  • #51 21930484
    Blisk
    Level 9  
    Posts: 51
    Now I am trying to make this relay ON and OFF, but doesn't work, what I need to steup under module?
    Screenshot of Tasmota configuration for Sonoff Basic with GPIO dropdowns and a Save button

    Tasmota configuration screen for Sonoff Basic showing GPIO dropdowns and a “Save” button.
  • #52 21930652
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14770
    Help: 659
    Rate: 12913
    I haven't managed to make a guide for it myself yet, but according to Tasmota page, you need to script it to use UART.
    Screenshot of Tasmota UART setup instructions with step list and console rules code blocks.
    Helpful post? Buy me a coffee.
  • MQTT connection failure blocks relay control

    #53 21931022
    Blisk
    Level 9  
    Posts: 51
    >>21930652
    on off still doesn't work

    Screenshot of Tasmota-switch configuration showing GPIO list and a Relay setting

    this is what I get
    00:00:00.001 HDW: ESP8266EX
    00:00:00.050 CFG: Loaded from flash at F6, Count 76
    00:00:00.056 QPC: Count 1
    00:00:00.068 Project tasmota - Tasmora-switch Version 15.3.0(release-tasmota)-2.7.8(2026-02-19T13:51:25)
    00:00:01.001 WIF: Connecting to AP1 TOM-FIN Channel 7 BSSId 70:4F:57:8F:0F:9F in mode 11n as tasmota-EB6B5A-2906...
    00:00:02.514 WIF: Connected
    00:00:02.767 HTP: Web server active on tasmota-EB6B5A-2906 with IP address 192.168.1.154
    16:10:38.049 MQT: Attempting connection...
    16:10:38.259 MQT: Connect failed to 192.168.1.197:1883, rc -2. Retry in 10 sec
    16:10:40.258 QPC: Reset
    16:10:49.594 MQT: Attempting connection...
    16:10:49.769 MQT: Connect failed to 192.168.1.197:1883, rc 5. Retry in 20 sec
    16:11:10.081 CMD: seriallog 0
    16:11:10.084 RSL: RESULT = {"SerialLog":{"0":{"Active":"0"}}}
    16:11:14.895 MQT: Attempting connection...
    16:11:15.034 MQT: Connect failed to 192.168.1.197:1883, rc 5. Retry in 30 sec
    16:11:47.168 MQT: Attempting connection...
    16:11:47.663 MQT: Connect failed to 192.168.1.197:1883, rc 5. Retry in 40 sec
    16:12:29.491 MQT: Attempting connection...
    16:12:32.459 MQT: Connect failed to 192.168.1.197:1883, rc 5. Retry in 50 sec
    16:13:23.875 MQT: Attempting connection...
    16:13:27.011 MQT: Connect failed to 192.168.1.197:1883, rc 5. Retry in 60 sec
    16:13:34.523 CMD: on system#boot do backlog baudrate 9600; serialsend5 0 endon
    16:13:34.529 RSL: RESULT = {"Command":"Unknown","Input":"ON system#boot do backlog baudrate 9600; serialsend5 0 endon"}
    16:14:30.538 MQT: Attempting connection...
    16:14:31.956 MQT: Connect failed to 192.168.1.197:1883, rc 5. Retry in 70 sec
    16:14:53.811 CMD: on power#state=1  do serialsend5 A00101A2 endon
    16:14:53.817 RSL: RESULT = {"Command":"Unknown","Input":"ON power#state=1  do serialsend5 A00101A2 endon"}
    16:15:43.963 MQT: Attempting connection...
    16:15:44.173 MQT: Connect failed to 192.168.1.197:1883, rc -2. Retry in 80 sec
    16:15:45.032 RSL: STATE = {"Time":"2026-07-01T16:15:45","Uptime":"0T00:05:13","UptimeSec":313,"Heap":24,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":22,"MqttCount":0,"POWER":"OFF","Wifi":{"AP":1,"SSId":"TOM-FIN","BSSId":"70:4F:57:8F:0F:9F","Channel":7,"Mode":"11n","RSSI":24,"Signal":-88,"LinkCount":1,"Downtime":"0T00:00:04"},"Hostname":"tasmota-EB6B5A-2906","IPAddress":"192.168.1.154"}
    16:15:53.085 CMD: on power1#state=1  do serialsend5 A00101A2 endon
    16:15:53.090 RSL: RESULT = {"Command":"Unknown","Input":"ON power1#state=1  do serialsend5 A00101A2 endon"}
    16:16:23.834 CMD: on power1#state=1  do serialsend5 A00100A1 endon
    16:16:23.839 RSL: RESULT = {"Command":"Unknown","Input":"ON power1#state=1  do serialsend5 A00100A1 endon"}
    16:17:09.573 MQT: Attempting connection...
    16:17:09.674 MQT: Connect failed to 192.168.1.197:1883, rc 5. Retry in 90 sec
    16:18:42.100 MQT: Attempting connection...
    16:18:42.590 MQT: Connect failed to 192.168.1.197:1883, rc 5. Retry in 100 sec
    16:18:44.376 CMD: on power1#boot do backlog baudrate 9600; serialsend5 0 endon
    16:18:44.382 RSL: RESULT = {"Command":"Unknown","Input":"ON power1#boot do backlog baudrate 9600; serialsend5 0 endon"}
    16:19:14.819 CMD: on power1#state=1  do serialsend5 A00101A2 endon
    16:19:14.824 RSL: RESULT = {"Command":"Unknown","Input":"ON power1#state=1  do serialsend5 A00101A2 endon"}
  • #54 21931080
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14770
    Help: 659
    Rate: 12913
    Did Tasmota change something? Well, in worst case, I can run OBK port on it. OpenESP8266. Probably.
    Helpful post? Buy me a coffee.
  • #55 21931141
    Blisk
    Level 9  
    Posts: 51
    >>21931080 hardly to tell, I only notice that sometimes just wont connect at all than after 10 minutes connection is ok
  • #56 21931381
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14770
    Help: 659
    Rate: 12913
    It also seem to mark your commands as unknown:
    
    16:19:14.819 CMD: on power1#state=1  do serialsend5 A00101A2 endon
    16:19:14.824 RSL: RESULT = {"Command":"Unknown","Input":"ON power1#state=1  do serialsend5 A00101A2 endon"}
    
    Helpful post? Buy me a coffee.
  • #57 21931600
    Blisk
    Level 9  
    Posts: 51
    >>21931381 yes I see that and don''t know why
    Did that worked on module I send you?
    I think I found out a problem, module is 12V not 5V, I will test it with 5V and see.
  • Tasmota rule sends relay commands over serial

    #58 21932703
    Blisk
    Level 9  
    Posts: 51
    now I have tested on 5V module but still not working

    Added after 29 [minutes]:

    I manage to solve this with chatgpt , now work ok
    ESP8266 and Tasmota - controlling the WiFi relay step by step
    Backlog SerialLog 0; Baudrate 115200; Rule1 0
    Rule1 ON System#Boot DO Backlog SerialLog 0; Baudrate 115200 ENDON ON Power1#State=1 DO SerialSend5 A00101A2 ENDON ON Power1#State=0 DO SerialSend5 A00100A1 ENDON
    Rule1 1
    Restart 1
Listen:

Topic summary

LABEL_AI_GENERATED
The discussion presents a step-by-step DIY IoT WiFi relay controller based on ESP8266, relay module, power supply, and Tasmota firmware, intended as a universal alternative to ready-made Sonoff-style devices. The topic covers GPIO/Dx pin mapping in Arduino Core, device identification by hostname versus fixed IP or MAC reservation, and local-network control from a phone app without a broker. Later replies address remote access options such as port forwarding, VPN, clouds, MQTT, and Node-RED, as well as flashing problems on relay boards where UART lines were shared with the relay circuitry. The troubleshooting concludes that removing RX/TX jumpers, using GPIO0 to enter flashing mode, checking UART communication, and backing up flash with esptool are necessary. For relay control after flashing, Tasmota rules and serial commands are used to drive the UART-controlled relay, and the final working configuration is implemented with Rule1 and SerialSend commands.
AI summary based on the discussion. May contain errors.

FAQ LABEL_AI_GENERATED

TL;DR: A single-relay ESP8266 with Tasmota draws only 0.7 W at 5 V (“almost like a Sonoff”)[Elektroda, p.kaczmarek2, post #19130883] "Sonoff is not a magic black box"[Elektroda, p.kaczmarek2, post #19132603] Set static IP or hostname, then control via HTTP or MQTT—no cloud needed.

Why it matters: DIY Wi-Fi switching costs little, keeps data local and scales with open-source firmware.

Quick Facts

• ESP8266-01 must run at 3.3 V; 5 V will destroy it[Elektroda, p.kaczmarek2, post #19130883] • Relay SRD-05VDC-SL-C coil voltage: 5 V[Elektroda, p.kaczmarek2, post #19130883] • Total current: 140 mA (0.7 W) relay on; 70 mA (0.35 W) off[Elektroda, p.kaczmarek2, post #19130883] • Tasmota config AP appears as “tasmota_xxxx”; browse 192.168.4.1 after flash[Elektroda, p.kaczmarek2, post #19130883] • Static address via console: IPAddress 192.168.x.y, or rely on hostname[Elektroda, khoam, post #19131175]

What parts do I need for a basic Wi-Fi relay?

You need an ESP8266-01 module, 5 V 500 mA flyback PSU, 3.3 V LDO, SRD-05VDC-SL-C relay, NPN transistor (BC547 or 2N7002), flyback diode, button, capacitors and resistors[Elektroda, p.kaczmarek2, post #19130883] Total hardware fits on a small perf-board and costs under €5 in retail parts.

How do I flash Tasmota onto the ESP8266-01?

  1. Connect USB-UART (3.3 V logic) to TX/RX.
  2. Tie GPIO0 to GND, then power the board.
  3. Run “esptool.py write_flash 0x0 tasmota.bin”.
  4. Remove GPIO0 from GND and reset.[Elektroda, p.kaczmarek2, post #19130883] Flash time is about 8 s over 921 600 baud.

Why do I need a 3.3 V regulator when I already have 5 V?

The ESP8266 core tolerates max 3.6 V. Supplying 5 V permanently damages the RF front-end—an irreversible failure edge-case[Elektroda, p.kaczmarek2, post #19130883] Use an LDO such as MCP1702 to drop 5 V to 3.3 V.

How do I map the relay and button inside Tasmota?

Open 192.168.x.x → Configuration → Configure Module. Assign GPIO0 or GPIO2 as “Relay1”, and another pin as “Button1”. Save and reboot; a toggle button appears on the web UI[Elektroda, p.kaczmarek2, post #19130883]

Can I control the relay from my phone without MQTT?

Yes. Apps such as Tasmota Control send plain HTTP commands (e.g., /cm?cmnd=Power%%20TOGGLE). They poll status every few seconds, so no broker is required[Elektroda, p.kaczmarek2, post #19130883]

Is internet-wide access possible?

Local control is default. For global reach, forward port 80, run a VPN, or expose an MQTT broker then use Node-RED dashboards[Elektroda, xury, post #19133954]

What power does the circuit consume?

With Wi-Fi active and relay on, draw peaks at 140 mA (0.7 W). Relay off sinks about 70 mA (0.35 W)[Elektroda, p.kaczmarek2, post #19130883] Idle Wi-Fi sleep can drop current to 20 mA, extending PSU headroom.

What happens if I leave GPIO0 grounded after flashing?

The ESP stays in bootloader mode and never runs Tasmota, appearing “dead” on Wi-Fi. Lift GPIO0, reset, and it boots normally[Elektroda, p.kaczmarek2, post #19130883]

How do I reserve an IP via DHCP?

Locate the ESP MAC in the router’s client list, then add a DHCP reservation linking that MAC to your chosen IP[Elektroda, p.kaczmarek2, post #19133249] Most SOHO routers expose this under LAN → DHCP Settings.

Can I change the ESP8266 MAC address?

Yes, call wifi_set_macaddr() in the Arduino Core. "Useful when cloning devices for testing"[Elektroda, khoam, post #19133412] Remember to keep it unique to avoid network conflicts.

How can I scale to multiple inputs and outputs?

Add I²C GPIO expanders (e.g., PCF8574) and map their pins in Tasmota’s Configure Template menu. Eight devices give 64 lines without firmware changes. Control remains through the same HTTP or MQTT endpoints.“}]}
AI summary based on the discussion. May contain errors.
ADVERTISEMENT