The Algorithm.

Working on a heating/cooling algorithm now that I can use HA. Here's the proposals the AI came up with based on my assessment. I like this. This is exactly what I was going for.

Claude: You're onto something important. Let me work through this.


The Problem with the Current Algorithm

The current formula computes a single adjustment and slides both setpoints by the same amount:

cool_sp = cool_base + adjustment
heat_sp = cool_base + adjustment - band_width

The band is always 4°F wide, always the same shape, just shifted up or down. This means on a cool, overcast day like yesterday:

  • Outdoor: ~68-72°F — below the cool threshold but not cold enough to trigger the heat adjustment (needs to be below indoor - heat_threshold, which is 74 - 20 = 54°F)
  • Algorithm says: adjustment = 0 (dead zone)
  • Band sits at: 70°F heat / 74°F cool
  • House drifts down to 70-71°F. No HVAC action — you're in the band.
  • But 70°F feels cold when you're sitting still.

The algorithm was designed around extreme days — hot days push cooling tighter, cold days push heating tighter. It has nothing to say about mild days, which is exactly when the dead zone leaves you uncomfortable.


Why Your Instinct Is Right

The two edges of the band serve completely different purposes:

  • Heat setpoint (bottom) = "don't let it drift below this." Only matters when the house wants to cool down (cool/overcast days, nighttime, winter).
  • Cool setpoint (top) = "don't let it climb above this." Only matters when the house wants to warm up (hot days, afternoon sun, summer).

On any given day, only one edge is doing real work. The other edge is irrelevant. But the current algorithm treats them as rigidly coupled.

Your observation: on a 72°F overcast day, the heat setpoint is the active edge and it should be at 72°F, not 70°F. On a 95°F day, the cool setpoint is the active edge and it should be at 73-74°F. The inactive edge can be wide — who cares.


What the New Algorithm Should Look Like

Instead of one adjustment moving both setpoints, compute them independently. The key parameter is a comfort target — the temperature you actually want the house to settle at:

comfort_target = 72°F  (new parameter — "the temp I want to feel")

# How hard is the weather pushing indoor temp away from target?
cold_pressure = max(0, comfort_target - outdoor_temp)
hot_pressure  = max(0, outdoor_temp - comfort_target)

# Heat edge: rises toward comfort_target on cool days
heat_sp = comfort_target - base_heat_margin + (cold_pressure × heat_squeeze)

# Cool edge: drops toward comfort_target on hot days  
cool_sp = comfort_target + base_cool_margin - (hot_pressure × cool_squeeze)

# Safety: enforce minimum band width (thermostats typically require ≥2°F)
if cool_sp - heat_sp < min_band:
    cool_sp = comfort_target + min_band/2
    heat_sp = comfort_target - min_band/2

The band squeezes from the side that matters and stays wide on the side that doesn't.

What this gives you for yesterday's scenario:

  • Outdoor 68°F, comfort target 72°F
  • cold_pressure = 72 - 68 = 4
  • Heat edge squeezes up: 72 - 3 + (4 × 0.3) = 70.2°F → house stays warmer
  • Cool edge barely moves: 72 + 3 - 0 = 75°F → doesn't matter, no cooling needed
  • Result: band is 70.2–75°F, house settles around 71-72°F instead of drifting to 70°F

For a 95°F day:

  • hot_pressure = 95 - 72 = 23
  • Cool edge squeezes hard: 72 + 3 - (23 × 0.15) = 71.5°F → aggressive cooling
  • Heat edge goes wide: 72 - 3 + 0 = 69°F → doesn't matter
  • Upstairs: cool_sp = 71.5 - 1 (offset) = 70.5°F
  • Result: tight cooling exactly where it matters

Parameters for the New Algorithm

Parameter What it controls Suggested start
comfort_target Ideal indoor temp 72°F
base_heat_margin How far below target before heating (mild day) 2-3°F
base_cool_margin How far above target before cooling (mild day) 2-3°F
heat_squeeze How aggressively heat edge rises when cold out 0.2-0.4 per °F
cool_squeeze How aggressively cool edge drops when hot out 0.1-0.2 per °F
min_band Minimum gap between heat and cool setpoints 2°F
upstairs_offset Cool setpoint reduction for upstairs 1°F (keep existing)

The comfort_target is the conceptual center of gravity. Everything else is about how the band shapes around it. The squeeze rates would be what the feedback log data helps us tune — if you're still logging "too_cold" on 65°F days, heat_squeeze needs to go up.


My Opinion

This is a genuinely better model. The current algorithm was fine for extreme days (and the squeeze rates can replicate that behavior), but its dead zone is the source of your mild-day discomfort. The new approach:

  1. Always has an opinion — no dead zone where both edges go slack
  2. Concentrates effort on the edge that matters — energy efficient
  3. Has a clear mental model — "where do I want the house to be, and which side needs protecting right now"
  4. The feedback log feeds directly into tuning — each "too_hot" or "too_cold" entry now maps clearly to "was the active edge tight enough?"

The one thing to watch: the squeeze rates need to be gentle enough that you don't get HVAC short-cycling (setpoints oscillating as outdoor temp fluctuates). A 10-minute evaluation interval with a 0.5°F change threshold should prevent that.