vinceg0267
(Vinceg0267)
November 25, 2023, 4:13pm
1
Hi, I’m trying to reset the energy of my three pzem but it doesn’t work. The log indicates the button is pressed but the energy does not reset.
esphome:
name: energy-monitor
friendly_name: Energy Monitor
esp32:
board: esp32dev
framework:
type: arduino
# Enable logging
logger:
level: debug
baud_rate: 0
# Enable Home Assistant API
api:
encryption:
key: "xxxx"
ota:
password: "xxxxxx"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Energy-Monitor Fallback Hotspot"
password: "D3TIYYhX2HNE"
captive_portal:
uart:
- id: ubus
rx_pin: GPIO1
tx_pin: GPIO3
baud_rate: 9600
stop_bits: 1
modbus:
id: mbus
uart_id: ubus
sensor:
- platform: pzemac
id: pzemac_1
modbus_id: mbus
address: 1
current:
name: "ID1 Current"
voltage:
name: "ID1 Voltage"
energy:
name: "ID1 Energy"
power:
name: "ID1 Power"
frequency:
name: "ID1 Frequency"
power_factor:
name: "ID1 Power Factor"
update_interval: 10s
- platform: pzemac
id: pzemac_2
modbus_id: mbus
address: 2
current:
name: "ID2 Current"
voltage:
name: "ID2 Voltage"
energy:
name: "ID2 Energy"
power:
name: "ID2 Power"
frequency:
name: "ID2 Frequency"
power_factor:
name: "ID2 Power Factor"
update_interval: 10s
- platform: pzemac
id: pzemac_3
modbus_id: mbus
address: 3
current:
name: "ID3 Current"
voltage:
name: "ID3 Voltage"
energy:
name: "ID3 Energy"
power:
name: "ID3 Power"
frequency:
name: "ID3 Frequency"
power_factor:
name: "ID3 Power Factor"
update_interval: 10s
button:
- platform: template
name: Pzem Reset
on_press:
- pzemac.reset_energy: pzemac_1
- pzemac.reset_energy: pzemac_2
- pzemac.reset_energy: pzemac_3
vinceg0267
(Vinceg0267)
November 25, 2023, 4:33pm
3
do you mean I have to set the logger to verbose?
Antoled
(Antonino)
November 27, 2023, 6:48pm
5
switch:
- platform: uart
name: "Reset KW Totali"
data: [0x01, 0x42, 0x80, 0x11]
1 Like
vinceg0267
(Vinceg0267)
November 28, 2023, 5:08am
6
This is solution, thank’s
1 Like
Antoled
(Antonino)
November 28, 2023, 5:47am
7
Perfect !
My pzem-004t code use double sensor ;
1: 2 second sample no register database
2 : 60 second register database
Pzem RX > Wemos D6
Pzem TX > Wemos D5
Codice ESPHOME
-------------------------------------------------------------------------------------------------------
esphome:
name: contatore
platform: ESP8266
board: d1_mini
substitutions:
name: PZEM
# Enable logging
logger:
# Enable Home Assistant API
api:
password: "xxxxxx"
ota:
password: "xxxxx"
wifi:
ssid: "xxxxxx"
password: "xxxxxxx"
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Contatore Fallback Hotspot"
password: "xxxxxx"
captive_portal:
web_server:
port: 80
# Example configuration entry
uart:
rx_pin: D6
tx_pin: D5
baud_rate: 9600
time:
- platform: sntp
id: sntp_time
modbus:
################################################################################
# Slow sensors for Home assistant #
################################################################################
sensor:
- platform: pzemac
current:
id: aac
internal: true
icon: "mdi:alpha-a-circle"
voltage:
id: vac
internal: true
icon: "mdi:alpha-v-circle"
power:
id: w
internal: true
icon: "mdi:alpha-w-circle"
power_factor:
id: pf
internal: true
icon: "mdi:alpha-w-circle"
update_interval: 2s
#----------------------------------
- platform: total_daily_energy
name: "PZEM Consumption"
power_id: w
filters:
- multiply: 0.001
unit_of_measurement: kWh
icon: mdi:counter
accuracy_decimals: 1
#----------------------------------
- platform: template
name: "PZEM Ampere_HI"
lambda: |-
if (id(aac).state) {
return (id(aac).state);
} else {
return 0;
}
unit_of_measurement: A
icon: "mdi:alpha-a-circle"
update_interval: 2s
- platform: template
name: "PZEM Ampere_SL"
lambda: |-
if (id(aac).state) {
return (id(aac).state);
} else {
return 0;
}
unit_of_measurement: A
icon: "mdi:alpha-a-circle"
update_interval: 200s
#-------------------------------
- platform: template
name: "PZEM Volt_HI"
lambda: |-
if (id(vac).state) {
return (id(vac).state);
} else {
return 0;
}
unit_of_measurement: V
icon: "mdi:alpha-v-circle"
update_interval: 2s
- platform: template
name: "PZEM Volt_SL"
lambda: |-
if (id(vac).state) {
return (id(vac).state);
} else {
return 0;
}
unit_of_measurement: V
icon: "mdi:alpha-v-circle"
update_interval: 200s
#---------------------------------
- platform: template
name: "PZEM Watt_HI"
lambda: |-
if (id(w).state) {
return (id(w).state);
} else {
return 0;
}
unit_of_measurement: W
icon: "mdi:alpha-w-circle"
update_interval: 2s
- platform: template
name: "PZEM Watt_SL"
lambda: |-
if (id(w).state) {
return (id(w).state);
} else {
return 0;
}
unit_of_measurement: W
icon: "mdi:alpha-w-circle"
update_interval: 200s
#-----------------------------------------------
- platform: template
name: "PZEM PF_HI"
lambda: |-
if (id(pf).state) {
return (id(pf).state);
} else {
return 0;
}
unit_of_measurement: φ
icon: "mdi:angle-acute"
update_interval: 2s
- platform: template
name: "PZEM PF_SL"
lambda: |-
if (id(pf).state) {
return (id(pf).state);
} else {
return 0;
}
unit_of_measurement: φ
icon: "mdi:angle-acute"
update_interval: 200s
switch:
- platform: uart
name: "Reset KW Totali"
data: [0x01, 0x42, 0x80, 0x11]
---------------------------------------------------
Configuration.yaml :
utility_meter:
daily_energy:
source: sensor.pzem_consumption
cycle: daily
monthly_energy:
source: sensor.pzem_consumption
cycle: monthly
-------------------------------------------------
Per registrare solo gli eventi dei sensori SL esposti e escluderi i dati ogni 2sec:
inserire nel configuration.yaml:
#https://home-assistant.io/components/recorder/
recorder:
commit_interval: 30
exclude:
entities:
- sensor.pzem_volt_hi
- sensor.pzem_watt_hi
- sensor.pzem_pf_hi
- sensor.pzem_ampere_hi
vinceg0267
(Vinceg0267)
November 29, 2023, 8:32am
8
Antoled:
Perfect !
My pzem-004t code use double sensor ;
1: 2 second sample no register database
2 : 60 second register database
Per registrare solo gli eventi dei sensori SL esposti e escluderi i dati ogni 2sec:
inserire nel configuration.yaml:
#Recorder - Home Assistant
recorder:
commit_interval: 30
exclude:
entities:
- sensor.pzem_volt_hi
- sensor.pzem_watt_hi
- sensor.pzem_pf_hi
- sensor.pzem_ampere_hi
What are the advantages of using slow sensors?
Antoled
(Antonino)
November 29, 2023, 11:08am
9
The sensor that updates quickly is only used to display the data, some appliances in the house have strange behavior, and you see every behavior. The slowly updating sensor is used to record data in the database and not fill it with data.