Skip to content

feat(heatplan): propose a zone's heat from prices and the site's plan - #2013

Closed
hannesb90 wants to merge 2 commits into
srcfl:masterfrom
hannesb90:feat/heat-planner
Closed

hannesb90 wants to merge 2 commits into
srcfl:masterfrom
hannesb90:feat/heat-planner

Conversation

@hannesb90

@hannesb90 hannesb90 commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

What

A heatplan package: 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. Zone config, the service and dispatch are separate changes.

Part of ADR 0012 section 4.

Stacked

This branch contains #1996 and #1997, which it needs (the twin and the control holds), rebased onto their current heads. It is a draft until those two merge. Review the last three commits:

  • refactor(drivercontrol): keep the hold test seams out of the API takes the three low notes from the review of refactor(drivercontrol): move operator holds out of the API #1997. The test seams (the hook parameters on Send and SendDefault, State.Lock/Unlock, ArmLocked, Expire, Peek, Len, State) are now behind Holds.Seams(), which panics outside a test binary; an export_test.go would not do, because the API package's hold-race tests need them too. TryActive reads a hold without waiting, for the control tick. Nothing calls it yet.
  • feat(heatplan): propose a zone's heat from prices and the site's plan, unchanged.
  • feat(heatplan): comfort follows the day's price, and a least daily saving, new. See below.

Nothing here reads a twin's status yet, so the new unproven state in #1996 changes nothing in this PR.

How it plans

  • A dynamic program over the zone's predicted temperature. Heat is costed as electricity divided by the source's efficiency (COP 1 for direct electric, a modelled or declared COP for heat pumps), so a floor cable, radiators, air-to-air, air-to-water, a hot-water tank, a spa and a pool are one problem with different inertia, band and efficiency.
  • On/off devices keep their minimum on and off times.
  • The site's plan comes first. Heat is costed at the import price, takes only the surplus the plan still exports and the headroom it leaves under the import limit, and may leave its comfort band before it proposes a value that draws through that limit.
  • Battery energy is not costed as cheap. Heat takes at most half of what the battery was to spend in a cheaper, later slot, at that slot's price.

What the owner sets

Two rules beside the plan, both off until the owner sets them. Nothing has a default: the numbers depend on the contract, the price area and the household.

  • Comfort follows the day's price (PriceComfort). The zone's target moves with the day's mean price, linearly between the owner's cheap, normal and dear levels. Each direction is per zone: a bathroom floor may follow cheap days up while room air only follows dear days down. The moved target stays inside the hard band. It needs no model of the house.
  • A least daily saving (SavingsGate). Planned heat is acted on only when the plans of all zones together save the owner's amount in a day; below it every zone is left on its target. An open gate closes at 80 % of the limit. A plan that leaves its band counts as saving nothing.
  • The comfort rule moves the target first, and the plan and its baseline both stand on it, so the plan is not credited with what the comfort rule saved.

A thermal section in the configuration carries the numbers (cheap_day_ore_kwh, normal_day_ore_kwh, dear_day_ore_kwh, min_saving_ore_per_day, and per zone cheap_day_raise_k, dear_day_lower_k, step_k). It is parsed and validated, and nothing acts on it yet. ADR 0012 gains the proposal in section 1 and under Open; it has not been answered.

Where it comes from: one household runs both rules in a local script on three floor-heating zones. With a 5 kr limit the planned savings of 0.1–4.9 kr a day never opened the gate, so in practice only the day's comfort level acted.

Evidence

Synthetic houses and prices, not hardware. On a volatile two-day price series the plan saves 14–65 % against leaving the device alone, and about 0–27 % on a calm series, without leaving any zone's band. It is within 0.02 % of a finer-grid and a local-search check, except a spa at 1.25 %. In a battery simulation with a re-planning EMS, costing battery energy as cheap cost up to 23 SEK a day more than the import price and emptied the battery before the peak ended. The rule here was never worse than the import price.

Not included

Zone config, the service, dispatch, a driver-declared heat source and COP curve, twins for tanks, pools and electric floors, zones on a shared source planned together, dead time, cooling and discrete modes.

The open questions this raises are in the ADR 0012 addendum on #1994.

🤖 Generated with Claude Code

hannesb90 and others added 2 commits November 15, 2026 15:14
The low notes from the review of srcfl#1997, for the step that adds a
planned-value caller:

- The test seams were part of the production API: two hook parameters on
  Send and SendDefault, and exported State.Lock, State.Unlock, ArmLocked,
  Expire, Peek, Len and State.CurrentHold. A planned-value caller could
  have held the per-driver lock through them. They are now behind
  Holds.Seams, which panics outside a test binary. An export_test.go
  would not do: the API package's hold-race tests need them too.
- Holds.State, which created an entry for any name, is reachable only
  through Seams.
- Active takes the per-driver lock and so waits for a command in flight.
  TryActive is the same read for the control tick: it never waits, and
  says so when a command or a default holds the lock.

The hold-race tests are unchanged apart from the call target.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: hannesb90 <[email protected]>
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]>
@frahlg

frahlg commented Nov 15, 2026

Copy link
Copy Markdown
Member

@hannesb90 thanks, this is good work. Fredrik asked me to carry it on rather than send it back to you, so it has merged in two parts, with your commits and authorship kept:

Fredrik's direction (15 November 2026), now decision 9 in ADR 0012

  • The planner: yes, as section 4 says. The next step is to run it in shadow, as the twin runs. It proposes and records, sends nothing, and the box shows what it would have saved.
  • Comfort follows the day's price: taken. It is the owner's own target moved by the owner's rule, so it needs no trusted twin. Decision 2 still applies to what it sends.
  • The least daily saving: not taken. In the house that ran it, it never opened, so it only turned the planner off. The shadow run's saving, shown to the owner before planned control is turned on, does that job.
  • Config: the thermal section comes with the change that acts on it.

Fixes in #2022

  • The battery offer is capped by the electricity the device draws, not its heat. A 6 kW pump at COP 3 is offered about 2 kW. The cap takes the warmest value the control can hold.
  • After takes the battery energy a zone used off what the next zone is offered. It moves that energy on the meter to the slot that gave it up. After now takes the request the zone was planned from.
  • A comfort shift rounded to the step stays within the owner's limit.
  • RunSlots 0 is documented as unknown and read as a switch just made.
  • New tests: run time across the plan's start in both directions, a 25-hour day, and no slot drawing past its bound in three houses.

Closing this PR, since its content is in master.

@frahlg frahlg closed this Nov 15, 2026
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.

2 participants