v1.1.4
Bug fix: cost no longer jumps negative at midnight on polling-based source sensors (#227)
Affected users: Anyone whose source energy sensor resets at midnight via a polling integration that may skip the explicit 0 reading (e.g. Vue 3 ESPHome total_daily_energy, Deye Modbus daily energy registers, and similar). Symptoms: cost sensor jumps to a large negative value at midnight instead of resetting cleanly to 0, then climbs from negative.
What happened
The reset detection in _async_update_energy_event only triggered when the source sensor reported an exact 0. When polling skips the zero sample and the first post-reset reading is small but non-zero (e.g. 0.1 kWh / 5 Wh), the previous baseline (yesterday's accumulated value, e.g. 49 kWh / 2100 Wh) was used to compute a huge negative delta. Combined with the #215 baseline-snapshot fix, this manifested as the cost sensor diving negative right at midnight.
Fix
Two additional reset-detection paths, aligned with HA's documented sensor conventions:
last_resetattribute change — canonical signal forstate_class=totalresetting sensors (e.g. HA'sutility_meterhelper). Resets are detected even if the value is non-zero.- Decrement on
state_class=total_increasing— per HA convention, any decrease on atotal_increasingsensor is a reset. Covers ESPHometotal_daily_energy, Deye Modbus daily registers, and most polling integrations regardless of how cleanly the device reports the reset moment.
The price-event handler gets the total_increasing decrement check too, to cover the race where a price update reads the post-reset source value before the energy-event handler runs.
Compatibility
- ✅ HA
utility_meterdaily/weekly/monthly helpers — detected vialast_resetchange - ✅ ESPHome
total_daily_energy(modern) — detected viatotal_increasingdecrement - ✅ Deye/Sunsynk Modbus daily registers — detected via
total_increasingdecrement - ✅ Cumulative grid meters (#215 fix preserved) — never decreases, no false positive
- ✅ Bidirectional / feed-in sensors (
state_class=totalwithoutlast_resetchange) — small decrements still treated as legitimate exports; existing feed-in tests pass unchanged
Upgrading
Update via HACS and restart Home Assistant. No configuration changes needed.
Full changelog: v1.1.3...v1.1.4