Repository navigation
feat(heatplan): propose a zone's heat from prices and the site's plan - #2022
Conversation
A dynamic program over a zone's predicted temperature. It costs heat as electricity divided by the source's efficiency, so direct electric heat, air-to-air, air-to-water, a hot-water tank, a spa and a pool are the same problem with different inertia, band and COP. The site's energy plan comes first. Heat is costed at the import price, takes only what the plan still exports and only the headroom it leaves under the import limit, and leaves its band before it proposes a value that draws through that limit. Battery energy costs what the site buys back in the cheapest later slot the battery was to cover, never what the battery was charged at. Two owner rules sit beside the plan, both off until the owner sets them: PriceComfort moves a zone's target with the day's mean price, linearly between the owner's cheap, normal and dear levels, inside the zone's hard band; SavingsGate leaves every zone on its target unless the plans together save the owner's least amount in a day. A `thermal` config section carries the owner's numbers as plain values with their own checks, and cmd/ftw turns them into the planner's rules, so no control package depends on heatplan. Nothing calls the package yet: the service and dispatch are separate changes. ADR 0012 gains the proposal under "What the owner sets". Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Signed-off-by: hannesb90 <[email protected]>
…gate - Site offers battery power by the electricity the device draws at full output, not by its heat: a 6 kW pump at COP 3 is offered about 2 kW. - After takes the battery energy a zone used off what the next zone is offered, and moves it on the meter to the slot that gave it up. - A comfort shift rounded to the control's step never passes the owner's raise or lower limit. - The savings gate and the thermal config section are taken out. The planner runs in shadow first and shows what it would save; config comes with the change that acts on it (ADR 0012, decision 9). - Tests: run time across the plan start in both directions, a 25-hour day, the step limit, the pump's draw and two zones sharing a battery. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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: 7ffe9319d7
ℹ️ 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".
| from.GridKW += taken | ||
| from.BatteryDischargeKW = math.Max(0, from.BatteryDischargeKW-taken/batteryShare) |
There was a problem hiding this comment.
Reserve import headroom for battery buyback in donor slots
When a later slot supplies battery energy to an earlier one, its replacement import is not included in that slot's MaxElecKW constraint. After subsequently adds this import without checking the site's limit, so a proposal reporting OverLimitKWh == 0 can exceed the limit in the resulting site plan. In a two-slot reproduction with a 5 kW limit, the donor initially imports 4.9 kW, supplies 0.5 kW of battery cover, and ends up importing 5.46125 kW after the zone is added, despite the proposal reporting no excess. Battery offers must reserve headroom in the donor slot and account for the zone's own consumption there.
Useful? React with 👍 / 👎.
| heatPrice += math.Max(0, r.Price[k]) / s.cop(k, z.TargetC[k], 0) | ||
| } | ||
| heatPrice /= float64(s.n) | ||
| holdPerKh := s.holdCost(heatPrice) | ||
| s.comfortPerKh = z.ComfortWeight * holdPerKh | ||
| s.bandPerKh = bandWeightFactor * (heatPrice*z.CapacityKWhPerK + holdPerKh + 1e-9) |
There was a problem hiding this comment.
Keep constraint penalties effective at negative prices
When every forecast price is non-positive, heatPrice and holdPerKh become zero, leaving bandPerKh at only the epsilon floor and making the derived import-limit penalty negligible compared with negative energy costs. The solver then deliberately exceeds an avoidable import limit to earn more from consumption. Using the existing radiator fixture with prices of -100 and a constant 5 kW limit produces 6.435 kWh of excess consumption, although holding its 21 °C target requires only 4.2 kW. Scale the constraint penalties using price magnitudes or enforce the constraints independently of the economic objective.
Useful? React with 👍 / 👎.
| run := max(1, a.RunSlots) | ||
| if a.On { | ||
| return off + min(run, on) - 1 | ||
| } | ||
| return min(run, off) - 1 |
There was a problem hiding this comment.
Preserve the full minimum duration for unknown run times
For RunSlots == 0, this initialization credits the device with one completed slot, although the documented contract treats an unknown run time as a switch just made. Consequently, an off device with MinOffSlots == 6 can start in slot 5 rather than waiting six complete slots; this reproduces with the pool fixture at negative prices. The same initialization shortens an unknown on duration, and a minimum of one slot permits an immediate switch. Represent zero elapsed slots explicitly so unknown run times retain the full minimum protection period.
Useful? React with 👍 / 👎.
- maxDrawKW takes the highest setpoint or offset a control can regulate to, so no slot draws more than its battery offer and headroom allow. - A shift too small for one step is 0, not −0. - Tests: exact meter and offer accounting in After, and a check that no slot in three houses draws more than its bound. - ADR 0012: the PR that merged the planner, the config shape as future, and battery energy among what zones share in turn. Co-Authored-By: Claude Opus 5.5 <[email protected]>
frahlg
left a comment
There was a problem hiding this comment.
Reviewed in two passes on Sonnet. The first pass was on #2013 at 6730139 and found three defects:
- the battery offer was capped by heat, not electricity;
Afteroffered the same battery energy to the next zone;- the comfort step could round past the owner's limit.
The second pass was on the fix at 7ffe931. It found no defect against the stated goals. It noted a slot that leaves its band could draw past the bound, two tests that were too loose, a −0 and three ADR lines. All of these are fixed in 72e9020:
- The bound now takes the warmest value a control holds. A new test checks every slot of three houses against it.
- The
Aftertest checks the meter and the offer exactly. It fails on a flipped sign, on a doubled move and on a giver cut without the share.
make verify is clean on 72e9020, and go test -race ./internal/heatplan passed.
This carries on hannesb90's heat planner from #2013, on Fredrik's word, instead of handing it back. There are two commits. The first is Hannes's planner, unchanged. The second holds the fixes from the review and Fredrik's decision on the owner's rules. The drivercontrol commit from #2013 is on its own in #2021.
What
A
heatplanpackage. For one zone, it proposes the control value to hold in each slot from prices, weather and the site's energy plan. Nothing calls it yet, so there is no behaviour change. It is part of ADR 0012, section 4. The PR text of #2013 describes how it plans.Changed against #2013
Request.Siteused to cap each slot's battery offer with the device's heat output. A 6 kW heat pump at COP 3 draws about 2 kW, yet was offered 6 kW, and its import headroom grew by the same amount. The cap is now the electricity drawn at full output at the worst COP the plan could run at. Without a forecast it falls back to the heat output, which nothing draws more than.Afteradded a zone's draw to the meter but left the battery as it was, so the next zone was offered the same energy again.Afternow takes the request the zone was planned from. It takes the battery energy the zone used off what the next zone is offered. It also moves that energy on the meter to the cheaper slot that gave it up. All zones together are never offered more than one zone would be.SavingsGate, thethermalconfig section, its lines inconfig.example.yamlandcmd/ftw/thermal_comfort.goare all taken out. In the house that ran the gate, it never opened. The planner will run in shadow first and show what it would save, and config comes with the change that acts on it. ADR 0012 records this as decision 9.Plan.Saving()stays, for the shadow run.Actuator.RunSlots0 is now described as an unknown run time. It is read as a switch just made, which is safe.Evidence
Synthetic houses, not hardware.
make verifyon this branch: clean.go test -race ./internal/heatplan ./internal/config: clean.startStateignoresRunSlotsin either direction.Not included
Zone config, the shadow service, dispatch, a driver-declared COP curve, and zones on a shared source planned together.
🤖 Generated with Claude Code