fix(deye): source energy counters from the Daily registers - #4391
Merged
Conversation
DEYE_ENERGY_KEYS mapped Predbat's *_today args onto the lifetime "Total*" accumulators. Those are firmware-derived and drift: on a live capture TotalConsumption read 14332.40 kWh where the other lifetime counters implied 15475.00 (buy 13579.20 + PV 2208.30 - sell 11.80 + discharge 5255.90 - charge 5556.60), a 7.4% shortfall. That fed straight into Predbat's learned load, so load_today climbed slower than the house actually consumed and every charge window came out under-sized. The Daily registers balance exactly on the same payload (DailyConsumption 12.80 = DailyActiveProduction 4.50 + DailyEnergyPurchased 7.00 - DailyGridFeedIn 0.00 + DailyDischargingEnergy 4.10 - DailyChargingEnergy 2.80), so all four counters now read from them. The old comment claimed daily counters were unusable because Predbat needs an incrementing series and a midnight reset would read as a large negative delta. That is not the case: minute_data() smooths the near-midnight drop and clean_incrementing_reverse() re-bases on any reset to <= 0, so the nightly return to 0.00 is absorbed. Comment corrected rather than left to mislead. Tests: energy counters now assert the Daily values, plus a new test pinning the daily energy balance so a drifted key spelling breaks the sum - the same failure that hid the original bug. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes DEYE inverter energy counter sourcing so Predbat’s *_today history inputs come from DEYE’s Daily* registers (which balance correctly) rather than the drifting lifetime Total* accumulators, improving learned load accuracy and downstream charge-window sizing.
Changes:
- Remap
DEYE_ENERGY_KEYStoDailyEnergyPurchased,DailyGridFeedIn,DailyActiveProduction, andDailyConsumption, and update related in-code comments. - Update DEYE tests to assert the daily-register mapping and add a balance-guard test for the daily register set.
- Bump Predbat version to
v8.47.1.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| apps/predbat/deye_const.py | Switches energy counter key mapping from Total* to Daily* and updates rationale comments. |
| apps/predbat/deye.py | Updates published-sensor comment to reflect daily counters and reset handling. |
| apps/predbat/tests/test_deye_api.py | Replaces lifetime-counter assertion with daily-register assertions; adds a daily energy balance guard test and updates registry entries. |
| apps/predbat/tests/test_deye_publish.py | Updates publish/config mapping test expectations to daily-register magnitudes. |
| apps/predbat/predbat.py | Version bump to v8.47.1. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
load_todaywas climbing slower than the house actually consumed, which made Predbat's learned load too low and under-sized every charge window.DEYE_ENERGY_KEYSmapped Predbat's*_todayargs onto the lifetimeTotal*accumulators. Those are firmware-derived and drift. On a live capture (productId 0_5411_1, 3-phase hybrid):A 7.4% shortfall, and it lands directly on the load history Predbat learns from.
Fix
The
Daily*registers balance exactly on that same payload:So all four counters now read from them:
import_todayTotalEnergyBuyDailyEnergyPurchasedexport_todayTotalEnergySellDailyGridFeedInpv_todayTotalActiveProductionDailyActiveProductionload_todayTotalConsumptionDailyConsumptionOn the midnight reset
The previous comment justified the lifetime choice by claiming Predbat needs an incrementing series and a daily reset "would read as a large negative delta every night". That is not the case, and the comment is corrected rather than left to mislead:
minute_data()smooths the near-midnight drop (thenear_midnightbranch inutils.py)clean_incrementing_reverse()re-bases on any reset to<= 0, so the nightly return to0.00is absorbed regardless of whether the inverter's day boundary aligns with local midnightTests
energy_counters_daily_registers— asserts all four resolve to the Daily values on the captured live payload (replaces the test that pinned the lifetime values)daily_energy_balance— new; pins the daily energy balance so a drifted key spelling breaks the sum. That is the same failure mode that hid the original bug./run_all -k deyeand./run_all --quickpass;./run_pre_commitclean.Version bumped to v8.47.1.
🤖 Generated with Claude Code