ESPHome firmware for the Dewenwils PTW04 / SHOWT01F 240VAC 40A 3HP Smart Timer Box — replaces Tuya cloud / Dewenwils app with local Home Assistant control via ESPHome (LibreTiny)
⚠️ Owners of the SHOWT01E 120V variant: Read the "Hardware details" and "GPIO Map" sections! The GPIO pair required to make the "N (load)" relay work (not used on the SHOWT01F variant) are P14 and P15, they were identified in this project but not in use for the SHOWT01F, you'll need to make your own ESPHome YAML to make use of P14 and P16 and change the relays logic.
⚠️ Owners of the SHOWT01A variant: This project is imcompatible with this variant. The SHOWT01A uses an ESP8266 MCU, this project is for variants using the Beken BK7231n MCU. The SHOWT01A or similar units using the ESP6266 can be flashed with ESPHome using this projetc: https://devices.esphome.io/devices/dewenwils-heavy-duty-40a-outdoor-plug-howt01a/
Replace the stock Tuya firmware on the Dewenwils PTW04 Smart Timer Box with ESPHome, enabling local control via Home Assistant without any cloud dependency.
- Product Overview
- Hardware Details
- GPIO Map
- Flashing Prerequisites
- Flashing Procedure
- ESPHome Configuration
- Home Assistant Integration
- Behavior & Features
- Credits
| Field | Value |
|---|---|
| Brand | Dewenwils |
| Model | PTW04 / SHOWT01F |
| Type | Smart Timer Box / Load Controller |
| Input | 240VAC 60Hz |
| Output | 40A Resistive 240VAC / 3HP 240VAC |
| Certifications | ETL Listed, FCC ID: 2A4G9-016, IC: 26865-014 |
| App | SmartLife (Tuya) or Dewenwils app |
| PCB Reference | RT-PTW01-1.0 |
| PCB Date | 20240523 |
The PTW04 is a WiFi-enabled load controller designed for 240VAC applications such as pool pumps, heaters, and motors. It uses two relays wired in series to switch both L1 and L2 lines of a 240VAC circuit simultaneously. A third relay footprint (NO3/K1) is present on the power board but not populated.
The device consists of two PCBs connected via a flat ribbon cable:
- Handles mains voltage (240VAC)
- Contains 2 populated bistable (latching) relays — Meishuo C-S-105-A-L1 (NO1/L1 and NO2/L2) + 1 empty footprint (NO3) most likely for the 120V variant (SHOWT01E)
- Terminal block connections:
NO3 | N | L2 | NO2 | L2 | L1 | NO1 | L1 - AC/DC power supply section providing 3.3V and 12V rails to the control board via flat ribbon cable
- Relay coils driven at 12V via NPN transistor drivers (U4/U5/U6) on the control board
The third relay footprint (NO3/K1) is not populated on the PTW04 (240VAC model). Based on comparison with the 120VAC variant of this product line (SHOWT01E), which most likely uses the same PCB, the third relay would be used to switch the neutral wire to the load — the 120VAC model has 5 terminals labeled L1 | L | L2 | N | N(Load) where N(Load) is the switched neutral.
On the 240VAC PTW04, this footprint is unused since 240VAC loads are controlled by switching both L1 and L2 simultaneously via the two populated relays.
For owners of the 120VAC variant (SHOWT01E): the GPIO pair controlling relay L3 (OUT3+ / OUT3- on connector J5) has not yet been identified in this project. The relays's logic would also need to be modified. Contributions to identify and map these GPIOs are welcome.
| Component | Description |
|---|---|
| U1 | Beken BK7231N — WiFi/BT SoC (LibreTiny compatible) |
| Y1 | Crystal YL260 Yx4H |
| U7 | XJS 5350Z — 5V LDO regulator |
| U4/U5/U6 | 3111S JRONK — Dual NPN transistors (SOT-23-6), relay drivers |
| SW1 | Push button (ON/OFF + reset) |
| D1 | Power LED — controlled by P22 on BK7231N |
| D2 | Load LED (red) — indicates relay state, controlled by P21 |
| D3 | WiFi LED (blue) — ESPHome status_led, controlled by P23 |
| J5 | Output connector: VIN, OUT1+, OUT1-, OUT2+, OUT2-, OUT3+, OUT3-, GND |
| Pad | Function |
|---|---|
GND |
Ground |
U1TX |
UART1 TX (connect to RX on USB-TTL adapter) |
U1RX |
UART1 RX (connect to TX on USB-TTL adapter) |
3V3 |
3.3V power input |
U2TX |
UART2 TX (reserved — do not use) |
U2RX |
UART2 RX (reserved — do not use) |
TEST |
P8 — factory test pad (not CEN) |
ATE |
P7 — factory test pad - do not use |
Note: The CEN pin is pulled HIGH to 3.3V via a 1kΩ resistor and is not exposed as a test pad. Download mode is triggered by power cycling via the GND probe — no CEN access required.
All GPIOs confirmed through empirical testing after firmware dump analysis.
| GPIO | Direction | Function | Notes |
|---|---|---|---|
| P24 | OUTPUT | Relay L1 SET | Active LOW — latches relay L1 ON via NPN transistor |
| P26 | OUTPUT | Relay L1 RESET | Active LOW — latches relay L1 OFF via NPN transistor |
| P17 | OUTPUT | Relay L2 SET | Active LOW — latches relay L2 ON via NPN transistor |
| P15 | OUTPUT | Relay L2 RESET | Active LOW — latches relay L2 OFF via NPN transistor |
| P14 | OUTPUT | Relay L3 RESET | Active LOW — latches relay L3 OFF via NPN transistor |
| P16 | OUTPUT | Relay L3 SET | Active LOW — latches relay L3 ON via NPN transistor |
| P21 | OUTPUT | LED Load (D2 red) | Active HIGH |
| P22 | OUTPUT | LED Power (D1) | Active HIGH — always ON when powered |
| P23 | OUTPUT | LED WiFi (D3 blue) | Active HIGH — ESPHome status_led |
| P28 | INPUT | Button SW1 | Active LOW — INPUT_PULLUP |
| GPIO | Reserved For |
|---|---|
| P2, P3, P4, P5 | Internal use / strapping pins |
| P10, P11 | UART1 (flash / TuyaMCU) |
| P25, P27 | Reserved by LibreTiny |
The BK7231N GPIOs cannot directly drive relay coils (which require ~50-100mA at 12V). Each relay is driven through a dual NPN transistor (3111S, SOT-23-6):
BK7231N GPIO (active LOW)
→ Series resistor
→ NPN Base
→ NPN Collector → Relay coil (12V)
→ NPN Emitter → GND
When the GPIO goes LOW, the transistor saturates and the relay coil is energized. This is why all relay outputs use inverted: true in ESPHome.
Important: The relays on the PTW04 are bistable (latching) — they maintain their state without continuous current. A short pulse (100ms) on the SET line latches them ON; a short pulse on the RESET line latches them OFF. This is why the ESPHome configuration uses timed impulses rather than sustained GPIO levels.
- USB-TTL UART adapter (CH340, CP2102, or similar) — 3.3V logic level
- USB extension cable (highly recommended for easier manipulation)
- 4× dupont female-to-female jumper wires
- BDM frame + 4 BDM probes (spring-loaded pogo pins) — used in this project for reliable contact on the silkscreened pads without soldering
Tip: A BDM frame holds the 4 probes (GND, TX, RX, 3V3) in precise alignment over the pads. Combined with a USB extension cable, this allows comfortable one-handed manipulation while keeping the other hand free to trigger the boot mode.
- ltchiptool — BK7231N flash tool
- ESPHome — firmware framework
- Home Assistant — optional but recommended
⚠️ Safety first: Always disconnect the device from 240VAC mains before opening or connecting any test equipment. Power the control board exclusively from your USB-TTL adapter during flashing. Never flash with mains voltage applied.
- Open the PTW04 enclosure
- Disconnect the flat ribbon cable between the power board and the control board
- Work only with the control board (RT-PTW01-1.0) — the green PCB with the BK7231N
Using the BDM frame with 4 pogo probes, position them on the silkscreened pads:
| Control Board Pad | USB-TTL Adapter Pin |
|---|---|
GND |
GND |
U1TX |
RX (cross-connect) |
U1RX |
TX (cross-connect) |
3V3 |
3.3V |
Note: Do not connect to U2TX/U2RX — these are UART2 (logger) and correspond to the relay GPIOs P26/P27.
Always backup before flashing. Open ltchiptool, select BK7231N and perform a full flash read
Keep this backup file in a safe location. It contains the original Tuya firmware and can be used to restore the device to factory state.
The TEST pad is connected to P8 (factory test pad, not CEN). CEN is pulled HIGH via a 1kΩ resistor internally and is not directly accessible as a pad.
The following method was used successfully on this device:
- Launch ltchiptool and start the chip detection / flash operation
- While ltchiptool is waiting for the chip to respond, briefly touch a jumper wire from GND to the GND pad repeatedly (tap GND to GND 2–3 times in quick succession during power-up)
- This triggers a reset that causes the BK7231N to enter UART download mode
- ltchiptool will detect the chip and proceed, at this stage, keep de GND connected to the GND pad.
Tip: This may require several attempts. The timing is critical — the GND tap must happen within the first ~100ms of power-on. Using a USB extension cable makes it much easier to manipulate the board while keeping the probes in contact.
- In ESPHome dashboard, create a new device using the provided YAML configuration in this repo. Make sure to change the WiFi, OTA and hotspot credentiels to fit your needs.
- Click Install → Manual download, ESPHome will compiles the firmware.
- → select UF2 Package and downloads the .uf2 firmware
- In ltchiptool, select the downloaded
.uf2and flash it to the device, use the same method as steps 4.2 to trigger download mode if the control board exited download mode (if the board was disconnected between steps 4 and 5).
See dewenwils-ptw04.yaml for the complete configuration.
| Setting | Value | Reason |
|---|---|---|
baud_rate: 0 |
0 | Disables UART2 logger, freeing P26/P27 for relay GPIOs |
restore_mode |
RESTORE_DEFAULT_OFF |
Actual power-on behavior managed by the select entity |
on_boot priority |
-100 | Ensures all components are fully initialized before boot actions run |
| Relay logic | Bistable impulse | 100ms SET/RESET pulses — relays hold state without continuous power |
| Relay pins | inverted: true |
Relay drivers are active LOW (NPN transistor logic) |
After flashing, power the control board via the USB-TTL adapter and wait for it to connect to WiFi. Home Assistant will automatically discover the device via mDNS.
Discovered entities:
| Entity | Type | Description |
|---|---|---|
| Load | Switch | Main load control (both relays simultaneously) |
| Power On Behavior | Select | Configures load state after power cycle — Always OFF / Restore last state / Always ON |
| Button | Binary Sensor | Physical button state |
| WiFi Signal | Sensor | WiFi signal strength in % |
| IP Address | Text Sensor | Current IP address |
| SSID | Text Sensor | Connected WiFi network |
| Uptime | Sensor | Device uptime |
| Restart | Button | Remote restart |
| LED | Color | GPIO | Behavior |
|---|---|---|---|
| D1 Power | Green | P22 (active HIGH) | ON whenever the device is powered |
| D2 Load | Red | P21 (active HIGH) | ON when the load (relays) is active |
| D3 WiFi | Blue | P23 (active HIGH) | ESPHome status LED — see below |
WiFi LED (D3) behavior with ESPHome status_led:
| D3 State | Meaning |
|---|---|
| Blinking fast | No WiFi connection / booting |
| Blinking slow | WiFi connected, API disconnected |
| OFF | WiFi + Home Assistant API connected |
| Blinking during OTA | Firmware update in progress |
| Press Duration | Action |
|---|---|
| Short (50–500ms) | Toggle load ON/OFF |
| Long (3s+) | Restart the ESP |
-
Configurable power-on behavior: The "Power On Behavior" select entity in HA controls what happens after any power cycle or restart — three options are available directly from the device page in Home Assistant, no reflashing required:
- Always OFF (default, recommended for heaters and safety-critical loads) — both relays are forced OFF at every boot via a RESET pulse, regardless of previous state
- Restore last state — relays resume the state they were in before the power was cut, stored in device flash memory
- Always ON — both relays are forced ON at every boot via a SET pulse
-
Dual-phase switching: Both relays (L1 and L2) always switch simultaneously, safely interrupting both phases of the 240VAC circuit.
-
Bistable relay safety: Because the relays are bistable (latching), they maintain their physical position even during a power failure. The boot RESET pulse ensures a known-good state is applied on every startup.
PTW04
┌─────────┐
Power L1 ───────►│ Line L1 │──► Load L1
│ Relay │ │
│ │ [Load]
│ Line L2 │ │
Power L2 ───────►│ Relay │──► Load L2
└─────────┘
- LibreTiny — BK7231N support
- ltchiptool — flash tool
- bk7231tools — firmware analysis
- ESPHome — firmware framework
- GPIO map derived from manual analysis of original firmware dump at offset
0x47690



