Skip to content

Add hvac-predict: steer a thermostat's setpoints ahead of the weather - #1

Open
dannysauer wants to merge 3 commits into
masterfrom
ccr-68783811-lf14ed
Open

dannysauer wants to merge 3 commits into
masterfrom
ccr-68783811-lf14ed

Conversation

@dannysauer

@dannysauer dannysauer commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

What this adds

hvac_predict/ is a new, self-contained project. It's a command line tool for a Home Assistant thermostat that is left in auto mode: it chooses the heating and cooling setpoints from the weather forecast and a thermal model of the house, and never changes the mode.

  • train fits the model to the sensor history in VictoriaMetrics.
  • decide predicts the house with the equipment off, and picks one of two pairs of setpoints for the comfort setting the thermostat's schedule has reached, or a wider third pair while the house drifts to a new target. It doesn't change the thermostat unless you pass --apply; it writes its state file either way.

hvac_predict/README.md is the operator's guide.

The PR has three commits:

  1. The project.
  2. The one file outside that directory: a .pre-commit-config.yaml at the root. pre-commit.ci is installed on this repository and reported an error on this PR while the repository had no configuration for it. The file has it run ruff check and ruff format --check on hvac_predict/ and on nothing else. If you'd rather take pre-commit.ci off this repository, drop that commit.
  3. A restructuring that came out of the owner's code-quality review. It moves three pieces of the decision rules out of advisor.py into decision.py, moves the prediction into outlook.py, and splits a 994-line test file. It changes nothing the tool does.

Status: not yet run against anything real

The tool has only met simulated houses and stand-ins for Home Assistant and VictoriaMetrics. Everything it assumes about the ecobee comes from reading the source of Home Assistant's ecobee integration.

So this PR is for review, not for use. A review with access to Home Assistant and the metrics is planned before the tool steers the real thermostat, and docs/planning/follow-up.md is written for it. That file lists what still needs checking and gives the simulation results.

Where to start reading

  1. docs/planning/follow-up.md for the concerns and the simulation results.
  2. docs/architecture/overview.md for how a decision is made, what the code assumes about Home Assistant, and ten checks to make against the real system. Two of those checks change the thermostat and need the owner's go-ahead, and so does the first decide --apply.
  3. docs/adrs/ for the decisions. Two are Accepted, because the owner stated them: leave the thermostat in auto mode, and give the house a fixed time to reach a new target unaided. Four are Proposed and are the implementer's choices.

How it was tested

  • 531 tests pass, and ruff and mypy are clean. The tests fit the model to simulated houses and run both commands against stand-ins for the two services. Only the two ruff commands run on this PR, through pre-commit.ci; the tests and mypy ran locally.
  • A closed-loop simulation runs the tool against a simulated house and thermostat for days. Over ten days in three climates the tool did not save energy. It ran the equipment 29 to 46 percent more hours than the fixed pair that ran it less. What it bought was arrival: the tool reached every new target, in two and a half to four hours at its slowest, where five of the six fixed-pair runs left at least one target unreached when the next change came.
  • About eighty single-line faults were seeded into the rules, the state handling and the thermostat module to check that the tests notice, and 35 more into the restructured code. Every one the tests missed became a new test, with two exceptions that change nothing a test can see.
  • The restructuring was checked against the code before it: 120,000 random decisions and two trained models match exactly, and the ten-day simulation prints the same output. The receipt has the scripts and the results.
  • AI agents reviewed the code for correctness, security, maintainability and documentation, in four rounds. The owner's thermo-nuclear-code-quality-review followed, and did not approve the code as it stood; the third commit answers it. Two more reviews, of that commit alone, found no change in behaviour. The fixes from the last round of each have tests behind them and no independent review yet.

Things a reviewer should know

  • A vacation set on the ecobee should be left alone in two of the three ways the ecobee might report it. That comes from reading the integration's source and has not been tried. In the third, the tool can't tell and goes on steering, and with holds that last until changed the vacation never takes effect. A vacation that starts within about three minutes of a run can also be overridden. Until check 3 has been done on the real thermostat, switch the enable entity off before a vacation and cancel the tool's hold. That needs homeassistant.enable_entity configured, which the example configuration leaves out.
  • The tool leaves the thermostat alone, with exit status 0, when it finds a hold it has no record of placing. A hold placed by hand, a pair the thermostat altered and a lost state file all look like that, and nothing alerts anyone.
  • The owner's rule runs the air conditioner on a winter night whenever the house won't reach its night-time target unaided in 90 minutes.
  • One requirement is not met to the minute. HVP-008 says a reading more than 20 minutes old is refused, and the code counts those minutes from the newest five-minute mark, so a reading can be nearly 25 minutes old. It is open question 25 in the overview.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Jc6x3jsgxX6aQk6rRgNmHp

