Skip to content

Commit 2fc721e

Browse files
STB3tekmaven
andauthored
New device: Tuya Smart Plug 20A with BL0942 Power Monitoring IC (#1371)
* Initial commit * Update documentation * Add pinout * Add yaml example * Update documentation * Update documentation * Update documentation * Add basic configuration * Update documentation, resolve errors * Remove trailing space * Fix another markdownlint issue --------- Co-authored-by: Ryan Hoffman <tekmaven@users.noreply.github.com>
1 parent 883d4fb commit 2fc721e

File tree

4 files changed

+223
-0
lines changed

4 files changed

+223
-0
lines changed
2.13 MB
Loading
716 KB
Loading
109 KB
Loading
Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
---
2+
title: Tuya Smart Plug 20A with BL0942 Power Monitoring IC
3+
date-published: 2025-12-07
4+
type: plug
5+
standard: eu
6+
board: bk72xx
7+
made-for-esphome: False
8+
difficulty: 3
9+
---
10+
11+
![Tuya Smart Plug 20A](Tuya_plug_EU.png)
12+
![Tuya Smart Plug Aliexpress](Tuya_plug_aliexpress.png)
13+
14+
The smart plug is using the Tuya T34 module design incorporating a BK7231N chip
15+
[T34 Datasheet](https://developer.tuya.com/en/docs/iot/t34-module-datasheet?id=Ka0l4h5zvg6j8)
16+
17+
The power monitoring chip is the BL0942, which is not so often seen in Tuya products.
18+
It is connected using the UART feature to UART1.
19+
20+
[BL0942 Datasheet](https://www.belling.com.cn/media/file_object/bel_product/BL0942/datasheet/BL0942_V1.06_en.pdf)
21+
22+
[BL0942 Application](https://support.tuya.com/en/help/_detail/Kd2fly62orx3p)
23+
24+
[BL0942 ESPHome](https://esphome.io/components/sensor/bl0942/)
25+
26+
The BL0942 is a sophisticated, calibration-free integrated circuit (IC) for energy measurement
27+
from Shanghai Belling Corp.
28+
It is used in single-phase electricity meters, smart plugs and smart home devices to enable accurate
29+
measurements of voltage, current and power via a UART/SPI interface, offering a cost-effective solution
30+
for energy monitoring.
31+
32+
![Tuya Smart Plug PCB view](Tuya_PCB.png)
33+
34+
## GPIO Pinout
35+
36+
| Pin | Function |
37+
| --- | ----------------- |
38+
| P25 | BL0942(10) TX |
39+
| P26 | BL0942(9) RX |
40+
| P14 | Relay & red LED |
41+
| P26 | Button (Inverted) |
42+
| P24 | Blue LED |
43+
44+
## Programming
45+
46+
Based on available documentation (links above) the T34 chip can be programmed using ESPHome tools
47+
48+
- pin 25 as UART_RXD
49+
- pin 26 as UART_TXD
50+
51+
It is easier to use the corresponding BL0942 pins to connect the programmers RX & TX pins.
52+
Programmer TX must be connected to pin 10 and RX must beconnected to pin 9.
53+
Connect a 5V DC source to the voltage regulator. Start programming and then cycle power of the 5V source to enter the bootloader.
54+
55+
It is important to **limit the download speed to 19200 baud** (--upload_speed 19200) otherwise the programming terminates.
56+
57+
## ESPHome Hardware definitions
58+
59+
```yaml
60+
esphome:
61+
comment: "Tuya Smart Socket EU 20A with Power Monitor"
62+
name: tuya-smartplug
63+
64+
bk72xx:
65+
board: generic-bk7231n-qfn32-tuya # actually a T34 Tuya module
66+
67+
# Relay output
68+
output:
69+
- platform: gpio
70+
pin: P14
71+
id: relay_1
72+
- platform: gpio
73+
pin:
74+
number: P24
75+
inverted: false
76+
id: led_output
77+
78+
light:
79+
- platform: binary
80+
name: "Status LED" # blue LED
81+
id: status_light
82+
output: led_output
83+
84+
# Local button on PCB
85+
binary_sensor:
86+
- platform: gpio
87+
id: button_1 # illuminated button
88+
pin:
89+
number: P26
90+
mode: INPUT_PULLUP
91+
inverted: true
92+
93+
uart:
94+
id: bl0942_uart # UART1 is used to read the data from the BL0942
95+
tx_pin: TX1
96+
rx_pin: RX1
97+
baud_rate: 4800
98+
99+
# Belling BL0942 Energy Monitor
100+
sensor:
101+
- platform: bl0942
102+
uart_id: bl0942_uart
103+
line_frequency: 50Hz
104+
voltage:
105+
name: 'Voltage'
106+
current:
107+
name: 'Current'
108+
power:
109+
name: 'Power'
110+
energy:
111+
name: 'Energy'
112+
frequency:
113+
name: "Frequency"
114+
115+
```
116+
117+
## ESPHome working example config
118+
119+
```yaml
120+
# Programming speed must be reduced otherwise the
121+
# switch will will exit the flashing routine
122+
# Use:
123+
# esphome run tuya_plug.yaml --upload_speed 19200
124+
125+
esphome:
126+
comment: "Tuya Smart Socket EU 20A with Power Monitor"
127+
name: tuya-smartplug
128+
name_add_mac_suffix: true
129+
130+
bk72xx:
131+
board: generic-bk7231n-qfn32-tuya # actually a T34 Tuya module
132+
133+
logger:
134+
level: NONE
135+
136+
wifi:
137+
# In case a secrets.yaml file is available in the root folder
138+
# with the following content:
139+
# secrets.yaml
140+
# wifi_ssid: "SSID"
141+
# wifi_password: "PASSWORD"
142+
143+
#ssid: !secret wifi_ssid
144+
#password: !secret wifi_password
145+
146+
ap:
147+
ssid: "TuyaPlug"
148+
149+
captive_portal:
150+
151+
api:
152+
153+
ota:
154+
platform: esphome
155+
156+
web_server:
157+
version: 3
158+
port: 80
159+
160+
# Relay output
161+
output:
162+
- platform: gpio
163+
pin: P14
164+
id: relay_1
165+
- platform: gpio
166+
pin:
167+
number: P24
168+
inverted: false
169+
id: led_output
170+
171+
light:
172+
- platform: binary
173+
name: "Status LED" # blue LED
174+
id: status_light
175+
output: led_output
176+
177+
# Local button on PCB
178+
binary_sensor:
179+
- platform: gpio
180+
id: button_1 # illuminated button
181+
pin:
182+
number: P26
183+
mode: INPUT_PULLUP
184+
inverted: true
185+
filters:
186+
- delayed_on: 50ms
187+
on_press:
188+
- switch.toggle: relay_switch # manual control for relay
189+
190+
# Switch to control the relay from the UI
191+
switch:
192+
- platform: output
193+
name: "Relay"
194+
id: relay_switch
195+
output: relay_1
196+
197+
uart:
198+
id: bl0942_uart # UART1 is used to read the data from the BL0942
199+
tx_pin: TX1
200+
rx_pin: RX1
201+
baud_rate: 4800
202+
203+
# Belling BL0942 Energy Monitor
204+
sensor:
205+
- platform: bl0942
206+
uart_id: bl0942_uart
207+
line_frequency: 50Hz
208+
voltage:
209+
name: 'Voltage'
210+
current:
211+
name: 'Current'
212+
power:
213+
name: 'Power'
214+
energy:
215+
name: 'Energy'
216+
frequency:
217+
name: "Frequency"
218+
219+
- platform: wifi_signal
220+
name: "TuyaPlug WiFi Signal"
221+
id: wifi_signal_sensor
222+
update_interval: 60s
223+
```

0 commit comments

Comments
 (0)