本帖最后由 郑小贤 于 2023-6-18 10:23 编辑
硬件:
D1mini(ESP12F)
培正PZEM-004
软件
ESPHOME
代码如下
# 电量统计
substitutions:
device_name: esp12felectricitystatistics
esphome:
name: ${device_name}
esp8266:
board: d1_mini
# Enable logging
logger:
api:
password: !secret api_password
ota:
password: !secret ota_password
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: ${device_name}
password: !secret ap_password
captive_portal:
uart:
rx_pin:
number: D3
tx_pin:
number: D4
baud_rate: 9600
id: mod_uart
modbus:
send_wait_time: 50ms
uart_id: mod_uart
id: mod_bus
sensor:
- platform: pzemac
current:
name: "${device_name}_Current"
voltage:
name: "${device_name}_Voltage"
energy:
name: "${device_name}_Energy"
unit_of_measurement: kWh
device_class: energy
state_class: total_increasing
accuracy_decimals: 3
filters:
- multiply: 0.001
power:
name: "${device_name}_Power"
frequency:
name: "${device_name}_Frequency"
power_factor:
name: "${device_name}_Factor"
address: 1
modbus_id: mod_bus
update_interval: 10s
培正模块与D1mini接线示意图培正模块 D1mini
GND ——> GND
TX ——> D3
RX ——> D4
5V ——> 5V
添加集成后,实现的效果如下。
PZEM-004检测能源
再进入到Homeassistant,配置-仪表盘-能源,配置电能实体。
配置电能
到这一步,HA就可以检测我们家里的能源消耗啦。
下一期出,通过自定义电费单价实体,实现HA能源电费计算。
尽请期待。
|