Skip to content

feat(thermaltwin,heat): typed bounded twin v2, sensor guard, flow input, and closed-loop shadow sim - #2157

Draft
hannesb90 wants to merge 11 commits into
srcfl:masterfrom
hannesb90:feat/thermal-twin-v2
Draft

hannesb90 wants to merge 11 commits into
srcfl:masterfrom
hannesb90:feat/thermal-twin-v2

Conversation

@hannesb90

Copy link
Copy Markdown
Contributor

Stacked on #2041 (feat/heat-shadow-plan) — marked as Draft until #2041 is merged so the diff stays easy to review. The new commits on top of #2041 start at c937fa95.

Summary

Follow-up improvements to the thermal twin, heat planner, and shadow runner based on 11 days of real-house data (SE3 Sweden, Nov 21 – Dec 2, 2026) across a hydronic air-to-water heat pump floor slab (over crawlspace) and 3 direct-electric underfloor zones:

  1. Lagged candidate twin + typed bounded v2 (go/internal/thermaltwin/lagged.go, model.go, service.go):

    • Adds typed emitter profiles (electric_floor K=6, hydronic K=2, room_air K=6) with optional emitter / flow_ref_c config fields and automatic inference (go/internal/config/heat.go).
    • Uses information-form RLS with exponential forgetting toward physical priors, exact box-QP bounds (a > 0, consistent c), and Huber outlier weighting so wood-stove spikes or brief disturbances don't corrupt the twin.
    • Supports hydronic learning directly from supply/flow temperature (*_flow_temp_c as max(0, flow - ref)/10) instead of noisy compressor cycles.
    • Judges slow outdoor-boundary zones over 12 hours (Long) without requiring AfterOff >= 10 windows.
    • Adds a Sample.Suspect sensor guard (frozen sensor flatline & phantom output_limited with < 10 W draw) so misbehaving thermostats don't poison training or scoring.
    • Allows the candidate twin to provide physical parameters (Params()) and earn write trust (go/internal/heatrun/service.go, guard.go) while holding floor plans to room minimum temperatures.
  2. Closed-loop shadow rollout & long-peak relief (go/internal/heatrun/shadowlog.go, go/internal/heatplan/comfort.go):

    • Tracks independent closed-loop simulated trajectories (sim_temp_c/sim_cost vs sim_base_temp_c/sim_base_cost) in heat-shadow.jsonl to eliminate the open-loop "free coasting" mirage when evaluating shadow savings against real meter data.
    • Adds PeakRelief.NoTimeCap (band MinC governs coast duration; DP picks cheapest quarters inside long peaks; non-positive prices are never treated as peaks).
  3. Offline benchmark tool (go/cmd/heat-replay):

    • Standalone zero-SQLite replay CLI that feeds exported 30-min zone windows and 15-min electricity prices through FTW's actual thermaltwin and heatplan packages.

Real-house historical benchmark (Nov 21 – Dec 2, 2026, SE3)

Verified with go run ./cmd/heat-replay on anonymized real-house data (ftw-heat-replay-anonymized-2026-12-02.json — happy to share privately):

Twin accuracy (thermaltwin v2 candidate vs 1-node twin & persistence)

Zone Emitter Horizon v2 Candidate MAE 1-node Twin / Persistence Notes
floor_1 (bathroom downstairs, 900 W) electric_floor 3 h 0.227 K (0.207 K clean) 0.268 K / 0.358 K Warm miss 4%, bias +0.024 K
floor_2 (bathroom upstairs, 575 W) electric_floor 3 h 0.479 K (0.310 K clean) 0.564 K / 0.743 K 28 phantom-limit windows skipped
floor_3 (entryway, 650 W) electric_floor 3 h 0.506 K 0.542 K / 0.739 K τ = 5.5 h, C = 0.35 kWh/K
house_hydronic_w (A2W HP, house_heat_w) hydronic 12 h 0.230 K (0.188 K clean) 0.232 K / 0.266 K τ = 61.4 h, C = 9.04 kWh/K
house_hydronic_flow (A2W HP, flow_temp) hydronic 12 h 0.239 K (0.189 K clean) 0.266 K / 0.266 K Clean skill 0.68 < 0.80, τ = 63.2 h

