Skip to content

Added support for door sensors#1592

Draft
albummi wants to merge 1 commit intoKartoffelToby:masterfrom
albummi:feature_doorSensor
Draft

Added support for door sensors#1592
albummi wants to merge 1 commit intoKartoffelToby:masterfrom
albummi:feature_doorSensor

Conversation

@albummi
Copy link

@albummi albummi commented Feb 7, 2025

Motivation:

I wanted to have additional sensors for my doors inside better thermostat with different timing, because a open door should not always shut down the heater if only for a minute, I did this with NodeRed and a Helper before. But having all in one place is more convinient

Changes:

  1. File: controlling.py
    Added handling for door sensors: Similar to window sensors, we added logic to check door sensors and turn off the HVAC system if a door is open.
    Added debugging logs: We included debugging logs to trace the state of door sensors and ensure they are being processed correctly.

  2. File: config_flow.py

  • Added configuration options for door sensors similar to window sensors. This allows users to specify door sensors in the thermostat configuration.
  1. File: trv.py
  • Modified trigger_trv_change and update_hvac_action functions to handle door sensors similar to window sensors. This ensures the HVAC mode is adjusted when a door is open.
  • Added debugging logs to ensure door sensor events are recognized and processed correctly.
  1. File: init.py
  • Fixed a syntax error related to an unclosed parenthesis in the async_update_entry call. This ensures the code is syntactically correct and can be executed without errors.
  1. File: door.py
  • Added logic to handle door sensors. This implementation monitors the state of door sensors and triggers appropriate actions based on their state.
  1. File: climate.py
  • Integrated door sensor checks into the climate control logic. This ensures that the HVAC mode is adjusted when a door is open.
  1. File: strings.json
  • Added strings related to door sensor configuration and states. This supports the new functionality for handling door sensors in the user interface.
  1. File: const.py
  • Defined new constants for door sensor configuration and states. These constants are used to manage door sensor settings and actions throughout the application.
  1. File: de.json
  • Added German translations for the new strings related to door sensor settings and states. This ensures that the user interface supports the new door sensor functionality in German.

Related issue (check one):

  • fixes #
  • [ X] There is no related issue ticket

Checklist (check one):

  • I did not change any code (e.g. documentation changes)
  • [X ] The code change is tested and works locally.

Test-Hardware list (for code changes)

Raspberry Pi5. , Homeassistent Supervised
Core 2025.1.4
Supervisor 2024.12.3
Operating System 14.2
Frontend 20250109.2

Zigbee2MQTT Version: [2.1.0]
TRV Hardware: SONOFF | TRVZB

## Motivation:
I wanted to have additional sensors for my doors inside better thermostat with different timing, because a open door should not always shut down the heater if only for a minute, I did this with NodeRed and a Helper before. But having all in one place is more convinient 

## Changes:
1. File: controlling.py
Added handling for door sensors: Similar to window sensors, we added logic to check door sensors and turn off the HVAC system if a door is open.
Added debugging logs: We included debugging logs to trace the state of door sensors and ensure they are being processed correctly.

2. File: config_flow.py
- Added configuration options for door sensors similar to window sensors. This allows users to specify door sensors in the thermostat configuration.

3. File: trv.py
- Modified `trigger_trv_change` and `update_hvac_action` functions to handle door sensors similar to window sensors. This ensures the HVAC mode is adjusted when a door is open.
- Added debugging logs to ensure door sensor events are recognized and processed correctly.

4. File: __init__.py
- Fixed a syntax error related to an unclosed parenthesis in the `async_update_entry` call. This ensures the code is syntactically correct and can be executed without errors.

5. File: door.py
- Added logic to handle door sensors. This implementation monitors the state of door sensors and triggers appropriate actions based on their state.

6. File: climate.py
- Integrated door sensor checks into the climate control logic. This ensures that the HVAC mode is adjusted when a door is open.

7. File: strings.json
- Added strings related to door sensor configuration and states. This supports the new functionality for handling door sensors in the user interface.

