From dc94bbaa3953dd84796de6cf481fd3cf8baf0d4e Mon Sep 17 00:00:00 2001 From: Folfy Date: Sun, 10 Nov 2024 15:25:50 +0000 Subject: [PATCH 1/2] Added linear calibration mode --- .../better_thermostat/calibration.py | 15 +++++++++++---- .../better_thermostat/config_flow.py | 3 +++ custom_components/better_thermostat/strings.json | 2 +- .../better_thermostat/translations/en.json | 2 +- .../better_thermostat/utils/const.py | 1 + 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/custom_components/better_thermostat/calibration.py b/custom_components/better_thermostat/calibration.py index 4cae0e52..230f5eb1 100644 --- a/custom_components/better_thermostat/calibration.py +++ b/custom_components/better_thermostat/calibration.py @@ -82,14 +82,18 @@ def calculate_calibration_local(self, entity_id) -> Union[float, None]: if self.attr_hvac_action == HVACAction.HEATING: if _new_trv_calibration > -2.5: _new_trv_calibration -= 2.5 - - if _calibration_mode == CalibrationMode.HEATING_POWER_CALIBRATION: + elif _calibration_mode == CalibrationMode.HEATING_POWER_CALIBRATION: if self.attr_hvac_action == HVACAction.HEATING: _valve_position = heating_power_valve_position(self, entity_id) _new_trv_calibration = _current_trv_calibration - ( (self.real_trvs[entity_id]["local_calibration_min"] + _cur_trv_temp_f) * _valve_position ) + elif _calibration_mode == CalibrationMode.LINEAR_CALIBRATION: + # offset setpoint by 0.5C for every 0.1C temperature difference to target (max +/-2C) + _offset = (_cur_target_temp - _cur_external_temp) * 5 + _new_trv_calibration = min(max(-2, _offset), 2) + 0.26 + # Respecting tolerance in all calibration modes, delaying heat if self.attr_hvac_action == HVACAction.IDLE: @@ -176,14 +180,17 @@ def calculate_calibration_setpoint(self, entity_id) -> Union[float, None]: if self.attr_hvac_action == HVACAction.HEATING: if _calibrated_setpoint - _cur_trv_temp_s < 2.5: _calibrated_setpoint += 2.5 - - if _calibration_mode == CalibrationMode.HEATING_POWER_CALIBRATION: + elif _calibration_mode == CalibrationMode.HEATING_POWER_CALIBRATION: if self.attr_hvac_action == HVACAction.HEATING: valve_position = heating_power_valve_position(self, entity_id) _calibrated_setpoint = _cur_trv_temp_s + ( (self.real_trvs[entity_id]["max_temp"] - _cur_trv_temp_s) * valve_position ) + elif _calibration_mode == CalibrationMode.LINEAR_CALIBRATION: + # offset setpoint by 0.5C for every 0.1C temperature difference to target (max +/-2C) + _offset = (_cur_target_temp - _cur_external_temp) * 5 + _calibrated_setpoint = _cur_target_temp + min(max(-2, _offset), 2) + 0.26 if self.attr_hvac_action == HVACAction.IDLE: if _calibrated_setpoint - _cur_trv_temp_s > 0.0: diff --git a/custom_components/better_thermostat/config_flow.py b/custom_components/better_thermostat/config_flow.py index c32446ca..ed5171de 100644 --- a/custom_components/better_thermostat/config_flow.py +++ b/custom_components/better_thermostat/config_flow.py @@ -96,6 +96,9 @@ selector.SelectOptionDict( value=CalibrationMode.HEATING_POWER_CALIBRATION, label="AI Time Based" ), + selector.SelectOptionDict( + value=CalibrationMode.LINEAR_CALIBRATION, label="Linear Proportional" + ), selector.SelectOptionDict( value=CalibrationMode.NO_CALIBRATION, label="No Calibration" ), diff --git a/custom_components/better_thermostat/strings.json b/custom_components/better_thermostat/strings.json index a445e276..6181d941 100644 --- a/custom_components/better_thermostat/strings.json +++ b/custom_components/better_thermostat/strings.json @@ -32,7 +32,7 @@ }, "data_description": { "protect_overheating": "Some TRVs don't close the valve completly when the temperature is reached. Or the radiator have a lot of rest heat. This can cause overheating. This option can prevent this.", - "calibration_mode": "The kind how the calibration should be calculated\n***Normal***: In this mode the TRV internal temperature sensor is fixed by the external temperature sensor.\n***Aggresive***: In this mode the TRV internal temperature sensor is fixed by the external temperature sensor but set much lower/higher to get a quicker boost.\n***AI Time Based***: In this mode the TRV internal temperature sensor is fixed by the external temperature sensor, but the value is calculated by a custom algorithm to improve the TRV internal algorithm.", + "calibration_mode": "The kind how the calibration should be calculated\n***Normal***: In this mode the TRV internal temperature sensor is fixed by the external temperature sensor.\n***Aggresive***: In this mode the TRV internal temperature sensor is fixed by the external temperature sensor but set much lower/higher to get a quicker boost.\n***AI Time Based***: In this mode the TRV internal temperature sensor is fixed by the external temperature sensor, but the value is calculated by a custom algorithm to improve the TRV internal algorithm.\n***Linear Proportional***: Adds/Substracts 0.5°C per 0.1°C difference of target vs actual temperature (independent of TRV internal temperature; recommended for HomematicIP", "calibration": "How the calibration should be applied on the TRV (Target temp or offset)\n***Target Temperature Based***: Apply the calibration to the target temperature.\n***Offset Based***: Apply the calibration to the offset." } }, diff --git a/custom_components/better_thermostat/translations/en.json b/custom_components/better_thermostat/translations/en.json index 2d9fcebf..95578adc 100644 --- a/custom_components/better_thermostat/translations/en.json +++ b/custom_components/better_thermostat/translations/en.json @@ -33,7 +33,7 @@ }, "data_description": { "protect_overheating": "Some TRVs don't close the valve completely when the temperature is reached. Or the radiator has a lot of rest heat. This can cause overheating. This option can prevent this.", - "calibration_mode": "The kind how the calibration should be calculated\n***Normal***: In this mode, the TRV internal temperature sensor is fixed by the external temperature sensor.\n***Aggresive***: In this mode, the TRV internal temperature sensor is fixed by the external temperature sensor but set much lower/higher to get a quicker boost.\n***AI Time Based***: In this mode, the TRV internal temperature sensor is fixed by the external temperature sensor, but a custom algorithm calculates the value to improve the TRV internal algorithm.", + "calibration_mode": "The kind how the calibration should be calculated\n***Normal***: In this mode the TRV internal temperature sensor is fixed by the external temperature sensor.\n***Aggresive***: In this mode the TRV internal temperature sensor is fixed by the external temperature sensor but set much lower/higher to get a quicker boost.\n***AI Time Based***: In this mode the TRV internal temperature sensor is fixed by the external temperature sensor, but the value is calculated by a custom algorithm to improve the TRV internal algorithm.\n***Linear Proportional***: Adds/Substracts 0.5°C per 0.1°C difference of target vs actual temperature (independent of TRV internal temperature; recommended for HomematicIP", "calibration": "How the calibration should be applied on the TRV (Target temp or offset)\n***Target Temperature Based***: Apply the calibration to the target temperature.\n***Offset Based***: Apply the calibration to the offset." } }, diff --git a/custom_components/better_thermostat/utils/const.py b/custom_components/better_thermostat/utils/const.py index cd319a1c..6c2bc5b8 100644 --- a/custom_components/better_thermostat/utils/const.py +++ b/custom_components/better_thermostat/utils/const.py @@ -105,4 +105,5 @@ class CalibrationMode(StrEnum): DEFAULT = "default" AGGRESIVE_CALIBRATION = "fix_calibration" HEATING_POWER_CALIBRATION = "heating_power_calibration" + LINEAR_CALIBRATION = "linear_calibration" NO_CALIBRATION = "no_calibration" From 83d7a7807b51a43d4ad3d36bf48d554677fb663a Mon Sep 17 00:00:00 2001 From: Folfy Date: Tue, 3 Dec 2024 15:04:37 +0000 Subject: [PATCH 2/2] Workaround: Rounding functions bugged with more than one decimal place --- custom_components/better_thermostat/calibration.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/custom_components/better_thermostat/calibration.py b/custom_components/better_thermostat/calibration.py index 230f5eb1..4924dfe9 100644 --- a/custom_components/better_thermostat/calibration.py +++ b/custom_components/better_thermostat/calibration.py @@ -92,7 +92,7 @@ def calculate_calibration_local(self, entity_id) -> Union[float, None]: elif _calibration_mode == CalibrationMode.LINEAR_CALIBRATION: # offset setpoint by 0.5C for every 0.1C temperature difference to target (max +/-2C) _offset = (_cur_target_temp - _cur_external_temp) * 5 - _new_trv_calibration = min(max(-2, _offset), 2) + 0.26 + _new_trv_calibration = min(max(-2, _offset), 2) + 0.2 # Respecting tolerance in all calibration modes, delaying heat @@ -190,7 +190,7 @@ def calculate_calibration_setpoint(self, entity_id) -> Union[float, None]: elif _calibration_mode == CalibrationMode.LINEAR_CALIBRATION: # offset setpoint by 0.5C for every 0.1C temperature difference to target (max +/-2C) _offset = (_cur_target_temp - _cur_external_temp) * 5 - _calibrated_setpoint = _cur_target_temp + min(max(-2, _offset), 2) + 0.26 + _calibrated_setpoint = _cur_target_temp + min(max(-2, _offset), 2) + 0.2 if self.attr_hvac_action == HVACAction.IDLE: if _calibrated_setpoint - _cur_trv_temp_s > 0.0: