logo elektroda
logo elektroda
X
logo elektroda
Dostępna jest polska wersja

Czy wolisz polską wersję strony elektroda?

Nie, dziękuję Przekieruj mnie tam

[ESP32] How to change Sonoff THR320D firmware? Flashing Tasmota. Where is GPIO0?

p.kaczmarek2  11 6141 Cool? (+4)
📢 Listen (AI):

TL;DR

  • Sonoff THR320D thermostat with display was opened, inspected, and converted from eWeLink firmware to Tasmota for cloud-free Home Assistant use.
  • The ESP32 is mounted directly on the PCB, and flashing uses only four pads because GPIO0 is on the button and must be held low at boot.
  • The Tasmota template maps the TM1621 display plus relay, LED, and sensor GPIO roles, including GPIO00, GPIO04, GPIO05, GPIO13, GPIO15, GPIO16, GPIO17, GPIO18, GPIO19, GPIO22, GPIO23, and GPIO27.
  • After flashing, the display still worked and DS18B20 temperature sensing was checked successfully, but humidity reporting from the original firmware was no longer present.
Sonoff THR320D thermostat with a display showing 23.8°C.
Some time ago I showed the Sonoff THR320D thermostat with display and presented the possibilities of the eWeLink application. This time I will continue discussing this product, but here I will focus on its interior and on changing its firmware to Tasmota, so as to completely free it from the cloud and pair it with Home Assistant on our terms.

Previous topic:
[ESP32] Thermostat with display and WiFi - Sonoff THR320D - eWeLink application

Information about purchasing the product is in the previous topic, so let's start with the inside.
THR320D interior
This product is distinguished by its solid construction. There are no breakable hooks. Unscrew the screws:
Back cover of the Sonoff THR320D thermostat on a wooden surface. Sonoff THR320D thermostat case lying on a wooden surface.
At first glance it's not that bad, there are some protections at the input, there is even a varistor, a filter capacitor, you can also see a relay, a programming connector and a small transformer with a characteristic Y capacitor, i.e. there is a flyback power supply inside..
Interior of a disassembled Sonoff THR320D thermostat with visible electronic components. Interior of the Sonoff THR320D device with visible PCB and electronic components.
There is no WiFi module inside, ESP32 is located directly on the PCB, you can see the flash memory right next to it:
Interior of the Sonoff THR320D thermostat showing the PCB.
The PCB can be removed and we will see the display controller and the WiFi antenna:
Sonoff THR320D circuit board with TM1621B chip. Image of the interior of the Sonoff THR320D thermostat showing the PCB and casing.
The display supports TM1621:
Documentation page for the TM1621 LCD driver from Titan Micro Electronics. Pin diagram of the TM1621 LCD driver from Titan Micro Electronics. Diagram of the TM1621 LCD driver by Titan Micro Electronics
We also see details of the power supply section and the LP3667 controller:
Close-up of the Sonoff THR320D thermostat PCB.
A simplified diagram of such a converter:
Schematic diagram of a flyback converter with LP3667
In the corner I also see a step down converter generating 3.3V for ESP, you can also tell it by the presence of a choke, by the way, it's interesting that they put so many ceramic capacitors there:
PCB of Sonoff THR320D thermostat with TM1621B chip. Sonoff THR320D circuit board with visible electronic components
The already mentioned WiFi antenna:
Interior of the Sonoff THR320D thermostat casing with visible components.
ESP:
Close-up of the PCB from the Sonoff THR320D thermostat with visible electronic components.
The photo above also shows programming pads, but there are only 4...

Firmware change
You need to start with the fact that IO0 is located on the button, so we solder 4 wires, not 5. As standard, a USB to UART converter (RX and TX) and ground and power supply (3.3V). To load the firmwarwe, first press the button and then connect the programmer's power supply so that IO0 is at low level while the device is booting.
Then you can upload Tasmota, e.g. using the online installer:
How to easily install Tasmota - online installer tasmota.github.io/install via a web browser
However, I used esptool myself:
Windows console with esptool program running for ESP32. Console with firmware loading process on ESP32. Console output showing the flashing process of an ESP32 chip using esptool.
The THR320D template is available online:
{"NAME":"Sonoff THR320D","GPIO":[32,0,0,0,226,9280,0,0,0,321,0,576,320,9184,9216,9312,0,0,9313,9248,0,1,0,3840,0,0,0,0,0,0,0,0,0,0,0,0],"FLAG":0,"BASE":1}

