PZEM004T v1 (export version) or local V3 — see
Shopee
.
An ESP32 or ESP32-C3 SuperMini. For an ESP32-C3 SuperMini, a model with an antenna is recommended (see
Shopee
).
Additional hardware reference
If the current PZEM004T model is unsuitable or you want to compare another version, see
another PZEM004T model on Shopee
. Before wiring it, verify the exact version, pinout, and module voltage.
esphome:name:pzem004t-mqttfriendly_name:PZEM004T to MQTTmin_version:2025.3.2name_add_mac_suffix:trueplatformio_options:board_build.f_flash:40000000Lboard_build.flash_mode:dioboard_build.flash_size:4MBesp32:board:esp32-c3-devkitm-1framework:type:esp-idfuart:rx_pin:8tx_pin:9baud_rate:9600modbus:mqtt:broker:"192.168.0.4"username:"user"password:"password"discovery:falsediscover_ip:falsewifi:ssid:"WIFI SSID"password:"********"ota:- platform:esphomepassword:"******"logger:level:INFOsensor:- platform:pzemaccurrent:name:"PZEM-004T Current"voltage:name:"PZEM-004T Voltage"energy:# Multiply Energy by 0.001 to convert Wh to kWh.name:"PZEM-004T Energy"filters:- multiply:0.001power:name:"PZEM-004T Power"frequency:name:"PZEM-004T Frequency"power_factor:name:"PZEM-004T Power Factor"update_interval:2s- platform:wifi_signalname:"WiFi Signal dB"id:wifi_signal_dbupdate_interval:300s- platform:copysource_id:wifi_signal_dbname:"WiFi Signal Percent"filters:- lambda:return min(max(2 * (x + 100.0), 0.0), 100.0);unit_of_measurement:"Signal %"
Lines 17-18 configure the RX/TX pins on the ESP32-C3.
Lines 24-26 configure the MQTT broker.
Lines 31-32 configure Wi-Fi.
Line 36 configures the OTA update password.
Line 58 sets the MQTT broker update interval.
Check the MQTT broker to confirm that it has received the measurements.
UID:mqtt:topic:17653025f5:3574a13d85label:PZEM004T Power MonitorthingTypeUID:mqtt:topicconfiguration:{}bridgeUID:mqtt:broker:17653025f5location:Housechannels:- id:PZEM004T_House_VoltagechannelTypeUID:mqtt:numberlabel:PZEM004T House Voltagedescription:""configuration:stateTopic:pzem004t-mqtt-be5d84/sensor/pzem-004t_voltage/state- id:PZEM004T_House_PowerchannelTypeUID:mqtt:numberlabel:PZEM004T House Powerdescription:""configuration:stateTopic:pzem004t-mqtt-be5d84/sensor/pzem-004t_power/state- id:PZEM004T_House_CurrentchannelTypeUID:mqtt:numberlabel:PZEM004T House Currentdescription:""configuration:stateTopic:pzem004t-mqtt-be5d84/sensor/pzem-004t_current/state- id:PZEM004T_House_EnergychannelTypeUID:mqtt:numberlabel:PZEM004T House Energydescription:""configuration:stateTopic:pzem004t-mqtt-be5d84/sensor/pzem-004t_energy/state- id:PZEM004T_House_FreqchannelTypeUID:mqtt:numberlabel:PZEM004T House Frequencydescription:""configuration:stateTopic:pzem004t-mqtt-be5d84/sensor/pzem-004t_frequency/state- id:PZEM004T_House_PowerFactorchannelTypeUID:mqtt:numberlabel:PZEM004T House PowerFactordescription:""configuration:stateTopic:pzem004t-mqtt-be5d84/sensor/pzem-004t_power_factor/state- id:PZEM004T_House_Sensor_StatuschannelTypeUID:mqtt:stringlabel:PZEM004T House Sensor Statusdescription:""configuration:stateTopic:pzem004t-mqtt/status- id:PZEM004T_House_Wifi_Sginal_Level_dBchannelTypeUID:mqtt:numberlabel:PZEM004T House Wifi Sginal Level dBdescription:""configuration:stateTopic:pzem004t-mqtt-be5d84/sensor/wifi_signal_db/state- id:PZEM004T_House_Wifi_Sginal_Level_PercentchannelTypeUID:mqtt:numberlabel:PZEM004T House Wifi Sginal Level Percentdescription:""configuration:stateTopic:pzem004t-mqtt-be5d84/sensor/wifi_signal_percent/state
BONUS: DSL script to calculate energy consumption for the day, month, and a selected period.
The results are updated in Energy_Consumption_Day, Energy_Consumption_Month, and Energy_Consumption_Period.
logInfo("EnergyConsumption", "Current Energy: " + PZEM004T_House_Energy.state.toString + " - " + now.toString)
val startOfDay = now.with(LocalTime.MIDNIGHT)
val startOfMonth = now.withDayOfMonth(1).with(LocalTime.MIDNIGHT)
val startOfPeriod = now.withMonth(4).withDayOfMonth(1).with(LocalTime.MIDNIGHT) // Starts on April 1
val dayAgoValue = PZEM004T_House_Energy.persistedState(startOfDay)
val monthAgoValue = PZEM004T_House_Energy.persistedState(startOfMonth)
val periodAgoValue = PZEM004T_House_Energy.persistedState(startOfPeriod)
val currentEnergy = PZEM004T_House_Energy.state as QuantityType<Number>
val dayEnergy = dayAgoValue.state as QuantityType<Number>
val monthEnergy = monthAgoValue.state as QuantityType<Number>
val periodEnergy = periodAgoValue.state as QuantityType<Number>
val dailyConsumption = (currentEnergy.subtract(dayEnergy)).doubleValue
val monthlyConsumption = (currentEnergy.subtract(monthEnergy)).doubleValue
val periodConsumption = (currentEnergy.subtract(periodEnergy)).doubleValue
// Update Items with calculated values
Energy_Consumption_Day.postUpdate(dailyConsumption)
Energy_Consumption_Month.postUpdate(monthlyConsumption)
Energy_Consumption_Period.postUpdate(periodConsumption)
Góp Ý / Bình Luận / Đánh giá