esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
291 stars 34 forks source link

PZEM-004T - detect missing data (if power meter is not powered) #4329

Open adynis opened 1 year ago

adynis commented 1 year ago

The problem

If (after working fine) suddenly the PZEM-004T stopps sending data (e.g.: the AC power of PZEM-004T is interrupted) then ... nothing happends: the last value remain active as if everyrhing is normal !? How to detect that actually data is not recent anymore ? that data is not send anymore?

I would like to see a NaN (undefined/unavailable/something else) in case of missing data, or at least to be able to detect when PZEM-004T device does not communciate anymore. Is there any solution?

Which version of ESPHome has the issue?

2023.3.0

What type of installation are you using?

Home Assistant Add-on

Which version of Home Assistant has the issue?

2023.3.5

What platform are you using?

ESP32

Board

No response

Component causing the issue

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

github-actions[bot] commented 11 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

BrainForge commented 11 months ago

I have the same problem, any ideas how to solve it?

LevKos commented 5 months ago

I also faced a similar problem. And it lies in the fact that if there is no power to the high-voltage part, it does not output anything, but in the driver it is processed that if there is nothing, then the values do not change. I suggest making the following changes to pzemac.cpp:

void MYPZEMAC::on_modbus_data(const std::vector &data) { if (data.size() < 20) { ESP_LOGW(TAG, "Invalid size for PZEM AC!"); // add start this->voltagesensor->publish_state(0); this->currentsensor->publish_state(0); this->powersensor->publish_state(0); this->frequencysensor->publish_state(0); this->power_factorsensor->publish_state(0); //add stop return; } .....