背景
之前有好友推荐了一款支持 Tasmota ↗ 的智能插座 Athom PG01EU16A,从 AliExpress 以 €15.26 包邮购入两个,到货却发现虽然外观一模一样,但印着的型号却是 ELIVCO LSPA9。

插座外部没有螺丝,根据这篇帖子 ↗ [存档] ↗,可以通过挤压顶部两侧来拆开它。

硬件
拆开后看到 Wi-Fi 模块印着 CB2S,搜索可知这又是 Tuya 基于 Beken BK7231 系列 ARM SoC 的模块,第三次踩雷。

而且 CB2S 规格特殊,没有引脚排布与其相似的常见 ESP 模块:

拆下模块后开始逆向电路,左下角的 IC 是 “AMS1117-3.3” 稳压器,用于提供 +3.3 V 电源;在它右侧的是 “BL0937” 交流电能监控 IC,用于测量插座的电压、电流及功率。

主要电路整理如下,元件标识按照 PCB 上的实际丝印,其余元件已略去:

可以换上一片常见的 ESP 模块,连接必要的引脚。

这里使用了一片 ESP-12F,选用的对应引脚为:
| CB2S | ESP-12F |
|---|---|
| 3V3 | VCC |
| GND | GND |
| P6 | GPIO5 |
| P7 | GPIO4 |
| P8 | GPIO2 |
| RX1 | GPIO13 |
| P24 | GPIO12 |
| P26 | GPIO14 |
另外上拉 EN、 下拉 GPIO15 即可。
软件
ESPHome 配置示例:
substitutions:
device_name: '插座 1'
esphome:
name: plug-1
comment: 'ELIVCO LSPA9 智能插座 1'
esp8266:
board: esp12e
restore_from_flash: true
preferences:
flash_write_interval: 10min # 降低闪存写入频率以避免磨损,按需调整
logger:
level: WARN
# baud_rate: 115200
wifi:
fast_connect: true
networks:
- ssid: !secret wifi_ssid
bssid: !secret wifi_bssid
password: !secret wifi_password
domain: !secret domain_name
api:
ota:
password: !secret ota_password
button:
# 硬重启
- platform: restart
id: restart_button
name: '重启 ${device_name}'
entity_category: diagnostic
status_led: # 按钮上自带的蓝色 LED
pin:
number: 2
inverted: true
switch:
# 插座继电器
- platform: gpio
id: relay
pin: 14
name: '${device_name}'
restore_mode: RESTORE_DEFAULT_OFF # 重启时试图恢复状态,失败则默认断电
icon: mdi:power-socket-de
binary_sensor:
# the button
- platform: gpio
id: switch_button
pin:
number: 13
inverted: true
on_release:
then:
- switch.toggle: relay
internal: true
sensor:
- platform: hlw8012
model: BL0937 # 注意指定型号以使用专属信号频率参数
current_resistor: 0.001 # 根据实际电阻值调整
voltage_divider: 1600 # (680×1000×3+1000)/1000 = 2041, 根据实际电阻值调整
sel_pin:
number: 12
inverted: true # BL0937 的逻辑与 HLW8012 相反
cf_pin: 4
cf1_pin: 5
current:
name: '${device_name} 电流'
voltage:
name: '${device_name} 电压'
power:
name: '${device_name} 功率'
energy:
name: '${device_name} 功耗'
# 转换至 kWh
filters:
- multiply: 0.001
unit_of_measurement: 'kWh'
accuracy_decimals: 4
update_interval: 60s
change_mode_every: 3yamlBL0937 分压电阻计算
其中 hlw8012 组件的 voltage_divider 参数需要根据实际分压电阻计算得出,否则电压信息不准确:
voltage_divider (Optional, float): The value of the voltage divider on the board as
(R_upstream + R_downstream) / R_downstream. Defaults to the Sonoff POW’s value2351.来源:https://esphome.io/components/sensor/hlw8012.html#configuration-variables ↗
根据实际电路,这款智能插座中使用的分压电阻如下:

其理论值应该为 (680×1000×3+1000)÷1000=2041,但实际结果并不准确;进行测试之后可以得到 1600 作为较准确的值,原因尚且不明。
之后即可在 Home Assistant 中直接接入:


Hello. I need to replace the IC which is located near C1. It is AC/DC converter, but I cannot see the maker/model/numbers on it.
Hi, I see the marking is "BP2525" on the IC above C1 on my end. It seems to be a BP2525X from Bright Power Semiconductor, used for converting 220V AC to 5V DC.
OK. Thank you. My smart plug is one of the oldest. On my it says BP2902, but I could not find anything about it. The problem is that I have only about 4V DC, instead of 5V. And because of that the AMS1117 is not working properly, so the plug is faulty now. I checked the plug through connecting the AMS1117 to 5V externally, and the plug started to work properly with no issues whatsoever. So I figured it is this AC/DC converter that is faulty, because everything else on the board seems to be fine.
Anyway, I found BP2525F on Aliexpress, so I will replace it now and it should solve my problem.