Repository navigation
fix(savings): compare the bill only where Home use is known - #2144
Conversation
/api/savings/daily priced the baseline only where Home use was known, but subtracted the whole bill. Time with unknown Home use, such as a charger whose power went unknown, counted as pure cost, and a day with 0 % coverage read as minus its whole bill. The bill (import_cost_ore, export_revenue_ore, actual_cost_ore) still counts all measured import and export. The new compared_actual_cost_ore is the bill for the intervals that also have a baseline, and saved_ore is baseline_cost_ore minus it. Coverage counts the same intervals. - Source intervals: a price slot adds its bill to the compared cost only when it adds its baseline. - Partial point log: the bill now keeps import while Home use was unknown; the saving still leaves it out. - Energy ledger: a bucket without an observed-consumer record is LoadUnknown and adds to the bill only. The blind self-consumption battery holds its charge across it. - Legacy point log: unchanged; its rows always carry Home use. Totals sum the days and today's forecast builds on the row's saved_ore, so both follow the rule. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5c63d280c6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| "actual_cost_ore": ds.ActualCostOre, | ||
| "baseline_house_ore": ds.BaselineHouseOre, | ||
| "baseline_ev_ore": ds.BaselineEvOre, | ||
| "baseline_cost_ore": ds.BaselineCostOre, | ||
| // The bill over the intervals baseline_cost_ore prices; see above. | ||
| "compared_actual_cost_ore": ds.ComparedCostOre, |
There was a problem hiding this comment.
Update the on-box card to use the compared cost
When Home use is missing for part of a day, saved_ore now compares the baseline with compared_actual_cost_ore, but the existing on-box consumer still presents the whole bill as the comparison cost. In web/components/ftw-savings-card.js, _paint() and _showSparkTip() read actual_cost_ore beside the baseline, so the displayed figures no longer explain the displayed saving. Moreover, web/components/savings-periods.js determines completeness from price availability, so a day with prices but no known Home use can now appear as a complete zero-saving result. Update these consumers alongside the API change to distinguish the bill from the compared cost and mark missing measurement coverage.
Useful? React with 👍 / 👎.
Fixes #2143.
Problem
/api/savings/dailypriced the baseline only where Home use was known, but subtracted the whole bill. Time with unknown Home use, such as a charger whose power went unknown, counted as pure cost. A day with 0 % coverage read as minus its whole bill: 29 Nov on the home box said −149.1 kr.Change
The saving now compares like with like. Each row keeps the bill and adds the part of it that has a baseline:
import_cost_ore,export_revenue_oreandactual_cost_oreare the bill, as before: all measured import and export.compared_actual_cost_oreis new: the bill for the intervals that also have a baseline.saved_ore = baseline_cost_ore − compared_actual_cost_ore.self_consumption_saved_oreuses the same compared cost.history_covered_msandpriced_covered_mscount the same intervals, so a day without Home use reads 0 % and partial.On a fully measured day
compared_actual_cost_oreequalsactual_cost_oreand nothing else moves. Totals sum the days, and today's forecast builds on the row'ssaved_ore, so both follow the rule.Per path:
writeLedgerSavings): a bucket without an observed-consumer record had no baseline but kept its import in the compared cost.LedgerFlowBucketsnow marks itLoadUnknown; it adds to the bill only, and the blind self-consumption battery holds its charge across it. A known 0 W still leaves a record, so it stays known.The handler comment documents the fields. No registry name changes, and
docs/protocol.mddoes not describe this endpoint.The two days on the home box
Under the new rule, estimated from the box's own 15-minute energy history and prices. A quarter counts as known when it has a Home use record. This matches the box's baseline to the öre; the compared cost is scaled by the box's bill over the ledger's bill, so treat it as ±2 kr.
actual_cost_orecompared_actual_cost_orebaseline_cost_oresaved_orebeforesaved_orenowThe week 24–30 Nov goes from −143.8 kr to about +193 kr. That is below the +270 kr from rebuilding Home use for the whole week: the rule leaves the unknown hours out rather than guess, and 25, 27, 28, 29 and 30 Nov read as partial.
Clients
None computes the saving from actual − baseline. The demo boxes in the web app and both phone apps build their own
saved_ore = baseline − actualat full coverage, which stays true for them.The web app (
savings-glance.ts), iPhone (Savings.swift) and Android (Savings.kt) show the box'ssaved_orewith the line "Costactual_cost_ore· with no solar or batterybaseline_cost_ore", and mark a day partial below 95 %priced_coverage_pctwith "The box had prices for N % of the time". On a partial day those two money figures no longer explain the saving, and the note blames prices when Home use was the gap. A follow-up in each client could showcompared_actual_cost_orebeside the baseline on a partial day and word the note as measured and priced. The on-box card inweb/components/ftw-savings-card.jshas the same line and marks a day partial only when it lacks prices; that follow-up belongs in this repo.Tests
internal/state: source intervals with an unknown stretch while import continues, a day with no Home use, and a fully measured day; the partial point log; ledger buckets with known, unknown and known-zero Home use; the legacy path's compared cost equals its bill.internal/savings: the same three cases for the ledger evaluation, including the self-consumption saving and coverage.internal/api: both endpoint paths, with the two problem days and the totals.Limit
The ledger knows Home use per five-minute bucket. After 30 days it keeps hourly totals, and an hour with any Home use record counts as known. On a box that writes source intervals, only windows that end before they started read the ledger.
🤖 Generated with Claude Code