Skip to content

Commit ff516c9

Browse files
authored
small fixes (#1889)
* pid percent rounding * mpc loss fix * mpc loss fix * trvzb valve maintenance interval
1 parent c14e51c commit ff516c9

3 files changed

Lines changed: 5 additions & 8 deletions

File tree

custom_components/better_thermostat/model_fixes/TRVZB.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
_LOGGER = logging.getLogger(__name__)
1313

14-
VALVE_MAINTENANCE_INTERVAL_HOURS = 24
14+
VALVE_MAINTENANCE_INTERVAL_HOURS = 84
1515

1616
# Some users report that the TRVZB motor can occasionally lose its calibration and
1717
# fail to fully close the valve when commanded to very small openings.

custom_components/better_thermostat/utils/calibration/mpc.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,6 @@ class MpcParams:
8080
perf_curve_bin_pct: float = 2.0
8181

8282

83-
84-
85-
8683
@dataclass
8784
class MpcInput:
8885
"""Input parameters for MPC calibration calculation."""
@@ -380,7 +377,6 @@ def build_mpc_key(bt, entity_id: str) -> str:
380377
return f"{uid}:{entity_id}:{bucket}"
381378

382379

383-
384380
def _detect_regime_change(recent_errors: list[float]) -> bool:
385381
"""Detect systematic bias in prediction errors using Student's t-test.
386382
@@ -1099,7 +1095,7 @@ def _compute_predictive_percent(
10991095
common_ok
11001096
and learn_signal
11011097
and u_last <= min_open
1102-
and observed_rate < -0.01
1098+
and observed_rate < 0.0 # Allow learning even on slow cooling
11031099
):
11041100
loss_candidate = max(0.0, -observed_rate)
11051101

@@ -1206,7 +1202,6 @@ def _compute_predictive_percent(
12061202
gain_method = "insufficient_heat_boost"
12071203
adapt_debug["gain_boosted_insuff"] = True
12081204

1209-
12101205
# --- LOSS learning (warming with low valve): ---
12111206
# If we are below u0 but the room is warming, loss is overestimated.
12121207
# This handles the case where residual_u0_ss fails because rate is too high (warming).
@@ -1215,7 +1210,7 @@ def _compute_predictive_percent(
12151210
and learn_signal
12161211
and (not updated_loss)
12171212
and u_last < (u0_frac_est - 0.05)
1218-
and observed_rate > 0.01
1213+
and observed_rate > 0.0
12191214
):
12201215
# We are warming, so gain*u > loss.
12211216
# Since u is small, loss must be very small.

custom_components/better_thermostat/utils/calibration/pid.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,8 @@ def compute_pid(
322322

323323
# Clamp final result
324324
percent = max(0.0, min(100.0, percent))
325+
# Round to nearest integer to avoid micro-updates that trigger TRV logic
326+
percent = int(round(percent))
325327

326328
# Update last_percent
327329
st.last_percent = percent

0 commit comments

Comments
 (0)