Skip to content

Commit

Permalink
Do no reset the accumulated error after temp change. Lower the coefs
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Marc Collin committed Oct 31, 2023
1 parent 3c497d2 commit 663a138
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
15 changes: 13 additions & 2 deletions custom_components/versatile_thermostat/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,23 @@ class RegulationParamLight:
""" Light parameters for regulation"""
kp:float = 0.2
ki:float = 0.05
k_ext:float = 0.05
offset_max:float = 1.5
stabilization_threshold:float = 0.1
accumulated_error_threshold:float = 10


class RegulationParamMedium:
""" Light parameters for regulation"""
kp:float = 0.3
ki:float = 0.05
k_ext:float = 0.1
offset_max:float = 2
stabilization_threshold:float = 0.1
accumulated_error_threshold:float = 20


class RegulationParamMedium:
class RegulationParamStrong:
""" Medium parameters for regulation"""
kp:float = 0.4
ki:float = 0.08
Expand All @@ -242,7 +252,8 @@ class RegulationParamMedium:
stabilization_threshold:float = 0.1
accumulated_error_threshold:float = 25

class RegulationParamStrong:
# Not used now
class RegulationParamVeryStrong:
""" Strong parameters for regulation"""
kp:float = 0.6
ki:float = 0.1
Expand Down
3 changes: 2 additions & 1 deletion custom_components/versatile_thermostat/pi_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def __init__(self, target_temp: float, kp: float, ki: float, k_ext: float, offse
def set_target_temp(self, target_temp):
""" Set the new target_temp"""
self.target_temp = target_temp
self.accumulated_error = 0
# Do not reset the accumulated error
# self.accumulated_error = 0

def calculate_regulated_temperature(self, internal_temp: float, external_temp:float): # pylint: disable=unused-argument
""" Calculate a new target_temp given some temperature"""
Expand Down
6 changes: 3 additions & 3 deletions tests/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
PRESET_AWAY_SUFFIX,
CONF_CLIMATE,
CONF_AUTO_REGULATION_MODE,
CONF_AUTO_REGULATION_MEDIUM,
CONF_AUTO_REGULATION_STRONG,
CONF_AUTO_REGULATION_NONE,
CONF_AUTO_REGULATION_DTEMP,
CONF_AUTO_REGULATION_PERIOD_MIN
Expand Down Expand Up @@ -127,7 +127,7 @@
MOCK_TH_OVER_CLIMATE_TYPE_CONFIG = {
CONF_CLIMATE: "climate.mock_climate",
CONF_AC_MODE: False,
CONF_AUTO_REGULATION_MODE: CONF_AUTO_REGULATION_MEDIUM,
CONF_AUTO_REGULATION_MODE: CONF_AUTO_REGULATION_STRONG,
CONF_AUTO_REGULATION_DTEMP: 0.5,
CONF_AUTO_REGULATION_PERIOD_MIN: 2
}
Expand All @@ -141,7 +141,7 @@
MOCK_TH_OVER_CLIMATE_TYPE_AC_CONFIG = {
CONF_CLIMATE: "climate.mock_climate",
CONF_AC_MODE: True,
CONF_AUTO_REGULATION_MODE: CONF_AUTO_REGULATION_MEDIUM,
CONF_AUTO_REGULATION_MODE: CONF_AUTO_REGULATION_STRONG,
CONF_AUTO_REGULATION_DTEMP: 0.5,
CONF_AUTO_REGULATION_PERIOD_MIN: 1
}
Expand Down
4 changes: 2 additions & 2 deletions tests/test_auto_regulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def find_my_entity(entity_id) -> ClimateEntity:
):
await entity.async_set_temperature(temperature=17)
assert entity.regulated_target_temp > entity.target_temperature
assert entity.regulated_target_temp == 18+0.5 # In medium we could go up to +3 degre. 0.7 without round_to_nearest
assert entity.regulated_target_temp == 18+1 # In strong we could go up to +3 degre. 0.7 without round_to_nearest
old_regulated_temp = entity.regulated_target_temp

# change temperature so that dtemp < 0.5 and time is > period_min (+ 3min)
Expand All @@ -331,4 +331,4 @@ def find_my_entity(entity_id) -> ClimateEntity:
# the regulated should have been done
assert entity.regulated_target_temp != old_regulated_temp
assert entity.regulated_target_temp > entity.target_temperature
assert entity.regulated_target_temp == 17 + 0.5 # 0.7 without round_to_nearest
assert entity.regulated_target_temp == 17 + 1 # 0.7 without round_to_nearest

0 comments on commit 663a138

Please sign in to comment.