Skip to content

fix: drift-free self-consumption (Option B)

Choose a tag to compare

@hoizi89 hoizi89 released this 28 Apr 13:35

πŸ› Bug Fix β€” Self-Consumption drift

Same systemic bug fixed via the same Option-B approach as in pv_management_fix v2.0.3.

Root cause (short)

`max(0, delta_pv - delta_export)` per state_changed event accumulates drift when PV/Export sensors fire asynchronously. Most visible on setups with separate sensors (Growatt-HAR, smart meter + inverter), invisible on synchronous Wechselrichter that bundle updates.

Fix

Self-Consumption + Feed-In computed from absolute totals via persisted baselines:

```python
total_self_consumption = baseline_self
+ (current_pv - baseline_pv)
- (current_export - baseline_export)
```

Self-correcting, behaviour-identical for synchronous setups.

Migration

  • New `baseline_*` fields in storage
  • Seeded from current sensor state at first update after upgrade
  • First computation yields Ξ”=0 β†’ existing values preserved
  • Sensor-reset detection rebases without disturbing totals

βœ… No breaking changes

  • Config / storage backward-compatible
  • HACS update + restart

Full Changelog: v4.0.3...v4.0.4