Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 1.0.0b24 (2026-11-29)

### Fixed

- Forget residual heat peaks that fail to arrive once the observed maximum stalls for a learned dead time, allowing cold rooms to heat again; keep the early end after a temperature fall and the four-hour absolute limit.
- Saturate predicted overshoot at one learned dead time, with bounded feedback from clean observed peaks and a conservative migration of legacy learning. Long heating runs no longer multiply an inflated short-run rate.
- Discard overshoot events disturbed by windows, drafts, recovery, rapid room humidity rises, significant solar gain or pipe heat. The AI check now sees the last expected and observed peak and its error.

## 1.0.0b23 (2026-11-24)

### Added
Expand Down
48 changes: 31 additions & 17 deletions custom_components/house_assistant/heating/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
humid_issue,
next_interval_hours,
overheat_issue,
overshoot_feedback,
update_stable_count,
)
from .logic.ai_schema import (
Expand Down Expand Up @@ -1120,7 +1121,13 @@ def _on_switch_change(self, event: Event[EventStateChangedData]) -> None:
run_hours = (ts - area.on_since) / 3600 if (not turned_on and area.on_since) else 0.0
if area.learner is not None:
area.learner.on_switch(
ts, area.temp, turned_on, run_hours, pipe_active=self.pipe_active(area)
ts,
area.temp,
turned_on,
run_hours,
pipe_active=self.pipe_active(area),
overshoot_factor=area.params.overshoot_factor,
sample=self._learning_sample(area, ts),
)
area.on_since = ts if turned_on else None
area.off_at = None if turned_on else ts
Expand Down Expand Up @@ -1988,6 +1995,9 @@ async def _control_area(
area.status = AreaStatus.ACTUATOR_UNAVAILABLE
self._handle_events(area, ts, window_open_since, temp_before)

# Observe disturbances before a switch callback can finish an event.
area.learner.add_sample(self._learning_sample(area, ts))

if area.switch_available and decision.want_on == area.switch_on:
self._command_done(area)
elif (
Expand All @@ -1997,27 +2007,30 @@ async def _control_area(
):
await self._switch(area, decision.want_on, ts)

area.learner.add_sample(
Sample(
ts,
area.temp,
area.switch_on,
self.outdoor_temp,
self.pv_assumed,
area.airing or area.temp is None,
pv_unknown=self.pv_kw is None,
window_open=area.window_open,
opening=area.opening,
draft=area.draft,
pipe_active=self.pipe_active(area),
pipe_rate_kph=self._pipe_rate(area),
)
)
# The virtual room first: on the first tick of a day it starts at the real
# temperature even if the circuit is running at that moment.
self._track_virtual(area, minutes, target)
self._count(area, minutes, target, ts)

def _learning_sample(self, area: Area, ts: float) -> Sample:
"""The same room/environment snapshot for periodic and switch-event learning."""
return Sample(
ts,
area.temp,
area.switch_on,
self.outdoor_temp,
self.pv_assumed,
area.airing or area.temp is None,
pv_unknown=self.pv_kw is None,
window_open=area.window_open,
opening=area.opening,
draft=area.draft,
pipe_active=self.pipe_active(area),
pipe_rate_kph=self._pipe_rate(area),
humidity=area.humidity,
sun_factor=area.params.sun_factor,
)

def _handle_events(
self, area: Area, ts: float, open_since: float | None, temp_before: float | None
) -> None:
Expand Down Expand Up @@ -2910,6 +2923,7 @@ async def _run_check(self) -> None:
"sun": r(model.s, 3),
"overshoot_k": r(area.learner.overshoot.value),
"overshoot_per_h": r(area.learner.overshoot_rate.value, 3),
"last_overshoot": overshoot_feedback(area.learner.last_overshoot),
"dead_time_min": r(area.learner.dead_time.value / 60, 0),
"recovery_min": r(area.learner.recovery.value / 60, 0),
"recovery_model": _recovery_model_payload(area.learner),
Expand Down
9 changes: 9 additions & 0 deletions custom_components/house_assistant/heating/logic/ai_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,12 @@ def humid_issue(humid_min: float, mould_min: float, minutes: float) -> bool:
if minutes <= 0:
return False
return mould_min >= 30 or humid_min >= HUMID_SHARE * minutes


def overshoot_feedback(last: dict[str, float] | None) -> dict[str, float] | None:
"""Expose the last clean peak prediction error without adding a policy parameter."""
if last is None:
return None
return {
key: round(last[key], 3) for key in ("expected_peak", "real_peak", "error_k") if key in last
}
59 changes: 44 additions & 15 deletions custom_components/house_assistant/heating/logic/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@
from typing import Any

from ...core.store_validation import checked, checked_fields, dataclass_schema
from .peaks import (
PEAK_CARRY_MAX_S,
PEAK_PASSED_K,
PEAK_STALL_RISE_K,
peak_quiet,
peak_stalled,
)

FROST_HYSTERESIS = 0.5 # K above the frost limit before frost protection ends
RECOVERED_MARGIN = 0.1 # K below the temperature before airing counts as recovered
FORCE_ON_BELOW = 1.0 # K below target: heat regardless of predictions
PEAK_PASSED_K = 0.15 # K below the highest temperature since switch-off: overshoot has arrived
# The overshoot expected at switch-off is forgotten after this at the latest. It ends
# earlier once the temperature falls again; the peak comes several dead times after
# the switch-off, so the limit is not tied to the dead time.
PEAK_CARRY_MAX_S = 4 * 3600.0
FLOOR_PULSE_PERIOD_S = 3600.0 # the floor pulses of a visit: run time per hour
EPS = 1e-6 # tolerance for comparing sensor values in 0.1 K steps (21.0 - 0.1 > 20.9)

Expand Down Expand Up @@ -127,6 +129,8 @@ class AreaRuntime:
carry_peak: float | None = None # expected peak after switch-off, until it has arrived
carry_max: float | None = None # highest temperature seen since switch-off
carry_since: float | None = None
carry_last_rise: float | None = None # time of the last meaningful new maximum
carry_rise_max: float | None = None # reference for cumulative small sensor steps
events: list[str] = field(default_factory=list)

# Not stored and not restored: after a restart a stale peak must not start a carry
Expand Down Expand Up @@ -268,12 +272,13 @@ def _update_window(
return True


def _update_carry(data: ControlInput, rt: AreaRuntime) -> None:
"""Keep the overshoot expected at switch-off until the temperature falls again.
def _update_carry(
data: ControlInput, params: ControlParams, learned: LearnedValues, rt: AreaRuntime
) -> None:
"""Keep residual heat until its peak passes or evidently fails to arrive.

Without it the switch-on prediction starts from the current temperature, which is
below target by the very overshoot the switch-off counted on, and the circuit would
come back after the minimum off time while the floor is still delivering heat.
Initially the floor may still deliver heat. Once its maximum stalls, a phantom
peak must not keep a cold room waiting through the four-hour absolute limit.
"""
if data.switch_on:
rt.was_on = True
Expand All @@ -283,13 +288,37 @@ def _update_carry(data: ControlInput, rt: AreaRuntime) -> None:
rt.was_on = False
rt.carry_peak = rt.last_peak
rt.carry_max = data.temp
rt.carry_since = data.now
rt.carry_since = (
data.last_switch_change
if data.last_switch_change is not None and data.last_switch_change <= data.now
else data.now
)
rt.carry_last_rise = rt.carry_since
rt.carry_rise_max = data.temp
rt.last_peak = None
if rt.carry_peak is None or data.temp is None:
if rt.carry_peak is None:
return
rt.carry_max = data.temp if rt.carry_max is None else max(rt.carry_max, data.temp)
expired = rt.carry_since is None or data.now - rt.carry_since >= PEAK_CARRY_MAX_S
if expired or data.temp - rt.carry_max <= -PEAK_PASSED_K + EPS:
if expired:
rt.carry_peak = None
return
if data.temp is None:
return
# Older stores lack the progress fields; retain their original switch-off time.
if rt.carry_last_rise is None:
rt.carry_last_rise = rt.carry_since
if rt.carry_rise_max is None:
rt.carry_rise_max = rt.carry_max if rt.carry_max is not None else data.temp
if data.temp - rt.carry_rise_max >= PEAK_STALL_RISE_K - EPS:
rt.carry_last_rise = data.now
rt.carry_rise_max = data.temp
rt.carry_max = data.temp if rt.carry_max is None else max(rt.carry_max, data.temp)
stalled = peak_stalled(data.now, rt.carry_since, rt.carry_last_rise, learned.dead_time_s)
# A cold room must not wait another dead time for an already stalled phantom peak.
cold_stall = data.temp < data.target - params.hysteresis_on and peak_quiet(
data.now, rt.carry_last_rise, learned.dead_time_s
)
if stalled or cold_stall or data.temp - rt.carry_max <= -PEAK_PASSED_K + EPS:
rt.carry_peak = None


Expand Down Expand Up @@ -419,7 +448,7 @@ def step(
"""Decide whether the circuit of one area should be on."""
rt.events.clear()
may_switch = _may_switch(data, settings)
_update_carry(data, rt)
_update_carry(data, params, learned, rt)
recovering = _update_window(data, params, learned, rt)

if data.temp is None:
Expand Down
Loading
Loading