Skip to content

fix(energy): check the day counter against the since-last-charge counter - #556

Closed
joszz wants to merge 1 commit into
mainfrom
fix/bev-day-counter
Closed

joszz wants to merge 1 commit into
mainfrom
fix/bev-day-counter

Conversation

@joszz

@joszz joszz commented Nov 4, 2026

Copy link
Copy Markdown
Owner

Refs #551 (not Fixes until the reporter confirms on the car).

What the telemetry shows

The reporter's telemetry.csv (MG ZS EV Long Range, 2022) settles which of the two suspects in the issue it is. Neither:

  • The correction factor is fine. PowerUsageSinceLastCharge went from 8.86 to 11.12 kWh while the state of charge dropped from 53.8 % to 50.5 %: 2.26 kWh against 3.3 % of 68.3 kWh = 2.25 kWh. HvSocKwh dropped by the same 2.26. The gateway scales both counters with the same factor, so the scale is right too.
  • The day counter is broken on this car. PowerUsageOfDay gains 33 to 35 kWh at some polls while the car is parked and nothing else moves: 33.16, then 66.23 two minutes later, then 99.48, then 134.24 on a 4 km day. The next day it starts at 34.67 with 0 km driven. Small real rises (0.09 kWh steps while driving) sit on top of those jumps.

The fix

The two counters come out of the same charge status message, so the since-last-charge counter is the reference for the day counter.

  • API (DailyStatsBuilder): per day, compare the counters' rises within runs where neither reset (a charge resets since-last-charge), and on a day without a charge compare the day total with what had left the battery since the last charge (factor 1.5 plus 1 kWh for regeneration and rounding). DailyStat gains sinceChargeTotal (the day off the since-last-charge counter, starting from the last reading before the day, so cached and uncached days agree) and counterUnbacked.
  • Frontend (utils/energy): dailyCounterTotal uses sinceChargeTotal for a flagged day on a car that plugs in. A plain hybrid stays on its day counter, because its counters hold fuel and the check has never been validated against one. The daily usage chart, month table and level history dialog all read through it.
  • Live cards: todaysEnergyKwh hides the kWh-today and Wh/km values when the day counter holds more than left the battery since a charge that was more than 24 hours ago. The since-last-charge efficiency card is unchanged and keeps working.

With the reporter's rows the chart reads 0.75 kWh on 2 Nov and 1.51 kWh on 3 Nov (0.85 kWh of it lost while parked overnight), instead of 134 and 141.

The widget API's powerUsageOfDayKwh still passes the raw counter through, as before.

Tests

  • DailyEnergyCheckTests with the reporter's 40 rows verbatim, plus a sound car, regeneration, a charge during the day, a single-poll day and a car without a since-last-charge counter. A repository test checks the seed from before the period.
  • Frontend: todaysEnergyKwh, dailyCounterTotal, and the card registry with the reporter's values.
  • dotnet test: 1474 passed, 17 skipped (Postgres). Vitest: 1212 passed. vue-tsc, ESLint, oxlint and dotnet format clean.

No migrations.

🤖 Generated with Claude Code

@joszz joszz added the test-build Publish pr-<number> preview images for testers label Nov 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Preview build pr-556

The preview images are deleted. Anyone who ran them should change the image back to the latest release (or latest, which follows main and carries the fix once it is merged), or from a clone run docker compose up -d --build in the same folder.
Adding the test-build label again publishes a fresh build.

@joszz
joszz force-pushed the fix/bev-day-counter branch from 5d9db3f to 1e69b2b Compare November 4, 2026 20:42
@joszz joszz added test-build Publish pr-<number> preview images for testers and removed test-build Publish pr-<number> preview images for testers labels Nov 4, 2026
@joszz
joszz force-pushed the fix/bev-day-counter branch 2 times, most recently from 1e5a5e6 to 786e798 Compare November 5, 2026 19:37
@joszz joszz added test-build Publish pr-<number> preview images for testers and removed test-build Publish pr-<number> preview images for testers labels Nov 5, 2026
@joszz
joszz force-pushed the fix/bev-day-counter branch from 786e798 to 7cc65a6 Compare November 8, 2026 17:57
An MG ZS EV (issue #551) adds 33 to 35 kWh to drivetrain/powerUsageOfDay at
some polls while parked, so a 4 km day read 134 kWh and 47040 Wh/km. Its
powerUsageSinceLastCharge comes out of the same charge status message and
matches the state of charge drop to the hundredth, so it is the reference.

- DailyStatsBuilder compares the two counters per day: their rises within
  runs without a reset, and on a day without a charge the day total against
  what had left the battery since the last charge. DailyStat gains
  SinceChargeTotal (the day off the since-last-charge counter, starting from
  the last reading before the day) and CounterUnbacked.
- utils/energy picks the figure: a plug-in day the API flags falls back to
  the since-last-charge total; a hybrid stays on its day counter.
- The live kWh-today and Wh/km cards hide a day counter that holds more
  than left the battery since a charge that was not today.

Refs #551

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@joszz
joszz force-pushed the fix/bev-day-counter branch from 7cc65a6 to 057e1cd Compare November 9, 2026 13:14
@joszz joszz closed this Nov 9, 2026
@joszz
joszz deleted the fix/bev-day-counter branch November 9, 2026 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test-build Publish pr-<number> preview images for testers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant