Repository navigation
feat(thermaltwin): learn each declared room's thermal twin in shadow - #1996
Conversation
3e1efa8 to
5150469
Compare
frahlg
left a comment
There was a problem hiding this comment.
Reviewed and tested: the shadow property holds. The service reads only LatestMetric and the outdoor temperature, has no path to the registry or a driver default, runs in its own goroutine, and the stack passes make verify on today's master. One thing before merge:
- "Trusted" does not show skill yet (
thermaltwin/model.go,Status()andphysical()). A twin is trusted on 3 h mean error ≤ 0.3 K, a physical range for tau and capacity, and some power samples. It is never compared with "the temperature stays as it is". In a thermostat-held house (indoor 21 ± 0.15 K, heat following the cold, three weeks of windows) a probe reachedtrustedat 0.08 K MAE, although(Tout−Tin)andPmove together and the room never moves, so tau and C cannot be learned there. Nothing reads the flag today, but ADR 0012 makes it the gate for planned control, and #2013 would be its first reader. Please judge against persistence (the error must beat "no change") and require enough variation in heat input in the windows judged; until then, call the state something other than trusted.
Lower:
- The heat input is
hp_power_w, the heat pump's total electrical power, which includes hot-water charging and defrost, sobis biased. A space-heat power metric declared by the driver would fix it; worth a line in the PR or the ADR. thermalTwins.Zonesre-reads and parses the whole driver catalog every 30 minutes on every site, heat pump or not, whileTickholdsmu. Cheap to skip when no enabled driver declares sensors.- The new
thermaltwin/<driver>/<metric>rows stay in the config store when a zone goes away; delete them with the zone.
Step 3 of ADR 0012 (srcfl#1994). For every room sensor a driver declares, FTW fits dT/dt = a(Tout - Tin) + b*P + c by recursive least squares over 30-minute windows: inertia, capacity, heat loss and other gains. The twin is judged by simulating each three-hour stretch from the parameters it had at the start with the inputs that really happened, and reports learning, trusted, drifting or no_heat_input. It reads LatestMetric and the load model's outdoor temperature, persists through modelstate, and is shown at GET /api/thermal/twins with shadow: true. It commands nothing and nothing plans from it. Refs srcfl#520 Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: hannesb90 <[email protected]>
Review of srcfl#1996: a twin reached "trusted" in a house a thermostat holds still, at 0.08 K error, although outdoor temperature and heat input move together there and the room never moves, so inertia and capacity cannot be learned. The error was never compared with "the temperature stays as it is". A twin is now trusted only when, over a week of three-hour judgements, its error is at most 0.8 of the error of assuming no change, and heat input varied within at least a fifth of the judged stretches. A twin whose error is within the limit without that reads "unproven". The API shows both errors and the share. Stored twins of the earlier form cold start. Also from the review: - The service no longer reads the driver catalog. main hands it the zones from the catalog it already loads at start and on each applied configuration, so nothing is parsed every 30 minutes or under the service's lock. - A zone that is no longer declared has its stored twin deleted, also when it went away while FTW was not running. An incomplete zone list (a driver with no catalog entry) forgets nothing. - hp_power_w includes hot-water charging and defrost, which biases b; said where the metric is named and in the changeset. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: hannesb90 <[email protected]>
1f1e0be to
5ea4f36
Compare
|
Thanks for the probe. Rebased onto master and addressed in 5ea4f36. 1. Trusted now needs skill. Each three-hour judgement is also scored for "the temperature stays as it is", and for whether heat input varied within the stretch (lowest window at most 70 % of the highest, and the highest at least 0.1 kW). Over a week of judgements a twin is trusted only when its error is at most 0.8 of the no-change error and heat input varied in at least a fifth of the stretches. A twin within the 0.3 K limit without that reads
Stored twins of the earlier form cold start, since the fingerprint changed. Lower:
Not run here: the race detector (unsupported on the Pi I tested on); CI ran it green. |
miravoss26
left a comment
There was a problem hiding this comment.
Thermal twin in shadow mode: an online RLS fit per declared room sensor, an /api/thermal/twins read endpoint, persistence in the state store, and a changeset. It commands nothing. Stacked on #1995, so this review only covers the surface a reviewer will hit first, not the full ~1400 added lines.
What I checked:
- Read-only HTTP endpoint (
GET /api/thermal/twins). No new deps, no new hosts, no secrets, no shell-outs. The state write goes through the existingdurableConfigWritetransaction with a parameterisedDELETE. - Test files exist for the model, the service, the API and the store, including tolerance checks on recovered tau / capacity / UA.
What I did not do: verify the RLS maths in thermaltwin/model.go or the windowing in service.go. That is the part that needs a human with the ADR 0012 context. Also, this PR can't merge before #1995, so merge order matters.
Needs a human decision on the model review. Nothing in the security screen blocks it.
frahlg
left a comment
There was a problem hiding this comment.
Thanks, all four points are addressed. At 5ea4f36, merged with today's master (including #2009, which also touches state/store.go): go build ./... and go vet are clean, and go test passes for state, thermaltwin, cmd/ftw and api.
A probe outside the PR (not committed) confirms the new gate. A thermostat-held house stays unproven: MAE 0.19 K against 0.18 K for no change, with no heat variation. Pump cycling and a nightly setback reach trusted. The shadow property holds: only main.go and the read-only GET /api/thermal/twins reach thermaltwin.
Notes for later, not blocking:
- A twin that was trusted and then fails the skill test reads
unproven, notdrifting. - The setback case had a heat-varied share of 0.23, close to the 0.2 gate, so real houses may sit near it. Worth watching once sites report.
Problem and result
Step 3 of ADR 0012 (#1994), following the owner's answer there: "Go ahead, starting with the twin in shadow." Planning heat needs to know how long a room coasts and how hard the heat source moves it. FTW measures neither today. This learns both, per declared room sensor, and commands nothing.
Model. One first-order twin per zone, fitted online by recursive least squares over 30-minute windows:
atau_h)bcapacity_kwh_per_k)a/bua_w_per_k)cother_gain_k_per_h)Inputs.
T_inis a sensor declared withasset = "space_heat"(feat(drivers): let a control declare what it does to heat #1995).T_outcomes from the same forecast cacheloadmodellearns from.Pishp_power_wfrom the sensor's own driver, or from the single other driver that reports it. With two candidates the twin does not guess: it learns without heat input and says so.Judgement. The twin is never judged by its own fit. Each three-hour stretch is simulated from the parameters it had at the start, using the inputs that really happened, and compared with the measured temperature. Status is
learning, thentrustedonce there is a week of windows, a day of judgements, physical parameters and a mean error ≤ 0.3 K. It becomesdriftingabove 0.5 K, orno_heat_inputwhen no heat input is available.GET /api/thermal/twinsreturns every twin withshadow: true. The route is also listed for analysis agents.Scope and safety
Commands nothing. No new path to
Registry. Per the owner's answer 3, an untrusted twin gives no planned control, and today no twin gives any.Layer, not core (docs(vision): a hard, simple core with layers on top #1772). The twin runs in its own goroutine and reads only
LatestMetric(noRawW/SmoothedW/ReadingsBy*) and the forecast cache. It never holds up the control tick. It fails soft: a missing catalog, sensor or outdoor temperature just skips windows.Bad data is rejected, not learned:
A changed source restarts the twin, because a fit to one source means nothing against another.
Persistence goes through
modelstatewith a feature fingerprint, so state fitted to another model form cold-starts.Learning steps: none, per the owner's answer 4. The twin learns only from ordinary operation and owner holds.
Only
space_heatzones. A tank or buffer has the same form, but it loses heat to the room it stands in, which no sensor here gives yet.Known limits, measured in tests rather than assumed:
TestTwinFollowsAChangedHousepins this.bis learned against electrical input, so it includes COP, which varies with outdoor temperature. That is good enough for a shadow twin, and it is a known refinement before planning.Verification
Raspberry Pi 4 (linux/arm64), Go 1.26.10, pinned drivers fetched:
make verifylocally.Checklist
🤖 Generated with Claude Code