Skip to content

Add EV charging energy and costs for day, week and month - #1547

Open
segran2 wants to merge 9 commits into
srcfl:masterfrom
segran2:feat/ev-charging-cost
Open

segran2 wants to merge 9 commits into
srcfl:masterfrom
segran2:feat/ev-charging-cost

Conversation

@segran2

@segran2 segran2 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1545.

Show EV charging energy and cost for today, this calendar week and this calendar month using FTW's configured total consumer price. Retain the reviewed heading and compact helper text below it. Days without charging do not mark the totals incomplete; missing data during recorded charging does.

Costs use 30-minute energy history, allocated across overlapping price slots by duration. This assumes uniform charging within each energy bucket; finer price-slot allocation remains approximate. Network tariff, energy tax configured within that tariff, and VAT follow the existing consumer-price model.

Version compatibility

  • The branch was previously based on v0.140.5-beta.1; its existing SoC and history-maintenance fixes were preserved.
  • On 12 October 2026, compared all four modified existing web/test files in the PR branch against the official v0.140.8-beta.1 release. Their upstream baseline Git blob IDs match the patch's preimage IDs, so the patch targets those release files without a rebase of the PR branch.
  • The reporter installed v0.140.8-beta.1 using the native release-slot updater. Web-only git apply --check was reported without errors after correcting file permissions. This is an applicability check, not an end-to-end UI confirmation.

Validation

  • Previous v0.140.5-beta.1 validation: 709 web tests passed; published branch tree matched the tested tree.
  • 12 October 2026: six standalone Node.js regression checks on the calculateEVChargeCost function extracted from the supplied patch passed: priced bucket, outside-period exclusion, zero-charge day, missing-price incompleteness, half-bucket prorating, and unreliable-quality flagging.
  • PR diff has the same five paths and 250 additions / 5 deletions as the supplied v0.140.8-beta.1 patch; no additional code change was required for the version-specific patch.
  • Not run here: full web test suite, Go test/build/vet, make verify, runtime API and browser UI tests on v0.140.8-beta.1. Do not treat this update as a full test pass.
  • Earlier full make verify attempt with Go 1.26 did not complete because dependency downloads were blocked.
  • UI was previously reviewed on a local v0.140.4-beta.1 installation. No new visual changes were made; visual verification on v0.140.8-beta.1 remains outstanding.

Merge status: GitHub reports the PR as mergeable at the latest check. The branch has not been rebased; no force-push was used.

Additional regression fix (12 October 2026)

  • Found a case where duplicated or overlapping price slots caused EV charging cost to be counted twice.
  • Fixed price-slot overlap accounting in commit ac0fe17e and added a regression test in e25c0e6c.
  • Eight standalone Node.js calculator tests passed after the fix, including the overlapping-slot case. These were run outside the full repository test harness; the full web/Go/CI suites remain unverified in this environment.
  • Important: The previously distributed v0.140.8-beta.1 patch predates this fix. The updated PR branch is the source of truth; regenerate the deployment patch before using it.

segran2 commented Oct 10, 2026

Copy link
Copy Markdown
Contributor Author

Clarification of “Costs are prorated across price slots from 30-minute energy history”:

The current implementation requests EV charging energy in 30-minute buckets. It then distributes each bucket’s energy across the overlapping price slots in proportion to the duration of the overlap, using FTW’s configured total consumer price.

For example, if a 30-minute bucket contains 3 kWh and spans two 15-minute price slots, the calculation assigns 1.5 kWh to each slot. This assumes uniform charging power within that bucket. If charging starts, stops or changes power within the half-hour, the calculated cost can differ from the cost obtained using finer-resolution energy readings. The full-bucket energy total is preserved; the approximation concerns its allocation between prices. Partial buckets at period boundaries are also prorated by duration.

The reason for choosing 30-minute history is the energy-history API’s limit of 2,000 buckets per request. A full 31-day month contains 2,976 quarter-hour buckets, whereas half-hour buckets fit within the limit, including the extra days needed when the current week starts in the previous month.

This limitation is stated in the PR so reviewers can assess the accuracy tradeoff. A more accurate follow-up would fetch 15-minute energy history in multiple bounded requests and combine the results before calculating costs. That would avoid spreading a half-hour energy total across different quarter-hour prices, while retaining any approximation already present in the underlying energy ledger.

Merge the release baseline and clarify the charging cost changeset.

Signed-off-by: segran2 <268038031+segran2@users.noreply.github.com>

segran2 commented Oct 11, 2026

Copy link
Copy Markdown
Contributor Author

Updated the existing feature branch for v0.140.5-beta.1 in commit f9f7fea. The release baseline is included without conflicts, and the complete patch applies cleanly to the untouched release tag. All 709 web tests pass. The full verification attempt was stopped while dependency downloads remained blocked; it is not reported as passing. The latest reviewed heading/helper text and day/week/month totals are retained.

segran2 commented Oct 11, 2026

Copy link
Copy Markdown
Contributor Author

Compatibility update: v0.140.8-beta.1

The EV charging costs patch has been prepared for FTW v0.140.8-beta.1. The release is installed on the FTW test system, and the web-only patch was checked against the release files using git apply --check (covering web/energy-history.js, web/index.html, and web/style.css).

