Fix: Total Import Energy zero-value safeguard for Home Assistant#338
Fix: Total Import Energy zero-value safeguard for Home Assistant#338Xoliul wants to merge 1 commit intodingo35:masterfrom
Conversation
Prevents publishing 0 for EV/Mains Import Active Energy over MQTT and REST when meter hasn't been read yet or on rare comm glitches. A single 0 corrupts HA statistics (state_class: total_increasing). - Add lastKnownEVImportWh/lastKnownMainsImportWh to SettingsCache (NVS) - Add energyValueToPublish() helper - never send less than last known good - Update mqttPublishData, mqttSmartEVSEPublishData, REST GET/POST, MQTT Set/EVMeter Made-with: Cursor
|
Ok so you never found the cause for the 0 value and you built this workaround.... I would prefer to get rid of the origin of the problem. |
|
That would only go wrong the first Wh of the energy meter, which for imported power would soon solve itself. But possible trouble for exported power for meters where no power delivery (solar) are present, not sure how that would behave. Perhaps have some logger running on telnet, with timestamps, would show what causes the bug? |
You can't prevent 0 values from being saved in HA unless you wrap it in a complex template sensor. That's not something anybody does from the start. If you do it afterwards, you lose all previous statistics, as they can not be transferred. It has happened twice for me in one year, both at random moments where nothing much seemed to be happening. For me it is nearly impossible to reproduce. Safeguarding from sending 0, or a lower value seems like an acceptable solution. |
|
Isn't this just overcomplicating things? What if you would only send kWh data to HA that is > 0 ? Or have you seen anything else then a zero in your HA statistical data ? |
|
I agree; the only problem would be on the "exported energy" value of the EV meter, which in general is 0 and will stay that way... |
|
Sure, it can be made simpler. |
|
I would say treat all Meters the same, so also but this safety on the export value for all meters. |
|
Ok the cause of the problem is that after a reboot, using modbus kWh meters, we might be giving out a zero value if the mqtt publish and or the REST publish is done before the answer on the modbus request of the energy value is received. This version guards giving out 0 values for import- and export energy values: Since I have no testing capabilities here, please test !!! |
Prevents publishing 0 for EV/Mains Import Active Energy over MQTT and REST when meter hasn't been read yet or on rare comm glitches. A single 0 corrupts HA statistics (state_class: total_increasing).