ELIVCO LSPA9 Smart Plug
Background
A friend of mine recommended a smart plug Athom PG01EU16A
that supports Tasmota, so I purchased two of these 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, we can crack it open by applying pressure to the top sides.
Hacking
After disassembling it, I saw a model number CB2S
printed on the WiFi 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 mines 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:
Update: @Oscar found a drop-in replacement module: TYWE2S Replacement Module (ESP-02S)
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.3V power source for the WiFi 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; note that pin P26
which is connected to the relay should not use ESP GPIOs that will be pulled up at boot, such as 1, 2, 3, 16, etc., to avoid unintended powering.
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
Example ESPHome configuration:
esphome:
name: plug-1
comment: 'Plug 1'
esp8266:
board: esp12e
restore_from_flash: true # enable this for restoring the relay state on reset
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
api:
ota:
password: !secret ota_password
status_led: # use the on-board blue LED as status indicator (as it was originally)
pin:
number: 2
inverted: true # due to it's connected in sink logic
switch: # the socket relay
- platform: gpio
pin: 14
id: plug_1
name: 'Plug 1'
restore_mode: RESTORE_DEFAULT_OFF # attempt to restore state and default to OFF if failed
binary_sensor: # the button
- platform: gpio
pin:
number: 13
inverted: true
id: button
internal: true # don't expose it to HASS, only use it locally
on_release:
then:
- switch.toggle: plug_1 # toggle the relay
sensor:
- platform: hlw8012
model: BL0937 # note that the model must be specified to use special calculation parameters
voltage_divider: 1600 # 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: 'Plug 1 Current'
voltage:
name: 'Plug 1 Voltage'
power:
name: 'Plug 1 Power'
energy:
name: 'Plug 1 Energy'
# convert it to kWh
filters:
- multiply: 0.001
unit_of_measurement: 'kWh'
accuracy_decimals: 4
update_interval: 60s
change_mode_every: 3
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.
The value of the voltage divider on the board as
(R_upstream + R_downstream) / R_downstream
. Defaults to the Sonoff POW’s value2351
.
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 the reason.
After that, we can add it directly in Home Assistant:
8 Comments
dima · 2023-02-05 at 07:36
thank so much for your research! I'v redone successfully 3 plugs according to your method
Oscar P · 2023-03-01 at 14:46
Hi Zry.io,
I'm thinking about replacing the old CB2S with an ESP02, do you think I could?
Apart from that I don't know how to flash it, I didn't even google it I'll find it out!!
thanks a lot!
zry98 · 2023-03-01 at 21:03
Hi, if by ESP02 you mean those tiny ones with only 8 pins (5 usable IO pins), I think it's still possible to do the job by giving up the blue LED indicator (connected on P8).
Oscar P · 2023-03-01 at 22:55
Ok, I'll give a try tomorrow, thaks a lot for such a very quick answer!!!!
Oscar P · 2023-03-11 at 12:16
Hi again Zry.io, I'm afraid i need some help. Yesterday I tried with ESP02 replacing the old CB2S but for some reason the relay doesn't work. According to your schema, the pin that goes to the relay is P26 which corresponds to GPIO14 in my ESP02, I have tested it with and without inverted but it still doesn't work. Any hints? Could it be that the relay is somehow broken?
Many thanks
Oscar
zry98 · 2023-03-11 at 20:44
Hi Oscar, are you sure it's an
ESP02
with 8 pins like this? Since I've never used one of these, and couldn't find any other official docs other than this, it says that GPIO14 (although I only see GPIO15 in its photo) is also connected toCH_PD
(CHIP_EN
in datasheet) so it won't work as a GPIO. Can you confirm the model and pins?Oscar P · 2023-03-11 at 22:30
Hi zry98, it is like this: https://templates.blakadder.com/ESP-02S.html
Many thanks again for your fast answer!!!
zry98 · 2023-03-21 at 04:29
I had no idea that modules like this existed! it will make replacing CB2S modules with Beken SoC so much easier. However you will have to change the ESPHome config to match the GPIOs.