hvac-predict is a command line tool for a Home Assistant thermostat that
is left in auto mode. It chooses the heating and cooling setpoints from
the weather forecast and a thermal model of the house, and never changes
the mode. It lives in hvac_predict/ and touches nothing else.

- train fits a small thermal model to the sensor history in
  VictoriaMetrics: a bounded least-squares fit of the rate of change,
  with terms for heat stored in the walls. It checks the model against
  the newest fifth of the history and does not write one that does no
  better than assuming no change.
- decide predicts the house with the equipment off and picks a pair of
  setpoints for the comfort setting the thermostat's schedule has
  reached: heat at the target, or cool at the target, a differential
  apart. After a change of target the house gets coast_minutes to reach
  it unaided before the equipment drives it there. Nothing is set
  without --apply.
- The tool leaves the thermostat alone when it is not in heat_cool
  mode, holds another preset such as a vacation, has no configured
  target, is on a hold the tool has no record of placing, or the enable
  entity is off.
- State between runs is a small JSON file, read and written under a
  lock. Data from both services is treated as untrusted.

The design is written down in the trellis layout under
hvac_predict/docs/: an architecture overview with the checks to make
against the real system, requirements HVP-001 to HVP-024 traced to
tests, six decision records (two accepted, four proposed), and evidence
receipts. docs/planning/follow-up.md lists the concerns that remain and
the results of the simulation testing.

Nothing here has run against a real Home Assistant, ecobee or
VictoriaMetrics. In simulation the tool reaches a new target sooner
than a thermostat left on one pair and does not save energy.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Jc6x3jsgxX6aQk6rRgNmHp
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-17T00:37:06.231776Z
We couldn’t complete this review. Comment @codex review to try again.
80c72b1 PR opened
🔒 Security Review ❌ Failed 2026-11-17T00:37:14.998297Z
We couldn’t complete this review. Comment @codex security review to try again.
80c72b1 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@chatgpt-codex-connector

Copy link
Copy Markdown

The account paying for this security review has reached its Codex usage limits. The payer can check the Codex usage dashboard. If you do not manage the paying account, contact this repository's admins.

pre-commit.ci is installed on this repository and reports "error during
ci config" on a pull request. The repository had no
.pre-commit-config.yaml, and pre-commit can't run without one:
`pre-commit run --all-files` stops with "InvalidConfigError:
.pre-commit-config.yaml is not a file".

The new configuration runs `ruff check` and `ruff format --check` on
hvac_predict/ only, at the ruff version hvac_predict pins. The older
scripts are left out because they fail both. The hooks are local, so
pre-commit.ci's scheduled update has no version to move away from that
pin, and they only report, so nothing is pushed to a pull request's
branch.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Jc6x3jsgxX6aQk6rRgNmHp
The owner's code-quality review found three pieces of the rules in
advisor.py, where a test of the rules alone could not reach them: the
time a house is given to reach a new target, the limit on a drift's
idle setpoint (HVP-018), and the check that the thermostat still holds
the tool's choice. decide() now takes what the state file remembers, a
Change and a Choice, and applies all three itself. Settling, Standing
and the two functions that built them are gone, and a Goal refuses a
reach that would not bound its drift pair.

Also from that review:

- outlook.py takes the prediction of the house left alone out of
  advisor.py.
- tests/test_advisor.py, at 994 lines, becomes test_advise.py,
  test_steer.py and test_outlook.py, with what they share in
  advising.py.
- thermal._Dynamics keeps the history its runs start from, training.py
  calls fit and backtest through typed helpers in place of partials,
  and the keys of `decide --json` are listed once.

What the tool does is unchanged. The tests of advise and steer pass
with their assertions untouched, 120,000 random decisions and two
trained models match the old code exactly, and the ten-day simulation
prints the same output. The receipt of 2026-11-19 under
docs/planning/evidence has the checks. Two reviews of the restructuring
added tests, and two things they found that were already true are now
open questions 25 and 26: a reading's age is counted from the newest
five-minute mark, and the model file is believed as written.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Jc6x3jsgxX6aQk6rRgNmHp
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.

2 participants