本文也發布在瀚思彼岸,另個學習HA的好地方。
先上圖:
這是我家的用電監控:
這是我家總電箱:
這是計算出每一條迴路可能的極限電流並清楚標示(總電箱、分電箱都一樣):
進入主題:
- 用原廠的上位機軟件設定各個PZEM-004T的address,本例設定為4、5、6
上位机软件 链接: https://pan.baidu.com/s/1bz0xh5PuSzBmZfRb-qPLPg**提取码: qi72**
-
參考原廠圖示接線,其實3.3V就可以了,不一定非要5V,三顆PZEM的接線並聯接到nodemcu即可。
-
ESPHOME的code,yaml裡面的電壓x2是因為台灣的家庭用電電壓是110V(單相三線),而本例是用來監控三台220V空調的所以x2,一般使用則不需要
一般家用通常可能只會監控入戶的兩條火線,則86明盒的大小還蠻適合的,所有零組件剛剛好能放進去:
substitutions:
device_name: energy-ac46
esphome:
name: ${device_name}
platform: ESP8266
board: nodemcuv2
logger:
baud_rate: 0 # (UART logging interferes with pzem)
level: DEBUG
#hardware_uart: uart1
api:
ota:
password: !secret wifi_pw
web_server:
port: 80
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_pw
ap:
ssid: ${device_name}_Fallback
password: !secret wifi_pw
#manual_ip:
#static_ip: 192.168.200.111
#gateway: 192.168.200.254
#subnet: 255.255.255.0
captive_portal:
uart:
- tx_pin: D1
rx_pin: D2
baud_rate: 9600
stop_bits: 1
modbus:
binary_sensor:
- platform: status
name: "${device_name} Status"
sensor:
- platform: pzemac
id: pzemac4
energy:
name: "energy_ac4"
filters:
- multiply: 0.002
unit_of_measurement: kWh
accuracy_decimals: 1
current:
name: "current_ac4"
id: "current_ac4"
accuracy_decimals: 1
voltage:
name: "voltage_ac4"
filters:
- multiply: 2
accuracy_decimals: 1
frequency:
name: "frequency_ac4"
accuracy_decimals: 1
power_factor:
name: "factor_ac4"
accuracy_decimals: 1
power:
name: "power_ac4"
id: "power_ac4"
filters:
- multiply: 2
accuracy_decimals: 0
update_interval: never
address: 4
- platform: pzemac
id: pzemac5
energy:
name: "energy_ac5"
filters:
- multiply: 0.002
unit_of_measurement: kWh
accuracy_decimals: 1
current:
name: "current_ac5"
id: "current_ac5"
accuracy_decimals: 1
voltage:
name: "voltage_ac5"
filters:
- multiply: 2
accuracy_decimals: 1
frequency:
name: "frequency_ac5"
accuracy_decimals: 1
power_factor:
name: "factor_ac5"
accuracy_decimals: 1
power:
name: "power_ac5"
id: "power_ac5"
filters:
- multiply: 2
accuracy_decimals: 0
update_interval: never
address: 5
- platform: pzemac
id: pzemac6
energy:
name: "energy_ac6"
filters:
- multiply: 0.002
unit_of_measurement: kWh
accuracy_decimals: 1
current:
id: "current_ac6"
name: "current_ac6"
accuracy_decimals: 1
voltage:
name: "voltage_ac6"
filters:
- multiply: 2
accuracy_decimals: 1
frequency:
name: "frequency_ac6"
accuracy_decimals: 1
power_factor:
name: "factor_ac6"
accuracy_decimals: 1
power:
name: "power_ac6"
id: "power_ac6"
filters:
- multiply: 2
accuracy_decimals: 0
update_interval: never
address: 6
- platform: total_daily_energy
name: "energy_ac4_daily"
power_id: power_ac4
id: energy_ac4_daily
unit_of_measurement: kWh
accuracy_decimals: 1
icon: mdi:counter
filters:
- multiply: 0.001
- platform: total_daily_energy
name: "energy_ac5_daily"
power_id: power_ac5
id: energy_ac5_daily
unit_of_measurement: kWh
accuracy_decimals: 1
icon: mdi:counter
filters:
- multiply: 0.001
- platform: total_daily_energy
name: "energy_ac6_daily"
power_id: power_ac6
id: energy_ac6_daily
unit_of_measurement: kWh
accuracy_decimals: 1
icon: mdi:counter
filters:
- multiply: 0.001
- platform: template
name: "today_ac46"
id: "today_ac46"
icon: mdi:counter
device_class: energy
state_class: measurement
unit_of_measurement: kWh
accuracy_decimals: 1
lambda: |-
return id(energy_ac4_daily).state + id(energy_ac5_daily).state + id(energy_ac6_daily).state ;
# return id(energy1_all_daily).raw_state + id(energy2_all_daily).raw_state
#################################
#SLOW SENSORS FOR HOME ASSISTANT#
#################################
- platform: template #########################
name: "current_ac4_slow"
lambda: |-
if (id(current_ac4).state) {
return (id(current_ac4).state);
} else {
return 0;
}
unit_of_measurement: A
icon: "mdi:alpha-a-circle"
update_interval: 60s
- platform: template #########################
name: "current_ac5_slow"
lambda: |-
if (id(current_ac5).state) {
return (id(current_ac5).state);
} else {
return 0;
}
unit_of_measurement: A
icon: "mdi:alpha-a-circle"
update_interval: 60s
- platform: template #########################
name: "current_ac6_slow"
lambda: |-
if (id(current_ac6).state) {
return (id(current_ac6).state);
} else {
return 0;
}
unit_of_measurement: A
icon: "mdi:alpha-a-circle"
update_interval: 60s
time:
- platform: homeassistant
id: homeassistant_time
switch:
- platform: restart
name: "${device_name}_Restart"
- platform: uart
name: "${device_name}_Reset"
data: [0x01, 0x42, 0x80, 0x11]
interval:
- interval: 5s
then:
- lambda: 'id(pzemac4).update();'
- delay: 150ms
- lambda: 'id(pzemac5).update();'
- delay: 150ms
- lambda: 'id(pzemac6).update();'