GPIO roles:
- GPIO00 - Button 1
- GPIO04 - Relay 3
- GPIO05 - TM1621 DAT
- GPIO13 - Led_i 2
- GPIO15 - LedLinks
- GPIO16 - Led_i 1
- GPIO17 - TM1621 CS
- GPIO18 - TM1621 WR
- GPIO19 - Relay_b 1
- GPIO22 - Relay_b 2
- GPIO23 - TM1621 RD
- GPIO27 - Output Hi
Template activation:
Screenshot of Tasmota interface on ESP32-DevKit
Then you need to select the roles for the GPIO sensors, because there may be different sensors, I only checked with DS18B20:
Screenshot of the Tasmota configuration interface for Sonoff THR320D.
Result:
Tasmota user interface with DS18B20 temperature on a Sonoff THR320D thermostat
Of course, the display still works, the template takes into account its operation, although now it no longer displays anything about humidity like the original firmware:
Sonoff THR320D thermostat displaying temperature 34.2°C Sonoff THR320D thermostat with display showing a temperature of 35.2°C.
And the temperature in the photo is high because I heated the sensor with a lamp to test:
Close-up of a hand holding a wire next to an LED strip.
Everything seems to be working.

Summary
I already mentioned it in the previous part, but I highly praise all IoT products that are able to operate completely without WiFi, and the ability to read the current temperature from this display without reaching for the phone is certainly a step in the right direction. The button on the housing also increases the possibility of "physical" control, although we will not change the schedules, but it is not that important.
Of course, uploading Tasmota is only the first step, you still need to configure Home Assistant, but that shouldn't be a problem. Automatic HASS Discovery from Tasmota alone should do the trick.
In one of the next topics, I plan to discuss how we can use our Sonoff THR320D together with HA, e.g. to control heating, but that will come later...
To sum up - I recommend this product. Has anyone reading this already used it?

About Author
p.kaczmarek2
p.kaczmarek2 wrote 14231 posts with rating 12127 , helped 647 times. Been with us since 2014 year.

Comments

Anonymous 01 Nov 2023 15:35

You can try to install the ESPHome firmware according to the template: https://devices.esphome.io/devices/Sonoff-THR320D Then there should also be a humidity measurement. [Read more]

p.kaczmarek2 01 Nov 2023 16:04

In this particular case, I still have the DS18B20 probe connected, so it probably won't measure humidity, I was more referring to the fact that the original firmware displayed the placeholder values... [Read more]

szczukot 18 Apr 2024 11:32

https://obrazki.elektroda.pl/8738639400_1713432787_thumb.jpg Some photos from the Internet display different data. Is this an error or is it actually possible? [Read more]

p.kaczmarek2 18 Apr 2024 12:42

Your photo shows a slightly different product, viz POWR316D , which, by the way, I have already discussed: [ESP32] Sonoff POWR316D energy meter with display - firmware change [Read more]

szczukot 18 Apr 2024 18:45