8. File: const.py
- Defined new constants for door sensor configuration and states. These constants are used to manage door sensor settings and actions throughout the application.

9. File: de.json
- Added German translations for the new strings related to door sensor settings and states. This ensures that the user interface supports the new door sensor functionality in German.

## Related issue (check one):

- [ ] fixes #<issue number goes here>
- [ X] There is no related issue ticket

## Checklist (check one):

- [ ] I did not change any code (e.g. documentation changes)
- [X ] The code change is tested and works locally.

## Test-Hardware list (for code changes)
Raspberry Pi5. , Homeassistent Supervised 
Core 2025.1.4
Supervisor 2024.12.3
Operating System 14.2
Frontend 20250109.2

Zigbee2MQTT Version: [2.1.0]
TRV Hardware:  SONOFF | TRVZB
@albummi
Copy link
Author

albummi commented Feb 7, 2025

Hope now everything is correct with the Git Structure ;)
Thanks for support @RubenKelevra

@RubenKelevra
Copy link
Collaborator

Hope now everything is correct with the Git Structure ;) Thanks for support @RubenKelevra

Yep, everything is fine now!

@RubenKelevra
Copy link
Collaborator

Have you tested this code locally?

@albummi
Copy link
Author

albummi commented Feb 7, 2025

Have you tested this code locally?

Yes, Tested with Virtual Devices first, also tested with real sensors. Door or window open turns off heater.
Tested with different delay times. Also tested creating new Thermostat entities and changing existing one.

Found no problem while day testing yesterday. Actually the changed version is running on my HA in normal use.
Please test if it also works in your enviroment to make sure it's stable with different devices / configurations

@albummi
Copy link
Author

albummi commented Mar 13, 2025

Hey, any status here?
Using this now in my productive setup and see now problems in daily use.
Already working on next feature to be added :)

@RubenKelevra
Copy link
Collaborator

Using this now in my productive setup and see now problems in daily use.

Which problems do you see in daily use?

@KartoffelToby
Copy link
Owner

@albummi i want to merge your PR (thanks for your work btw) have you tested it in your setup?

@albummi
Copy link
Author

albummi commented Mar 21, 2025

Hey @KartoffelToby
Sorry for delay, actually traveling.

So in my setup all works fine, I’m using 5 minutes delay with no name AliExpress sensors and sonic thermostat on a RaspberryPi 5.
seeing no issues running on my productive setup.

@RubenKelevra the „now“ was a typo, there should be „see no problems“

@albummi
Copy link
Author

albummi commented May 2, 2025

Hey, is there any update about merging this to public? In my system still working without problem.

Would line to start integrating other features as well :)

@wtom wtom requested a review from Copilot October 1, 2025 00:36
Copy link
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 adds door sensor support to the Better Thermostat integration, extending the existing window sensor functionality to also handle door sensors with similar timing controls. This allows users to automatically turn off heating when doors are opened and restore heating after they're closed, with configurable delays.

  • Added door sensor configuration and handling logic similar to existing window sensors
  • Extended HVAC control logic to check both window and door sensor states
  • Added German translations and UI configuration options for door sensors

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
utils/controlling.py Added door sensor handling to HVAC control logic and renamed function to handle both sensors
utils/const.py Added door sensor configuration constants and attributes
translations/de.json Added German translations for door sensor UI elements
strings.json Added English strings for door sensor configuration
events/trv.py Extended TRV event handling to check door sensor state
events/door.py New file implementing door sensor event handling and queue processing
config_flow.py Added door sensor configuration options to setup and options flows
climate.py Integrated door sensor support into main climate entity
__init__.py Added migration logic for door sensor configuration

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +59 to +61
CONF_SENSOR_DOOR = "door_sensors"
CONF_DOOR_TIMEOUT = "door_off_delay"
CONF_DOOR_TIMEOUT_AFTER = "door_off_delay_after"
Copy link

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

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

Duplicate constant definitions found. CONF_SENSOR_DOOR, CONF_DOOR_TIMEOUT, and CONF_DOOR_TIMEOUT_AFTER are already defined at lines 33, 39, and 40 respectively.

Suggested change
CONF_SENSOR_DOOR = "door_sensors"
CONF_DOOR_TIMEOUT = "door_off_delay"
CONF_DOOR_TIMEOUT_AFTER = "door_off_delay_after"
Copilot uses AI. Check for mistakes.
Comment on lines +144 to +152
# Überprüfen Sie hier sowohl den Fenster- als auch den Türsensor
_new_hvac_mode = handle_sensors(self, _remapped_states)

# Debugging-Logs hinzufügen
_LOGGER.debug(
f"better_thermostat {self.device_name}: Türsensorzustand: {self.door_open}"
)
_LOGGER.debug(
f"better_thermostat {self.device_name}: Fenstersensorzustand: {self.window_open}"
Copy link

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

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

Comments and debug logs are written in German while the rest of the codebase uses English. This creates inconsistency and may cause issues for non-German speaking developers.

Suggested change
# Überprüfen Sie hier sowohl den Fenster- als auch den Türsensor
_new_hvac_mode = handle_sensors(self, _remapped_states)
# Debugging-Logs hinzufügen
_LOGGER.debug(
f"better_thermostat {self.device_name}: Türsensorzustand: {self.door_open}"
)
_LOGGER.debug(
f"better_thermostat {self.device_name}: Fenstersensorzustand: {self.window_open}"
# Check both the window and door sensors here
_new_hvac_mode = handle_sensors(self, _remapped_states)
# Add debugging logs
_LOGGER.debug(
f"better_thermostat {self.device_name}: Door sensor state: {self.door_open}"
)
_LOGGER.debug(
f"better_thermostat {self.device_name}: Window sensor state: {self.window_open}"
Copilot uses AI. Check for mistakes.
asyncio.create_task(window_queue(self))
if self.door_id is not None:
self.door_queue_task = asyncio.Queue(maxsize=1)
asyncio.create_task(control_queue(self))
Copy link

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

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

Duplicate call to asyncio.create_task(control_queue(self)) at line 352. This task is already created at line 347, causing the control queue to be started twice.

Suggested change
asyncio.create_task(control_queue(self))
Copilot uses AI. Check for mistakes.
Comment on lines 347 to +353
asyncio.create_task(control_queue(self))
if self.window_id is not None:
asyncio.create_task(window_queue(self))
if self.door_id is not None:
self.door_queue_task = asyncio.Queue(maxsize=1)
asyncio.create_task(control_queue(self))
if self.door_id is not None:
Copy link

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

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

The door_queue_task is created inside the conditional block but is used unconditionally in other parts of the code. This will cause AttributeError when door_id is None.

Suggested change
asyncio.create_task(control_queue(self))
if self.window_id is not None:
asyncio.create_task(window_queue(self))
if self.door_id is not None:
self.door_queue_task = asyncio.Queue(maxsize=1)
asyncio.create_task(control_queue(self))
if self.door_id is not None:
else:
self.window_queue_task = None
asyncio.create_task(control_queue(self))
if self.window_id is not None:
asyncio.create_task(window_queue(self))
self.door_queue_task = None
if self.door_id is not None:
self.door_queue_task = asyncio.Queue(maxsize=1)
Copilot uses AI. Check for mistakes.
hass.config_entries.async_update_entry(config_entry, data=new)


if config_entry.version == 2:
Copy link
Collaborator

Choose a reason for hiding this comment

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

@albummi this will never run for old installations

config_entry.version = 6
hass.config_entries.async_update_entry(config_entry, data=new)

if config_entry.version == 5:
Copy link
Collaborator

Choose a reason for hiding this comment

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

@albummi same here, should be checking for version 6 and then set it to 7.

@KartoffelToby
Copy link
Owner

I'll merge it as soon as all conflicts are solved :)

@KartoffelToby KartoffelToby marked this pull request as draft January 5, 2026 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

5 participants