Skip to content

fix(phev): electric range from the BMS estimate, charger power and time units - #574

Open
joszz wants to merge 4 commits into
mainfrom
fix/phev-range-and-charge-units
Open

joszz wants to merge 4 commits into
mainfrom
fix/phev-range-and-charge-units

Conversation

@joszz

@joszz joszz commented Nov 8, 2026 •

Copy link
Copy Markdown
Owner

Refs #570 (not Fixes until the reporter confirms on the car). Also carries the commit from #572 (Refs #571), see below.

Combined preview build

The reporter of #570 also reported #571, on the same plug-in hybrid, so this branch carries #572's commit as well. Its pr-<number> image holds the fixes for both issues, and the reporter only needs to switch once.

#572 is closed in favour of this PR. #575 builds on this one and adds the fix for #573. When the reporter confirms, merging #575 alone brings in all three fixes, and this PR then closes too. Until then pr-574 stays up so the reporter can switch between the two builds.

1. Electric Range card never shows (#570)

The card needs electricRangeKm, which only came from drivetrain/range. The gateway publishes that topic only when the car's fuelRangeElec holds 1 or more (extract_electric_range), so a car that leaves it at 0 never sends it. Nothing hid the card because of the drivetrain: a PHEV passes mayPlugIn.

The gateway also publishes drivetrain/hybrid_electrical_range, the BMS's own estimate (bmsEstdElecRng, in km, 0 included). #393 skipped it as a repeat of the other topic. It now maps to the same ElectricRangeKm column. The gateway sends it with the charge status, before drivetrain/range in the same poll, so both merge into one telemetry row and drivetrain/range still wins on a car that sends both. That avoids a migration in a preview build.

Edge case: when the Worker restarts, the broker replays retained messages in its own order. If the BMS estimate comes in after drivetrain/range, it shows until the next poll.

2. Edit mode explains the missing card (#570)

While editing the layout, a card that is shown but has no data now says "Hidden until your car reports this" under its name. Before, it was a plain placeholder that vanished on Done without a word.

3. Charging session units (#570 screenshot)

The card showed "2507.1 kW · 900 min" on a car charging at about 4 kW with 15 minutes to go.

  • obc/powerSinglePhase and obc/powerThreePhase are in W, and drivetrain/remainingChargingTime is in seconds. The gateway's Home Assistant discovery says so, and it has been that way since at least gateway 0.9.0. Everything read them as kW and minutes, WIDGET.md included. The Worker now stores kW and minutes, which fixes the cards, the level details and the Homepage widget at once. Rows stored before the fix keep the old units, but these fields only feed the live status, which the next charge poll overwrites.
  • The card always preferred the three-phase figure. Both are worked out from the same charger voltage and current, so one of them is wrong: on a single-phase charger the three-phase figure reads about 58% of the truth. The new chargerPowerKw picks the one closest to the HV battery's own charging power (hvPower). Without that it keeps the three-phase figure, as before.

Tests

  • Mapper: hybrid_electrical_range (incl. 0), new units for power and remaining time. Handler: BMS estimate then range in one poll keeps the range, estimate alone is kept.
  • chargerPowerKw cases (the [Bug]: Adding Electric Range Card to dashboard does not work #570 numbers, three-phase, no battery power, one figure only). The card's summary uses the matching figure. The dashboard edit hint appears only on cards that are shown but have no data.
  • Vitest 1293 passed. vue-tsc, oxlint, ESLint, stylelint and Prettier are clean.
  • dotnet test: 1554 passed. dotnet format --verify-no-changes is clean.

No migrations.

🤖 Generated with Claude Code

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

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Preview build pr-574

Images for this pull request are published, built from 56cfa16 (version 0.15.1-preview.0.12.pr.574, shown in the footer).
Every push here replaces them. Closing the pull request or removing the test-build label deletes them.

Important

Update to the latest release (0.15.0) first if you run an older version, as a normal update. The preview is built on top of it, the database warning on this comment compares with it, and going back means going back to it.
Switch where you always run GarageStack: the same folder, Portainer stack or Unraid container. Compose names the database volume after the folder or stack, so starting from anywhere else runs on a new, empty database.
Don't use docker compose down -v or docker volume prune while testing. A backup first never hurts.

All-in-one or Unraid: change the image to

ghcr.io/joszz/garagestack:pr-574

Docker Compose with the published images (your own compose file with garagestack-api, garagestack-worker and garagestack-frontend): change the tag of those three images to pr-574, then

docker compose pull
docker compose up -d

Docker Compose from a clone of this repository, in the clone's folder on main:

git pull
PREVIEW_TAG=pr-574 docker compose -f docker-compose.yml -f docker-compose.preview.yml up -d

With the bundled database, put --profile bundled-postgres after docker compose, as you do for a normal start.

To pin this exact build rather than follow the pull request, use pr-574-56cfa16 as the tag.

Going back: change the image back to the latest release, 0.15.0. latest works too, but it follows main, so it can hold changes that are not released yet, database ones included. From a clone, run docker compose up -d --build in the same folder.

Step by step: Testing a preview build.

joszz and others added 4 commits November 9, 2026 14:13
…s capacity is set

MG's API scales the state of charge by a nominal 72.5 kWh pack, and the
gateway only replaces that for the BEV series it has a table entry for.
A PHEV with a pack of about 23 kWh showed 68.9 of 72.5 kWh at 95%.
Only a BEV now falls back to the gateway's capacity; every other car
needs HV_BATTERY_CAPACITY_KWH for kWh figures.

Refs #571

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ds no range

On some plug-in hybrids the Electric Range card never showed (#570). It
needs electricRangeKm, which only came from drivetrain/range, and the
gateway publishes that topic only when the car's fuelRangeElec holds 1 or
more. A car that leaves it at 0 never sends it.

The gateway also publishes drivetrain/hybrid_electrical_range, the BMS's
own estimate (bmsEstdElecRng, in km). It was skipped as a repeat of the
other topic. It now maps to the same column. The gateway sends it with the
charge status, before drivetrain/range in the same poll, so both merge into
one row and drivetrain/range still wins on a car that sends both. No
migration, so it can go out as a preview build.

While editing the layout, a card that is shown but has no data now says
"Hidden until your car reports this", so it no longer vanishes on Done
without a word. The card description no longer claims a range of zero is
never reported, since the BMS estimate does send 0.

The handler tests share one in-memory setup for the end-to-end MQTT cases.

Refs #570

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Charging session card showed "2507.1 kW · 900 min" on a plug-in hybrid
charging at about 4 kW with 15 minutes to go (#570). The gateway publishes
obc/powerSinglePhase and obc/powerThreePhase in W and
drivetrain/remainingChargingTime in seconds (its Home Assistant discovery
says so, unchanged since at least 0.9.0). Everything read them as kW and
minutes, the Homepage widget docs included. The Worker now stores kW and
minutes, which fixes the cards, the level details and the widget at once.

The card also always preferred the three-phase figure. Both are worked out
from the same charger voltage and current, so one of them is wrong: on a
single-phase charger the three-phase figure reads about 58% of the truth.
chargerPowerKw picks the one closest to the HV battery's own charging
power, and keeps the three-phase figure without it, as before.

Refs #570

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Spanish locale landed on main (#568) without dashboard.cardWithoutData, which broke the
type-check and the pr-574 image build. Also follows the reworded electric range description.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@joszz
joszz force-pushed the fix/phev-range-and-charge-units branch from 920c0da to 56cfa16 Compare November 9, 2026 13:13
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