Closed-loop shadow rollout vs real meter

Zone Days Open-loop Mirage (plan / base) Closed-loop Baseline Real Meter Closed-loop Planned Planned Temp (min / mean)
house_hydronic_w 7.9 d 444.4 / 846.0 kr 637.9 kr 646.8 kr (1.4%) 541.9 kr (−15%) 19.5 / 20.3 °C
floor_3 2.9 d 1.46 / 36.25 kr 35.4 kr 35.6 kr (0.6%) 15.1 kr 20.2 / 22.0 °C
floor_2 8.8 d 53.4 / 213.9 kr 106.5 kr 77.5 kr 44.7 kr 22.5 / 23.7 °C
floor_1 8.8 d 89.6 / 286.3 kr 212.2 kr 145.9 kr 71.9 kr 23.6 / 24.4 °C

Verification

  • go test ./internal/thermaltwin ./internal/heatplan ./internal/config ./internal/heatrun — all passing.
  • go run ./cmd/heat-replay -in ftw-heat-replay-anonymized-2026-12-02.json — verified end-to-end.
  • Currently running live in heat.write: false shadow mode on Raspberry Pi 4 (v0.166.0-beta.97).

hannesb90 and others added 11 commits December 5, 2026 17:47
A water-heated floor answers late and then settles, which the twin's form
cannot say. Run a candidate with six earlier windows of heat beside it and
score both over the same stretches. Nothing plans from it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: hannesb90 <bruhn90@gmail.com>
Raise the floor's limit for a measured room, leave neighbours' heat out of
dear slots, and check each plan against the lagged candidate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: hannesb90 <bruhn90@gmail.com>
Judge it as a plan uses it, on a week, against no-change and on how often a
zone ends colder than predicted. Bound the covariance without freezing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: hannesb90 <bruhn90@gmail.com>
A house on always-open loops moves a tenth of a kelvin in three hours, the
sensor's own step, so no form can beat "no change" there. A zone that
loses heat to outdoors is now held to a twelve-hour score instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The candidate learns one half-hour step at a time and is judged over three
or twelve hours. A house drifting 0.04 K/h is under its sensor's step in a
window and half a kelvin in twelve hours, so the step never sees it. Keep a
bounded rate correction that each judgement moves against its stretch's
error: the twelve hours for a slow zone, the three for a floor.

Replayed on 2026-11-27..12-02, the house's twelve-hour error fell from 0.54
to 0.23 K and its bias from -0.54 to -0.21 K; three hours and the floors
were unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: hannesb90 <279736760+hannesb90@users.noreply.github.com>
…Forecast hysteresis

- Raise longWarmupSamples from 12 (6h) to 48 (24h) so cold-start 12h errors before Huber engages do not pollute a week of hydronic skill scores.
- Make warmMissK emitter-aware (0.75 K for lively electric_floor, 0.5 K for hydronic/room_air) and tighten electric_floor negative lag lower bounds.
- Tolerate tiny 1-min relay blips and 15-min blockade boundary overlaps in AfterOff while keeping minAfterOffForForecast=10 strict.
- Align Lagged.Forecast skill gate with Status hysteresis (driftSkill once WasTrusted) so trusted zones do not flap unchecked around 0.80.
- Pass Twin.LastEval into heat-replay instead of hardcoded 0 so replay scores AfterOff/Forecast accurately.
A write needs the candidate twin trusted and checking the plan, so the
streaming-phone test's house carries one that agrees with it, as the
heatrun tests do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: hannesb90 <bruhn90@gmail.com>
@hannesb90
hannesb90 force-pushed the feat/thermal-twin-v2 branch from 5dc4287 to 0cc88dc Compare December 5, 2026 16:58
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.

1 participant