This confirms patch applicability; it does not yet establish that the EV charging cost calculations or UI have passed end-to-end runtime verification on this release. The production service uses the native release-slot launcher, so the patch is applied to release web assets rather than to a Git checkout.

Note: the patch was initially created for v0.140.5-beta.1 and adapted for v0.140.8-beta.1.

segran2 commented Oct 11, 2026

Copy link
Copy Markdown
Contributor Author

Field verification on FTW v0.140.8-beta.1 (12 October 2026)

The reporter installed the updated EV charging cost implementation, including the coveredUntil fix for duplicate/overlapping price slots, in the native release directory on their FTW system.

Verified from the reporter's terminal output and Safari screenshots:

  • The running FTW UI identifies itself as v0.140.8-beta.1.
  • web/energy-history.js contains the new coveredUntil overlap-accounting logic (confirmed by grep at lines 144–156).
  • The History → EV charging — energy and cost panel renders correctly, with Today / This week / This month summaries and Swedish currency formatting.
  • Displayed values at the time of the screenshot: Today 0.0 kWh / 0.00 kr; This week 0.0 kWh / 0.00 kr; This month 31 kWh / 68.61 kr (about 2.21 kr/kWh).
  • Safari Web Inspector's Errors filter was empty on the History page; no visible JavaScript errors were reported.
  • Other energy-history summary and chart components remained visible.

Scope/limitations: This confirms successful deployment and UI rendering with real site data, not independent verification of the 68.61 kr calculation against raw charging/price records. A Node.js syntax check was not run on the FTW host because node is not installed there. The full web/Go test suites and make verify have not been run for this deployed version. No evidence of a fresh charging session after this fix is available. Please keep these distinctions in the review/merge decision.

segran2 commented Oct 11, 2026

Copy link
Copy Markdown
Contributor Author

Automated verification update — PASS

The contributor ran the complete make verify target on their Mac against segran2/ftw branch feat/ev-charging-cost, with HEAD e25c0e6 (following ac0fe17 and f9f7fea). They explicitly reported EXIT CODE: 0 from a fresh make verify run.

The previously shared output showed passing Python unit tests (including packaging, release ordering/schema and native optimizer), release asset / image promotion / GHCR / container boundary checks, and Energyplan 0.5.1 verification. The Docker-context check printed SKIP release Docker context: Docker daemon unavailable. The rollback-related error messages were part of exercised negative test scenarios and ended in paired latest alias rollback checks passed.

Conclusion: Local make verify completed successfully on this PR branch, subject to the explicitly skipped Docker-daemon-dependent check. This is contributor-reported execution; I did not independently run the suite or inspect the full final log. The separate on-device UI check on FTW v0.140.8-beta.1 was documented above.

segran2 commented Oct 11, 2026

Copy link
Copy Markdown
Contributor Author

Real-data EV charging cost verification — PASS (October 2026)

Verified on the contributor's FTW v0.140.8-beta.1 installation using read-only /api/energy/history and /api/prices responses in Safari, with an independently executed browser-console calculation following the PR's price-slot overlap rules.

Observed results (1 Oct 2026 through 12 Oct 2026 00:45 local time):

Check Result
EV charging energy 30.608 kWh (UI rounds to 31 kWh)
Recalculated charging cost 68.61 SEK
FTW History UI charging cost 68.61 SEK
Difference at displayed precision 0.00 SEK
Average price 2.241 SEK/kWh
Missing price coverage detected 0 gaps
History response truncated false
Price data enabled true
Price currency SEK

The energy history contained 548 vehicle_charge records (including zero-energy records), and the price response contained 1,156 slots. The independent console calculation weighted each positive-energy bucket by its overlap with price slots, avoided counting overlapping price coverage twice, and reproduced the UI total to the öre.

Interpretation and limits: This verifies reproducibility of the displayed total from FTW's actual history and configured price API data, including complete price coverage for the positive-energy buckets. It does not independently validate the configured tariffs/VAT against the electricity supplier's invoice or prove that charger energy measurements match an external meter. The console check follows the same calculation principle as the implementation, so it is a real-data cross-check rather than a fully independent pricing-model audit.

Combined with the contributor-reported make verify exit code 0 (Docker-daemon-dependent test explicitly skipped) and the successful on-device UI check, this provides a strong basis for PR review.

segran2 commented Oct 11, 2026

Copy link
Copy Markdown
Contributor Author

@Frahl Ready for your action at your convenience.

segran2 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor Author

Field update: EV Charging Costs on FTW v0.141.2-beta.1

The EV Charging Costs web patch has been adapted locally to the v0.141.2-beta.1 release files (web/energy-history.js, web/index.html, and web/style.css).

Verification:

  • make verify completed successfully (exit code 0).
  • The regenerated patch passed reverse application verification locally (PATCH CHECK: 0).
  • On the running v0.141.2-beta.1 FTW server, git apply --check returned 0, confirming applicability to the deployed release files.
  • After installation, EV Charging Costs is displayed and working in both Safari and the macOS ftw.app.

Scope note: This is field verification of a locally regenerated deployment patch; the PR branch itself has not been rebased to v0.141.2-beta.1 as part of this update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Calculate and report EV charging energy cost

1 participant