Repository navigation
Estimate a Tesla's battery capacity from its rated range - #172
Conversation
A Tesla tells its usable level (usable_battery_level) beside its SoC, and its range (battery_range) is the rated one, a fixed conversion of that level. A charge now keeps the range read with its start and end SoC, and the usable level read with its end (migration 0027), which a capacity estimate from the rated range rests on. FieldSoC covers the usable level, told in the same block: Field stays on 16 bits. The simulator's rated range follows its usable level, a point below the SoC, as the real car's does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
As TeslaMate reads it: the rated efficiency is the median, over the observed charges of 10 minutes or more ending at 95 % at most, of the energy the car measured over the rated range it added; each charge ending with 50 % usable or more gives a rated estimate, its rated range brought back to 100 % of the usable level, times that efficiency. Once there are 5 rated estimates, the current capacity, its change and the monthly medians rest on them alone (the API's basis): the car's own count is far more precise than a SoC change over whole kW. The power and billed estimates stay in the series. The battery page draws the rated points, gives the rated efficiency, the two new reasons a charge gives none, and says a Tesla's range at 100 % follows the battery, not the season. A fifth chart color tells the points the median does not rest on. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Capture and persist rated-range data internal/tesla/*, internal/core/charge.go, internal/core/snapshot.go, internal/core/event.go, internal/store/*, internal/simulator/teslaapi/*, internal/tesla/simulator_test.go, documentation/self-hosting/updating.md |
Tesla usable-charge readings and charge range values flow through snapshots and derived charges into new nullable database columns. Simulator data and tests cover the updated readings. The migration note states that rebuilding is required for past charges to receive these values. |
Calculate rated estimates and select the trend basis internal/core/capacity.go, internal/core/capacity_test.go, AGENTS.md |
Rated efficiency uses qualifying measured-energy and range data. Eligible charges produce rated estimates. When the rated estimate count meets the configured threshold, rated estimates alone determine current capacity, change, and monthly capacity; all estimates remain available. |
Expose and display rated estimates internal/api/battery.go, internal/api/battery_test.go, internal/api/openapi_test.go, web/src/widgets/battery-charts/ui/BatteryCharts.vue, web/src/widgets/battery-tiles/ui/BatteryTiles.vue, web/src/shared/i18n/locales/*, web/src/shared/theme/*, web/test/*, web/e2e/battery.spec.ts, documentation/guide/*, AGENTS.md |
The battery response adds the estimate basis, rated efficiency, and rated-exclusion counts. The interface plots rated estimates, distinguishes their chart color and basis, and displays rated-related notes and exclusion reasons. Guides and translations describe the calculations and chart distinctions. |
Possibly related issues
- runsten-app/runsten#134 — The rated-efficiency and capacity calculations use the measured Tesla charge energy that this issue adds to the data flow.
Possibly related PRs
- runsten-app/runsten#170 — Stores Tesla-reported charge energy, which this change uses to calculate rated efficiency.
- runsten-app/runsten#148 — Adds the Tesla simulator data path that this change extends and tests for rated capacity.
- runsten-app/runsten#137 — Adds Tesla normalization that this change extends to retain usable battery level.
Priority:
Merge Risk: 
Minimal · up to 75c6a
-
No confirmed issue prevents merging after normal checks.
Security architecture risk: 
Low · up to 75c6a
-
The new estimates retain existing account and vehicle access checks, and the added storage fields support missing historical readings. No introduced security-boundary failure was established. Deployment, downgrade, and concurrent recovery behavior were not fully assessed.
Retained concerns
No architecture-level concerns identified.Security review details
-
Security Blast Radius
- inferred — The inspected new response data remains scoped to the resolved vehicle within the authenticated account. No broader data-read authority was established through the new fields. This does not establish a service-wide resource-exhaustion bound.
Trust Boundaries and Controls
- observed — The battery route uses the existing authenticated operation wrapper. Before reading history, accountVehicle validates the vehicle identifier and resolves it using the session account; PeriodEvents receives that same account and resolved vehicle. Another account's vehicle is treated as not found.
Resilience and Maintainability Implications
- observed — The new persisted readings use the existing account-scoped transaction mechanism, which sets the account context before executing writes. The PR's added insert parameters do not replace that containment mechanism or separate charge updates from cursor recovery state.
-
Pre-merge checks: 
3 · 
1
-
Failed checks: 1 warning Passed checks: 3 passed-
Full details: Description check
-
Explanation
The description explains the purpose, implementation, API and UI changes, migration impact, tests, and issue reference. It does not reproduce every template checkbox or use the exact "How it was tested" heading, but it provides the required information in substance.
Full details: Out of Scope Changes check
-
Explanation
The reviewed changes stay within issue
#167. Data-model, persistence, migration, normalization, simulator, API, UI, localization, tests, guides, and update notes support the Tesla capacity estimate or its required presentation and rollout. No unrelated change is demonstrated.
-
Full details: Linked Issues check
-
Explanation
Issue
#167is directly linked and open. The implementation covers the Tesla readings, rated-efficiency calculation, per-charge estimate, rated basis, API, Battery page, simulator test, and guides. The changes also include automated tests for the core, API, chart, tile, and simulator behavior. The reviewed changes do not update ADR 0023 or add a new ADR that documents the Tesla method and its combination with existing estimates. The PR objective text also identifies this missing update.Resolution
Update ADR 0023 or add a new ADR. Document the Tesla rated-range method and how rated estimates combine with the existing estimates.
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment @coderabbitai help to get the list of available commands.
|
On the linked-issue warning: the ADRs are kept outside this repository; ADR 0023 has been updated there with the Tesla rated-range method and how its estimates combine with the others. The user-facing method is documented in documentation/guide/battery.md ("A Tesla"). |
Closes #167
A Tesla's battery capacity, estimated the way TeslaMate's Battery Health reads it, from the rated range and the energy the car measures during a charge.
What changes
usable_battery_levelis read (core.Snapshot.UsableSoC, covered byFieldSoC). A charge keeps the rated range read with its start and end SoC, and the usable level read with its end (migration0027).energy_measured_kwh / (end_range − start_range)on observed charges of 10 min or more ending at 95 % at most; the median over the whole history.ratedestimate, one per charge:end_range / end_usable × 100 × efficiency, when the usable level ends at 50 % or more. Same plausibility bounds as the other sources; two new reasons a charge gives none (no_efficiency,low_soc).basis: "rated"); the power and billed estimates stay in the series.GET /vehicles/{vehicle}/battery:basis,rated_efficiency, sourcerated,excluded.no_efficiencyandexcluded.low_soc; spec and golden files regenerated (battery-rated.json).chart-5, for the points it does not rest on), the rated efficiency in kWh/100 km under the capacity, the new reasons for a Tesla only, and the range at 100 % said to follow the battery for a Tesla.model3scenario's 75 kWh.AGENTS.md.Update
Migration
0027; the past charges give a rated estimate only after a rebuild (update notes).Tests
task unit(Go lint, tests, govulncheck, build; front lint, Vitest, audit, build) and the store tests against PostgreSQL. Checked on the simulator only: no real charge recorded yet.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Documentation