[分享] NT$500(兩路),PZEM-004T家庭用電監控(ESPhome)

本文也發布在瀚思彼岸,另個學習HA的好地方。

先上圖:

這是我家的用電監控:

image

這是我家總電箱:

這是計算出每一條迴路可能的極限電流並清楚標示(總電箱、分電箱都一樣):

進入主題:

  1. 用原廠的上位機軟件設定各個PZEM-004T的address,本例設定為4、5、6

上位机软件 链接: https://pan.baidu.com/s/1bz0xh5PuSzBmZfRb-qPLPg**提取码: qi72**
102839yjdyn0j0sjjrsad0

  1. 參考原廠圖示接線,其實3.3V就可以了,不一定非要5V,三顆PZEM的接線並聯接到nodemcu即可。

  2. 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();'
       
2個讚

謝謝分享,研究了一下,做些回饋

  • platform: uart
    name: “${device_name}_Reset”
    data: [0x01, 0x42, 0x80, 0x11]
    這部分的reset是針對modbus位址1的reset

程式裡的modbus為4,5,6不適用,建議改為

  • platform: uart
    name: “${device_name}_pzemac4_Reset”
    data: [0x04, 0x42, 0x83, 0x41]
  • platform: uart
    name: “${device_name}_pzemac5_Reset”
    data: [0x05, 0x42, 0x82, 0xD1]
  • platform: uart
    name: “${device_name}_pzemac6_Reset”
    data: [0x06, 0x42, 0x82, 0x21]

如此可重置設備裡的累計電量(energy)

1個讚

另外,pzemac也提供energy重置的功能–

on_…:
then:
- pzemac.reset_energy: pzemac_1

套用進程式就是

button:

  • platform: template
    name: “pzemac4_energy_reset”
    on_press:
    • pzemac.reset_energy: pzemac4
  • platform: template
    name: “pzemac5_energy_reset”
    on_press:
    • pzemac.reset_energy: pzemac5
  • platform: template
    name: “pzemac6_energy_reset”
    on_press:
    • pzemac.reset_energy: pzemac6
2個讚

不知道使用廣播Address(0x00)能不能達到全部重設的功能?
0x00 , 0x42 , 0x81, 0x81

didibaba 您好

請問如何秀出昨天的用電量

謝謝

請問一個PZEM-004T只能接一個CT嗎?如果可以接多個CT的話,會有辦法辨別是在各CT的數值嗎?

1個pzem 只能接1顆CT

如果監控入戶線,是要兩個pzem個別監控是嗎?
那這樣pzem的電源就是要接再110V NFB後面?

是的, 一般家庭單相三線或四線就是兩個pzem各別監控兩條入戶火線