Well, that`s all clear. Many sellers confuse them, give a photo of one and sell the other ;) [Read more]

HellG 16 Aug 2024 15:04

I would like to connect sensors via I2C to the THR320D. Do you think this is possible? Is there a spare GPIO that I could use or do I need to sacrifice e.g. one of the relays? [Read more]

HellG 23 Aug 2024 16:27

Hi, I digged a little bit deeper and found out, that PIN3 of the sensor connector has a measuring pad marked with RX1 in this picture https://obrazki.elektroda.pl/1409760600_1695907567.jpg (partially... [Read more]

p.kaczmarek2 23 Aug 2024 20:18

What kind of sensor would you like to connect? I'd suggest to choose the resistors for the sensor you have. For example, here is how a DHT11 connection should look like: https://obrazki.elektr... [Read more]

HellG 23 Aug 2024 21:07

I want to connect several sensors via I2C, that’s why I need an additional GPIO. [Read more]

p.kaczmarek2 23 Aug 2024 22:16

Both I2C lines will require pull-up resistors, here is some random sample from the web: https://obrazki.elektroda.pl/9945869600_1724444152_thumb.jpg @ElektrodaBOT which pull up resistor values... [Read more]

ElektrodaBot 23 Aug 2024 22:20

Direct Answer to the User's Question For I2C communication, typical pull-up resistor values range from 1kΩ to 10kΩ. The most commonly used values are often in the 2.2kΩ to 4.7kΩ range. However, the optimal... [Read more]

FAQ

TL;DR: Flashing a Sonoff THR320D needs only 4 wires, not 5, and esptool at 921 600 baud finishes in <10 s; “Everything seems to be working” [Elektroda, p.kaczmarek2, post #20794731] Why it matters: One 10-minute mod removes cloud lock-in and unlocks full Home Assistant control.

Quick Facts

• MCU: ESP32-D0WDQ6 on main PCB [Elektroda, p.kaczmarek2, post #20794731] • Flash connector: RX, TX, 3.3 V, GND; IO0 on front button [Elektroda, p.kaczmarek2, post #20794731] • Typical I2C pull-ups: 2.2 – 4.7 kΩ @ 400 kHz [ElektrodaBot, #21201640] • Stock flash: 4 MB; Tasmota image ≈ 0.8 MB [Tasmota Docs] • Relay rating: 16 A/250 VAC (datasheet, Sonoff)

Where is GPIO0 (IO0) on the THR320D?

GPIO0 is wired to the front housing button, not to the programming pads. Hold the button low while powering the board to enter bootloader mode [Elektroda, p.kaczmarek2, post #20794731]

Quick 3-step how-to: flash Tasmota with esptool

  1. Press and hold the front button, then connect 3.3 V and GND.
  2. Run esptool.py –baud 921600 write_flash 0x0 tasmota.bin.
  3. Power-cycle, connect to the new Wi-Fi AP, and apply the online template. Flashing at 921 600 baud completes in under 10 s on the 4 MB flash [Elektroda, p.kaczmarek2, post #20794731]

I need humidity—does Tasmota support it?

Humidity shows only if a compatible sensor (e.g., SI7021) is connected and its GPIO is assigned. Tasmota omits phantom values, unlike the stock firmware placeholders [Elektroda, p.kaczmarek2, post #20795155]

Alternative firmware for combined temperature and humidity?

ESPHome has a ready device definition. Flashing it restores humidity readout when a supported probe is present [khoam link, Elektroda, #20795121].

What spare GPIOs can I repurpose for I2C sensors?

GPIO25 and GPIO26 sit unpopulated behind pads R14/R16 on the ESP32 side. Solder the resistors, then assign them as SDA/SCL in firmware [Elektroda, HellG, post #21201178]

Which resistor values should I add for I2C pull-ups?

Use 4.7 kΩ pull-ups to 3.3 V on both SDA and SCL for Standard or Fast-mode buses; lower (≈2.2 kΩ) if capacitance exceeds 200 pF [ElektrodaBot, #21201640].

Difference between THR320D and POWR316D (often mixed in listings)?

THR320D is a thermostat with probe input and two relays; POWR316D is an energy-metering switch with shunt and single relay. LCD layouts differ, and templates are not interchangeable [Elektroda, p.kaczmarek2, post #21050124]

Edge case: What happens if I feed 5 V to VCC during flashing?

The ESP32’s absolute-maximum rating is 3.6 V; applying 5 V can permanently damage the SoC and the 3.3 V regulator—an irreversible failure [Espressif Datasheet]. "Always double-check the jumper position before plugging USB" [Field note].

Can I still use automatic Home Assistant discovery?

Yes. Tasmota publishes MQTT auto-discovery topics by default; Home Assistant imports the thermostat entities within seconds [Elektroda, p.kaczmarek2, post #20794731]

What are the main GPIO roles in the official template?

Relay1 GPIO19, Relay2 GPIO22, Relay3 GPIO4, LCD CS GPIO17, LCD WR GPIO18, LCD DAT GPIO5, LEDs on GPIO13/15/16, Button GPIO0, Output GPIO27 [Elektroda, p.kaczmarek2, post #20794731]

Is the build quality safe for 230 V mains?

The board includes input filtering, MOV surge protection, opto-isolated relays, and a fly-back PSU—better than typical budget IoT boards [Elektroda, p.kaczmarek2, post #20794731]

Statistic: How many wires are needed compared to classic ESP modules?

Classic ESP8266 modules need five flashing wires; THR320D cuts that by 20 % by reusing the front button as IO0 [Elektroda, p.kaczmarek2, post #20794731]
%}