Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/linear compensation (proportional controller mode) #1522

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions custom_components/better_thermostat/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,18 @@ def _convert_to_float(value):
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.2


# Respecting tolerance in all calibration modes, delaying heat
if self.attr_hvac_action == HVACAction.IDLE:
Expand Down Expand Up @@ -200,14 +204,17 @@ def calculate_calibration_setpoint(self, entity_id) -> 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.2

if self.attr_hvac_action == HVACAction.IDLE:
if _calibrated_setpoint - _cur_trv_temp_s > 0.0:
Expand Down
3 changes: 3 additions & 0 deletions custom_components/better_thermostat/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
),
Expand Down
6 changes: 3 additions & 3 deletions custom_components/better_thermostat/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
"no_off_system_mode": "If your TRV doesn't support the 'off' mode, enable this to use target temperature 5°C instead"
},
"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": "How the calibration is 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": "How the calibration is applied on the TRV\n***Target Temperature Based***: Apply the calibration to the target temperature.\n***Offset Based***: Apply the calibration to the temperature offset."
"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.\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."
}
},
"confirm": {
Expand Down
2 changes: 1 addition & 1 deletion custom_components/better_thermostat/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
},
Expand Down
1 change: 1 addition & 0 deletions custom_components/better_thermostat/utils/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Loading