fix(hev): read the energy counters as fuel, not kilowatt-hours - #366
Merged
Merged
Conversation
The gateway publishes drivetrain/powerUsageOfDay on the same topic for every drivetrain, but a plain hybrid has no traction battery worth metering: the trip computer puts its fuel total there instead, in hundredths of a litre. Read as kWh that turned a 59 km day into "394 kWh today" and "6678 Wh/km". The scale is measured, not guessed. Regressing the counter against the fuel gauge within each tank over 90 days of an HS Hybrid+ (20 tanks, r2 0.94 to 0.997) implies a 54.7 L tank against the 55 L the car actually has. The same car's soc_kwh and totalBatteryCapacity are the BMS percentage scaled by an EV-sized 72.5 kWh default, roughly forty times the real 1.83 kWh pack. The percentage behind them is genuine, so the HV card now takes charge and capacity separately and shows kWh only once the real capacity is known. Every reading of those counters goes through utils/energy, so the unit is decided in one place rather than per card. BEV and PHEV behaviour is unchanged, since their counters really do hold kWh. Capacity is deployment configuration (HV_BATTERY_CAPACITY_KWH), served on the vehicle list DTO beside the detected drivetrain. Left unset, a plug-in car keeps the gateway's figure and a hybrid shows percentages only, rather than a confident wrong number of kWh. The widget API keeps exposing the raw counter as powerUsageOfDayKwh; renaming it would break existing Homepage configs, so the caveat is documented instead. Co-Authored-By: Claude Opus 5 <noreply@anthropic.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.
What was wrong
On a plain hybrid the dashboard reported 394.0 kWh used today over 59 km, and an efficiency of 6678 Wh/km. Both are physically impossible: 394 kWh is four times a large EV pack.
The gateway publishes
drivetrain/powerUsageOfDayon the same topic for every drivetrain, but a plain hybrid has no traction battery worth metering. The trip computer puts its fuel total there instead, in hundredths of a litre. The real reading was 3.94 L over 59 km, or 6.7 L/100 km.The same car's
soc_kwhandtotalBatteryCapacityare the BMS percentage scaled by an EV-sized 72.5 kWh default, roughly forty times the real 1.83 kWh pack. The percentage behind them is genuine; only the kWh are invented.Verifying the scale
The hundredths-of-a-litre scale is measured, not assumed. Regressing the counter against the fuel gauge within each tank over 90 days of production data from an MG HS Hybrid+ gives 20 tanks with r2 between 0.94 and 0.997, implying a 54.7 L tank against the 55 L the car actually has.
Supporting evidence: the counter over distance lands between 5.5 and 8.0 on normal days and 8.9 to 12.3 on short-distance days, exactly how a hybrid behaves on cold short trips. Independently, integrating
HvPoweracross SoC changes puts the pack at 1 to 2 kWh, and the largest observed SoC swing (27.9 points in 38 s) needs 2607 kW at 72.5 kWh but a plausible 65 kW at 1.83 kWh.What changes
394.0 kWh3.9 L6678 Wh/km6.7 L/100km56.8 kWh/72.5 kWh1.4 kWh/1.8 kWhThe
78%summary is unchanged, because it was already correct.BEV and PHEV behaviour is untouched, since their counters really do hold kWh.
How
frontend/src/utils/energy.ts.energyUnit()decides litres vs kWh from the drivetrain;hvBatteryReading()resolves charge, stored energy and capacity together.dailyEnergyKwhbecomesdailyCounterTotal: the reset detection was always unit-agnostic, only its name claimed otherwise.HV_BATTERY_CAPACITY_KWH/HvBattery__CapacityKwh), served on the vehicle list DTO beside the detected drivetrain. Left unset, a plug-in car keeps the gateway's figure and a hybrid shows percentages only, rather than a confident wrong number. Wired into compose,.env.example, the all-in-one entrypoint and the Unraid template.Deliberately left alone
The widget API still exposes the raw counter as
powerUsageOfDayKwh. Renaming it would break existing Homepage widget configs, so the hybrid caveat is documented in the README table instead.Testing
vue-tscall clean.🤖 Generated with Claude Code