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 6585 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.
Summary generated by AI based on the discussion content.
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 14701 posts with rating 12748 , helped 656 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: With 4 wires and the rule "IO0 is located on the button," this FAQ helps Sonoff THR320D owners flash Tasmota, find GPIO0, map the ESP32 pins, and avoid confusing the thermostat with the similar-looking POWR316D. [#20794731]

Why it matters: It turns a cloud-tied mains thermostat into a locally controlled ESP32 device that can work with Home Assistant on your terms.

Option Flashing path Display behavior mentioned in thread Best fit
Tasmota Online installer or esptool Display works, but humidity placeholders disappear Fast local control and HA discovery
ESPHome devices.esphome.io template May restore humidity-related display behavior Users who want template-based customization

Key insight: The crucial hardware detail is that GPIO0 is not a separate pad. You enter flash mode by holding the front button while applying 3.3 V power through the UART programmer. [#20794731]

Quick Facts

  • The exposed programming interface uses 4 wires, not 5: RX, TX, GND, and 3.3 V. GPIO0 is reached through the button circuit, not an extra header pin. [#20794731]
  • The THR320D template maps key functions to named pins: GPIO04 relay, GPIO05 TM1621 DAT, GPIO17 TM1621 CS, GPIO18 TM1621 WR, GPIO23 TM1621 RD, and GPIO27 Output Hi. [#20794731]
  • The board includes an offline-capable architecture with a relay, input protection, a varistor, a filter capacitor, and a flyback supply, plus a separate 3.3 V step-down stage for the ESP32. [#20794731]
  • One discovered expansion path uses the sensor connector’s PIN3 test pad, marked RX1, routed through unpopulated resistors toward GPIO26; GPIO25 is also mentioned on the nearby network. [#21201178]
  • For added I2C sensors, typical pull-ups on a 3.3 V ESP32 board fall in the 1 kΩ to 10 kΩ range, with 2.2 kΩ to 4.7 kΩ used most often. [#21201640]

How do I flash Tasmota onto a Sonoff THR320D, and where do I connect the UART wires?

Flash it through the ESP32 serial interface using 4 wires connected to the programming pads: RX, TX, GND, and 3.3 V. 1. Solder the 4 UART wires. 2. Hold the front button to force IO0 low. 3. Apply 3.3 V power and upload Tasmota with the online installer or esptool. The thread explicitly says 5 wires are unnecessary because GPIO0 is handled by the button. [#20794731]

Where is GPIO0 on the Sonoff THR320D, and how do I put it into ESP32 bootloader mode for flashing?

GPIO0 is on the button circuit, not on a separate fifth programming pad. To enter ESP32 bootloader mode, press and hold the button, then connect the UART programmer’s 3.3 V supply so IO0 stays low during boot. That sequence is the key step for flashing. [#20794731]

What is the Tasmota template for the Sonoff THR320D, and which GPIOs are assigned to the relay, LEDs, and TM1621 display?

The thread provides a ready-made Tasmota template for the Sonoff THR320D and a pin map for its main functions. It assigns GPIO04 to Relay 3, GPIO13 to Led_i 2, GPIO15 to LedLinks, GPIO16 to Led_i 1, GPIO05 to TM1621 DAT, GPIO17 to TM1621 CS, GPIO18 to TM1621 WR, and GPIO23 to TM1621 RD. It also lists GPIO19 and GPIO22 as relay-related pins and GPIO27 as Output Hi. [#20794731]

How do I configure a DS18B20 probe in Tasmota after flashing a Sonoff THR320D?

Configure the sensor GPIO role manually after loading the THR320D template. The thread says the base template activates the display and core functions, but the sensor role still must be selected because different probes can be used. The author verified operation with a DS18B20 and showed it working afterward. [#20794731]

Why does the Sonoff THR320D display stop showing humidity placeholders after switching from the stock firmware to Tasmota?

Tasmota keeps the display working, but it does not show the stock firmware’s humidity placeholder dashes. In the tested unit, a DS18B20 probe was connected, so there was no humidity sensor to report. The author notes that the original firmware still showed placeholder values, while Tasmota showed nothing in that area. [#20795155]

What is the TM1621, and how is it used in the Sonoff THR320D display?

"TM1621 is a display driver IC that controls segmented LCD panels, handling signal timing and segment selection." In the THR320D, the thread identifies TM1621 as the display support chip and maps its interface to GPIO05 for DAT, GPIO17 for CS, GPIO18 for WR, and GPIO23 for RD. That is why the display can still work after flashing a proper template. [#20794731]

What is a flyback power supply, and why is it used inside devices like the Sonoff THR320D?

"A flyback power supply is an isolated switch-mode converter that stores energy in a transformer and releases it to the low-voltage side, allowing compact mains-to-logic conversion." The thread identifies a small transformer and a Y capacitor, then calls the THR320D supply a flyback design. That fits a mains-powered thermostat that still needs a low-voltage rail for the ESP32 and display electronics. [#20794731]

What are the differences between flashing the Sonoff THR320D with Tasmota and using the ESPHome configuration from devices.esphome.io?

Tasmota was confirmed working on the THR320D, including the display, relay logic, and DS18B20 support. ESPHome was suggested as an alternative because its published device template may also restore humidity measurement behavior on the display. In short, the thread presents Tasmota as tested and ESPHome as a promising option for fuller display integration. [#20795121]

How can I integrate a Tasmota-flashed Sonoff THR320D with Home Assistant using automatic discovery?

Use Tasmota’s automatic Home Assistant discovery after flashing and basic setup. The thread says flashing Tasmota is only the first step, but also adds that automatic HASS Discovery from Tasmota should handle the integration. That makes the THR320D suitable for local HA-based heating control without the vendor cloud. [#20794731]

Why does my Sonoff THR320D look different from product photos online, and how can I tell it apart from the Sonoff POWR316D?

Your unit may look different because some sellers mix photos of the THR320D and POWR316D. The thread identifies one disputed product photo as a POWR316D, not a THR320D, and notes that sellers sometimes show one model and ship the other. If the listing image does not match the thermostat discussed here, check the exact model number before buying or flashing. [#21050562]

What spare GPIO options are available on the Sonoff THR320D if I want to add extra sensors over I2C?

The thread points to an unpopulated route from the sensor connector toward GPIO26, with a neighboring path tied to GPIO25. That means extra I2C wiring may be possible, but not as a ready-made spare header. If you need both SDA and SCL, you may have to populate missing resistors or repurpose an existing function such as a relay line. [#21201178]

How do I use the sensor connector test pad linked to GPIO26 on the Sonoff THR320D, and what resistor values should I choose for that mod?

Use the sensor connector’s PIN3 test pad marked RX1 as the access point, then populate the missing resistor path toward GPIO26. The thread says that node runs near R16 and R25, which are not populated. No exact THR320D resistor values are given; the advice is to choose values for the specific sensor you plan to attach. A DHT11-style example is shown, but not an I2C-specific BOM. [#21201469]

Which pull-up resistor values work best for I2C sensors on a 3.3V ESP32-based board like the Sonoff THR320D?

Typical I2C pull-ups are 1 kΩ to 10 kΩ, with 2.2 kΩ to 4.7 kΩ used most often. The thread also gives mode-based guidance: about 1.5 kΩ to 10 kΩ for 100 kHz, 1.5 kΩ to 4.7 kΩ for 400 kHz, and 1 kΩ to 2.2 kΩ for 1 MHz. Start near 4.7 kΩ on 3.3 V unless bus capacitance or speed forces a lower value. [#21201640]

What safety precautions should I take when opening and flashing a mains-powered thermostat like the Sonoff THR320D?

Disconnect it from mains power before opening the case or attaching a UART adapter. The board contains input protection parts, a relay, and an internal mains power supply, so treat it as live mains hardware, not a USB gadget. For flashing, power the ESP32 side from a 3.3 V UART programmer only, and avoid applying mains during the wiring and programming steps. [#20794731]

What troubleshooting steps help when a Sonoff THR320D won’t enter flash mode or esptool can’t detect the ESP32?

First, verify the wiring count and boot sequence. 1. Confirm you used exactly 4 wires: RX, TX, GND, and 3.3 V. 2. Hold the button before power-up so GPIO0 stays low. 3. Recheck that your USB-UART adapter provides 3.3 V, not 5 V. A common failure case is searching for a nonexistent fifth GPIO0 pad instead of using the button. [#20794731]
Summary generated by AI based on the discussion content.
%}