ELIVCO LSPA9 Smart Plug
Integrate the ELIVCO LSPA9 smart plug with Home Assistant to enable remote control of the plug.
Background
A friend of mine recommended a smart plug Athom PG01EU16A that supports Tasmota ↗, so I purchased two of them from AliExpress for €15.26 with free shipping. However, upon arrival, I discovered that although the appearance of the plugs was identical, the printed model number was ELIVCO LSPA9 instead.

There are no external screws, according to this post ↗ [Archive] ↗, we can crack it open by applying pressure to the top sides.

Hardware
After disassembling it, I saw a model number CB2S printed on the Wi-Fi module, a quick search showed that it’s another Tuya module based on the Beken BK7231 series ARM SoC, this is the third time I stepped on these landmines from Tuya.

And what made things worse is that the CB2S module has a unique pinout that is not similar to any commonly available ESP modules:

Anyway, I removed the module and reverse-engineered the circuit: the IC in the lower left corner is an “AMS1117-3.3” voltage regulator, it provides the +3.3 V power source for the Wi-Fi module as well as some other components; to its right is a “BL0937” AC power monitoring IC, which is used to measure the voltage, current and power on the plug.

The main circuit can be organized as follows, with components labeled as per their actual PCB silkscreen printings, some less important components have been omitted:

We can replace the CB2S module with a common ESP module and connect the necessary pins.

Here I used an ESP-12F module, with corresponding pins selected as:
| CB2S | ESP-12F |
|---|---|
| 3V3 | VCC |
| GND | GND |
| P6 | GPIO5 |
| P7 | GPIO4 |
| P8 | GPIO2 |
| RX1 | GPIO13 |
| P24 | GPIO12 |
| P26 | GPIO14 |
And remember to pull up EN and pull down GPIO15.
Software
ESPHome configuration example:
substitutions:
device_name: 'Plug 1'
esphome:
name: plug-1
comment: 'ELIVCO LSPA9 Smart Plug 1'
esp8266:
board: esp12e
restore_from_flash: true
preferences:
flash_write_interval: 10min # reduce write frequency to flash to avoid wearing it out, adjust it as needed
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:
# for hard restart
- platform: restart
id: restart_button
name: 'Restart ${device_name}'
entity_category: diagnostic
status_led: # the built-in blue LED in the button
pin:
number: 2
inverted: true
switch:
# the power relay
- platform: gpio
id: relay
pin: 14
name: '${device_name}'
restore_mode: RESTORE_DEFAULT_OFF # attempt to restore state on start and defaults to OFF if failed
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 # note that the model must be specified to use special calculation parameters
current_resistor: 0.001 # adjust it according to the actual resistor value on board
voltage_divider: 1600 # (680×1000×3+1000)/1000 = 2041, adjust it according to the actual resistor values on board
sel_pin:
number: 12
inverted: true # the logic of BL0937 is opposite from HLW8012
cf_pin: 4
cf1_pin: 5
current:
name: '${device_name} Current'
voltage:
name: '${device_name} Voltage'
power:
name: '${device_name} Power'
energy:
name: '${device_name} Energy'
# convert to kWh
filters:
- multiply: 0.001
unit_of_measurement: 'kWh'
accuracy_decimals: 4
update_interval: 60s
change_mode_every: 3yamlBL0937 Voltage Divider Calculation
The parameter voltage_divider of the hlw8012 component needs to be calculated based on the actual voltage divider resistors, otherwise the voltage data will be inaccurate.
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.Source: https://esphome.io/components/sensor/hlw8012.html#configuration-variables ↗
According to the actual circuit, the voltage divider used in this smart plug is as follows:

So the theoretical value should be (680×1000×3+1000)÷1000=2041, but then the actual result is wrong; after lots of trial-and-error, I found 1600 as a relatively accurate value, but I still don’t know why.
After that, we can add it directly in 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.