Bootloop Workaround for Flashing Sonoff TH Elite (THR316D/THR320D and maybe others) with ESPHome for the first time

Flashing Sonoff TH Elite THR320D via UART resulted in a bootloop that appeared to be power supply and radio related.

I tried:

  • Minimal configuration
  • Configuration that was known working from another identical device
  • Multiple devices new from the box after testing with stock firmware and Tasmota firmware
  • Multiple different power 3.3v supplies (checked with multimeter)
  • Battery power
  • Mains power

What happened:

Any configuration that included WiFi or BLE would trigger a bootloop.

Posting this for two reasons:

  1. I would like to know why flashing ESPHome resulted in a bootloop without this workaround, in hopes of contributing a fix if there is one possible.
  2. So that others experiencing this issue can find a potential workaround.

I only have a Sonoff TH Elite model THR320D, but I suspect this could apply to these similar Sonoff devices:

  • TH Origin - THR316, THR320
  • POW Origin - POWR316
  • POW Elite - POWR316D, POWR320D
  • TH Elite - TH316D, TH320D (this device)
  • Smart Switch - TH10, TH16
  • High Power Smart Switch - POWR3

Workaround:

  1. Flash the device with Tasmota via UART.
  2. Connect the device to mains power.
  3. Provide WiFi details via Tasmota captive portal.
  4. Connect to the Tasmota web UI and flash a minimal esphome (legacy format) configuration with board set to esp32dev (not nodemcu-32s).
  5. Power cycle the device on mains power, wait a few minutes.
  6. Disconnect mains power.
  7. Flash the device with esphome (modern format) and board set to nodemcu-32s including the WiFi module and SSID / password via UART.
  8. Connect to mains power.
  9. Power cycle the device.
  10. Flash via OTA wirelessly going forward.

I have no idea what causes this problem or why this workaround works. I was able to reproduce the problem with four different units new out of the box and using these steps got me up and running with ESPHome on all of the devices with OTA updates working perfectly.

I must admit, this really does seem to be a power issue but I tried multiple power supplies, multiple outlets, 3.3v battery power, and 3.3v power provided by an ESP32-dev board. In all situations I ended up with a bootloop whenever wireless (WiFi or BLE) tried to start.

I’d love some help figuring out why this is happening.

1 Like

Found this while hitting similar issues installing Tasmota on SonOff THR320.

The simple fix was to flash from the USB 3.3v supply then switch to AC for the web config. It may be possible to flash with the mains connected but this would be risky (put mildly - just don’t!).

I have seen this before on the ESP8266 modules (I built my own battery powered WiFI/MQTT thermostats using these a few years back) - specifically they use a LOT more power for the initial wifi connection which caused a brownout (reset). The solution was a relatively large electrolytic capacitor on the power lines to smooth things out. I guess this sonoff unit has the same issue and the 3.3v from the USB Serial adapter is not sufficient.

It may be possible to add an electrolytic capacitor (say 220uf 16V at a guess) across the 0V/3.3V power from the USB/Serial unit to work around the issue for flashing and intial tests.