Skip to content

Generic thermostat: propagate unavailable sensor state and add sensor error actions#167290

Open
akshimassar wants to merge 4 commits into
home-assistant:devfrom
akshimassar:generic-thermostat-sensor-error
Open

Generic thermostat: propagate unavailable sensor state and add sensor error actions#167290
akshimassar wants to merge 4 commits into
home-assistant:devfrom
akshimassar:generic-thermostat-sensor-error

Conversation

@akshimassar
Copy link
Copy Markdown

@akshimassar akshimassar commented Apr 3, 2026

Breaking change

Proposed change

This PR improves generic_thermostat behavior when the temperature sensor becomes unavailable at runtime.

  • Propagates sensor unavailability to the climate entity by setting current_temperature to None when sensor state is unavailable, unknown, or invalid.
  • Adds configurable sensor_error_action with values:
    • keep (default, preserves current behavior)
    • force_off
    • force_on
  • Integrates sensor_error_action into the existing control path by mapping to too_cold/too_hot, so keep-alive, cooldown/min-cycle, and max-cycle handling are still honored.
  • Adds translated selector labels for action values in config flow.
  • Adds regression coverage for runtime unavailable handling, action behavior, mode-off behavior, and config flow snapshots.

Rationale

Thermostat failures can be safety-relevant, and wireless sensor loss is a realistic failure mode.

In my setup, a garage temperature sensor lost connectivity while the actuator was off. The thermostat still appeared healthy (idle, last known temperature above target), but the real garage temperature continued to fall.

This PR addresses two user-facing risks:

  • Visibility: when sensor input is unavailable, current_temperature now reflects that instead of continuing to expose stale data. This allows monitoring/alerts to react correctly.
  • Safe fallback behavior: different heating systems need different fail-safe actions.
    • For electric heating, force_off may be safest to reduce overheating risk.
    • For water-based freeze protection, force_on may be safest to reduce freezing risk.
    • keep remains available and, with unavailable temperature propagation, now respects max-cycle limits instead of reactivating from stale temperature input.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies a diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

Copilot AI review requested due to automatic review settings April 3, 2026 11:23
Copy link
Copy Markdown
Contributor

@home-assistant home-assistant Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @akshimassar

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves generic thermostat behavior when a temperature sensor becomes unavailable at runtime by:

  1. Propagating sensor unavailability: Sets current_temperature to None when the sensor state becomes unavailable, unknown, or invalid (e.g., NaN, Inf)
  2. Configurable error handling: Introduces a sensor_error_action option with three modes:
    • keep (default): Maintains current behavior without forcing any action
    • force_off: Forces the actuator off when sensor is unavailable
    • force_on: Forces the actuator on when sensor is unavailable
  3. Integrated control path: Sensor error actions map to the existing too_cold/too_hot control logic, preserving keep-alive, cooldown/min-cycle, and max-cycle handling
  4. Enhanced visibility: Adds sensor_error and sensor_error_action attributes to the climate entity state for monitoring

Changes:

  • Added sensor error action constants and configuration options
  • Modified temperature update logic to propagate unavailability instead of silently ignoring it
  • Implemented sensor error tolerance computation based on configured action
  • Added config flow support with translated selector labels
  • Comprehensive test coverage including runtime unavailability, action behavior, mode-off scenarios, and keep-alive/max-cycle interactions

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
homeassistant/components/generic_thermostat/const.py Adds constants for sensor error actions and default behavior
homeassistant/components/generic_thermostat/config_flow.py Integrates sensor_error_action selector into configuration flow with translation support
homeassistant/components/generic_thermostat/climate.py Implements sensor unavailability propagation, error action handling, and control logic updates
homeassistant/components/generic_thermostat/strings.json Provides translated labels for sensor error action options and configuration fields
tests/components/generic_thermostat/test_climate.py Adds comprehensive tests for unavailability handling, error actions, and timer behavior
tests/components/generic_thermostat/test_config_flow.py Updates config flow tests to include new sensor error action option
tests/components/generic_thermostat/snapshots/test_config_flow.ambr Updates snapshots to include new state attributes

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

@akshimassar akshimassar marked this pull request as ready for review April 3, 2026 12:10
@issue-triage-workflows
Copy link
Copy Markdown

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes.
Thank you for your contribution!

Set current_temperature to None when the target sensor becomes
unavailable or unknown at runtime, so climate state reflects sensor
availability.

Add regression tests covering runtime propagation and ensuring
keep_alive callbacks and max_cycle_duration shutdown are still honored
while the sensor is unavailable.
Introduce configurable behavior for sensor-unavailable states via
keep/force_on/force_off actions while preserving existing cycle and
keep-alive control paths. Surface the option in config flows and add
regression coverage for runtime behavior and snapshots.
@akshimassar akshimassar force-pushed the generic-thermostat-sensor-error branch from ea2c6e3 to 0dad262 Compare June 2, 2026 13:45
@akshimassar
Copy link
Copy Markdown
Author

I've rebased upon latest dev branch. Still would like to merge it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants