惠桔和家亲X1S智能插座目前(2024-04)在闲鱼上卖15元一个,5个包邮,性价比挺高。该插座带电量统计功能,原使用和家亲APP控制。
插座使用胶水粘合,只能强行破拆,用螺丝刀或者撬棍从缝隙插入慢慢撬。主控模块是tuya CB2S,CB2S内部芯片是BK7231M,计量芯片是BL0937。
BK7231N和BK7231T都可以直接刷入esphome,而BK7231M似乎还没有方法刷入esphome,那只能用替换大法了,我是用ESP-02S这个模块来替换,这个模块的外形、尺寸和CB2S完全一样,这个模块内部芯片是esp8285,和esp8266相似,目前淘宝的价格是5.x元,邮费5.x元。
更换模块需要将电路板拆出来,要注意一个,拆电路板需要焊掉这两个焊点:
先给ESP-02S模块刷好固件,再将模块焊接进去。
esphome代码:
esphome:
name: "esphome-x1s-mod"
friendly_name: "ESPHome_x1s-mod"
esp8266:
board: esp8285
restore_from_flash: true
substitutions:
# 非常重要!!这里要校准,见文章说明!!
voltage_divider: "2351"
current_resistor: "0.001"
current_multiply: "1"
preferences:
flash_write_interval: 10s
# Enable logging
logger:
baud_rate: 0
# Enable Home Assistant API
api:
encryption:
key: "改你自己的"
ota:
password: "改你自己的"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Esphome-x1s-mod Fallback Hotspot"
password: "改你自己的"
captive_portal:
web_server:
status_led:
pin:
number: TX
inverted: True
output:
- platform: gpio
id: led1
pin:
number: RX
inverted: True
switch:
- platform: gpio
pin: GPIO13
name: "Relay"
id: relay1
restore_mode: RESTORE_DEFAULT_OFF
# RESTORE_DEFAULT_OFF RESTORE_DEFAULT_ON ALWAYS_OFF ALWAYS_ON
on_turn_on:
- output.turn_on: led1
on_turn_off:
- output.turn_off: led1
binary_sensor:
- platform: gpio
pin: GPIO12
name: "Switch"
filters:
- delayed_on_off: 100ms
on_press:
then:
- switch.toggle: relay1
sensor:
- platform: hlw8012
model: BL0937
current_resistor: ${current_resistor}
voltage_divider: ${voltage_divider}
sel_pin:
number: GPIO14
inverted: true
cf_pin:
number: GPIO5
inverted: true
cf1_pin:
number: GPIO4
inverted: true
current:
name: "Current"
accuracy_decimals: 3
filters:
- multiply: ${current_multiply}
voltage:
name: "Voltage"
accuracy_decimals: 2
power:
name: "Power"
id: my_power
accuracy_decimals: 2
energy:
name: "Energy"
accuracy_decimals: 2
update_interval: 2s
- platform: total_daily_energy
name: "Daily Energy"
power_id: my_power
accuracy_decimals: 2
- platform: wifi_signal
name: "WiFi Signal"
update_interval: 10s
- platform: uptime
name: Uptime
update_interval: 10s
替换模块后的样子:
然后还有一件很重要的事情是校准BL0937芯片的计量,才能让电压、电流、功率等正确显示,可以参考esphome官方的校准方法 https://esphome.io/components/sensor/hlw8012.html
如果你不想校准,可以试试我的校准参数,不保证能用。
将代码里的:
voltage_divider: "2351"
current_resistor: "0.001"
current_multiply: "1"
改成:
voltage_divider: "1578.5763"
current_resistor: "0.001072"
current_multiply: "0.8539"
在 esphome 里面显示的样子: