Skip to content

v1.1.4

Choose a tag to compare

@martinarva martinarva released this 29 Apr 18:25

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_reset attribute change — canonical signal for state_class=total resetting sensors (e.g. HA's utility_meter helper). Resets are detected even if the value is non-zero.
  • Decrement on state_class=total_increasing — per HA convention, any decrease on a total_increasing sensor is a reset. Covers ESPHome total_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_meter daily/weekly/monthly helpers — detected via last_reset change
  • ✅ ESPHome total_daily_energy (modern) — detected via total_increasing decrement
  • ✅ Deye/Sunsynk Modbus daily registers — detected via total_increasing decrement
  • ✅ Cumulative grid meters (#215 fix preserved) — never decreases, no false positive
  • ✅ Bidirectional / feed-in sensors (state_class=total without last_reset change) — 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