Skip to content

Comments

Persist winter price brake offset and apply to control temperature#194

Merged
JohanAlvedal merged 1 commit intocodex/01from
codex/add-persistent-winter-price-braking-offset
Jan 20, 2026
Merged

Persist winter price brake offset and apply to control temperature#194
JohanAlvedal merged 1 commit intocodex/01from
codex/add-persistent-winter-price-braking-offset

Conversation

@JohanAlvedal
Copy link
Owner

Motivation

  • Allow a real, persistent winter price braking offset to affect the computed control temperature so expensive prices actually raise the control signal.
  • Compute brake targets from price pressure and apply them only when outdoor temperature is below WINTER_BRAKE_THRESHOLD using the existing WINTER_BRAKE_TEMP_OFFSET.
  • Surface the braking internals as attributes so users can inspect brake_target_c, brake_offset_c, and control_outdoor_temperature at runtime.

Description

  • Add a per-entry Store (_brake_offset_store) and persistence helpers async_load/async_save wrappers via _load_brake_offset and _persist_brake_offset to hold brake_offset_c across restarts.
  • Compute price_pressure = clamp(price_factor_percent / 100, 0, 1) and brake_target_c = price_pressure * WINTER_BRAKE_TEMP_OFFSET (applied only when sensor_data["outdoor_temp"] <= WINTER_BRAKE_THRESHOLD), then rate-limit the applied brake_offset_c using the existing apply_rate_limit.
  • Apply the offset to the temperature used for control as control_outdoor_temperature = fake_temp + brake_offset_c and clamp that final control temperature within MIN_FAKE_TEMP..MAX_FAKE_TEMP before passing it into _apply_control_bias.
  • Ensure attributes brake_target_c, brake_offset_c, and control_outdoor_temperature are populated in the sensor attributes for visibility.
  • Guard ML initialization for test environments and add a minimal Store stub in test helpers so unit tests can run without a full Home Assistant runtime.

Note: the implementation uses only the existing constants WINTER_BRAKE_TEMP_OFFSET, WINTER_BRAKE_THRESHOLD, MIN_FAKE_TEMP, and MAX_FAKE_TEMP as requested.

Testing

  • Ran pytest against the repository test suite; final result: 31 passed.
  • During development initial test collection failed due to missing homeassistant.helpers.storage in the test stubs, which was resolved by adding a minimal Store stub; after that all tests passed.

Explanation of the true control signal: the effective control value sent to the heat pump is the PI-adjusted temperature adjusted_temp which is assigned to the sensor via self._attr_native_value after control_outdoor_temperature (which includes brake_offset_c) is run through _apply_control_bias.


Codex Task

@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@JohanAlvedal JohanAlvedal merged commit 403e867 into codex/01 Jan 20, 2026
1 of 4 checks passed
@JohanAlvedal JohanAlvedal deleted the codex/add-persistent-winter-price-braking-offset branch January 29, 2026 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant