Added support for door sensors#1592
Conversation
## 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
|
Hope now everything is correct with the Git Structure ;) |
Yep, everything is fine now! |
|
Have you tested this code locally? |
Yes, Tested with Virtual Devices first, also tested with real sensors. Door or window open turns off heater. Found no problem while day testing yesterday. Actually the changed version is running on my HA in normal use. |
|
Hey, any status here? |
Which problems do you see in daily use? |
|
@albummi i want to merge your PR (thanks for your work btw) have you tested it in your setup? |
|
Hey @KartoffelToby 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. @RubenKelevra the „now“ was a typo, there should be „see no problems“ |
|
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 :) |
There was a problem hiding this comment.
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.
| CONF_SENSOR_DOOR = "door_sensors" | ||
| CONF_DOOR_TIMEOUT = "door_off_delay" | ||
| CONF_DOOR_TIMEOUT_AFTER = "door_off_delay_after" |
There was a problem hiding this comment.
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.
| CONF_SENSOR_DOOR = "door_sensors" | |
| CONF_DOOR_TIMEOUT = "door_off_delay" | |
| CONF_DOOR_TIMEOUT_AFTER = "door_off_delay_after" |
| # Ü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}" |
There was a problem hiding this comment.
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.
| # Ü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}" |
| 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)) |
There was a problem hiding this comment.
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.
| asyncio.create_task(control_queue(self)) |
| 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: |
There was a problem hiding this comment.
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.
| 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) |
| hass.config_entries.async_update_entry(config_entry, data=new) | ||
|
|
||
|
|
||
| if config_entry.version == 2: |
There was a problem hiding this comment.
@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: |
There was a problem hiding this comment.
@albummi same here, should be checking for version 6 and then set it to 7.
|
I'll merge it as soon as all conflicts are solved :) |
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:
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.
File: config_flow.py
trigger_trv_changeandupdate_hvac_actionfunctions to handle door sensors similar to window sensors. This ensures the HVAC mode is adjusted when a door is open.async_update_entrycall. This ensures the code is syntactically correct and can be executed without errors.Related issue (check one):
Checklist (check one):
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