Skip to content

Commit

Permalink
Add minimal_deactivation_delay (#905)
Browse files Browse the repository at this point in the history
* Add minimal_deactivation_delay

In some cases users may want to keep the equipment on if it will deactivate for a short time.
This could help reduce wear on gas boilers.

* fix(prop_algorithm): correct the log message for minimal_deactivation_delay

* fix(translations): correct the translations for minimal_deactivation_delay
  • Loading branch information
tmad authored Feb 12, 2025
1 parent 15a4810 commit bb4d3a5
Show file tree
Hide file tree
Showing 38 changed files with 270 additions and 3 deletions.
3 changes: 3 additions & 0 deletions custom_components/versatile_thermostat/base_thermostat.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class BaseThermostat(ClimateEntity, RestoreEntity, Generic[T]):
"last_temperature_datetime",
"last_ext_temperature_datetime",
"minimal_activation_delay_sec",
"minimal_deactivation_delay_sec",
"last_update_datetime",
"timezone",
"temperature_unit",
Expand Down Expand Up @@ -370,6 +371,7 @@ def post_init(self, config_entry: ConfigData):
self._tpi_coef_ext = 0

self._minimal_activation_delay = entry_infos.get(CONF_MINIMAL_ACTIVATION_DELAY)
self._minimal_deactivation_delay = entry_infos.get(CONF_MINIMAL_DEACTIVATION_DELAY)
self._last_temperature_measure = self.now
self._last_ext_temperature_measure = self.now

Expand Down Expand Up @@ -1684,6 +1686,7 @@ def update_custom_attributes(self):
self._current_tz
).isoformat(),
"minimal_activation_delay_sec": self._minimal_activation_delay,
"minimal_deactivation_delay_sec": self._minimal_deactivation_delay,
ATTR_TOTAL_ENERGY: self.total_energy,
"last_update_datetime": self.now.isoformat(),
"timezone": str(self._current_tz),
Expand Down
6 changes: 6 additions & 0 deletions custom_components/versatile_thermostat/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,12 @@ def check_config_complete(self, infos) -> bool:
):
return False

if (
infos.get(CONF_USE_ADVANCED_CENTRAL_CONFIG, False) is False
and infos.get(CONF_MINIMAL_DEACTIVATION_DELAY, -1) == -1
):
return False

if (
infos.get(CONF_PROP_FUNCTION, None) == PROPORTIONAL_FUNCTION_TPI
and infos.get(CONF_USE_TPI_CENTRAL_CONFIG, False) is False
Expand Down
1 change: 1 addition & 0 deletions custom_components/versatile_thermostat/config_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@
STEP_CENTRAL_ADVANCED_DATA_SCHEMA = vol.Schema( # pylint: disable=invalid-name
{
vol.Required(CONF_MINIMAL_ACTIVATION_DELAY, default=10): cv.positive_int,
vol.Required(CONF_MINIMAL_DEACTIVATION_DELAY, default=0): cv.positive_int,
vol.Required(CONF_SAFETY_DELAY_MIN, default=60): cv.positive_int,
vol.Required(
CONF_SAFETY_MIN_ON_PERCENT,
Expand Down
2 changes: 2 additions & 0 deletions custom_components/versatile_thermostat/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
CONF_PRESENCE_SENSOR = "presence_sensor_entity_id"
CONF_PRESET_POWER = "power_temp"
CONF_MINIMAL_ACTIVATION_DELAY = "minimal_activation_delay"
CONF_MINIMAL_DEACTIVATION_DELAY = "minimal_deactivation_delay"
CONF_TEMP_MIN = "temp_min"
CONF_TEMP_MAX = "temp_max"
CONF_SAFETY_DELAY_MIN = "safety_delay_min"
Expand Down Expand Up @@ -289,6 +290,7 @@
CONF_TPI_COEF_EXT,
CONF_PRESENCE_SENSOR,
CONF_MINIMAL_ACTIVATION_DELAY,
CONF_MINIMAL_DEACTIVATION_DELAY,
CONF_TEMP_MIN,
CONF_TEMP_MAX,
CONF_SAFETY_DELAY_MIN,
Expand Down
21 changes: 19 additions & 2 deletions custom_components/versatile_thermostat/prop_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,20 @@ def __init__(
tpi_coef_ext,
cycle_min: int,
minimal_activation_delay: int,
minimal_deactivation_delay: int,
vtherm_entity_id: str = None,
max_on_percent: float = None,
) -> None:
"""Initialisation of the Proportional Algorithm"""
_LOGGER.debug(
"%s - Creation new PropAlgorithm function_type: %s, tpi_coef_int: %s, tpi_coef_ext: %s, cycle_min:%d, minimal_activation_delay:%d", # pylint: disable=line-too-long
"%s - Creation new PropAlgorithm function_type: %s, tpi_coef_int: %s, tpi_coef_ext: %s, cycle_min:%d, minimal_activation_delay:%d, minimal_deactivation_delay:%d", # pylint: disable=line-too-long
vtherm_entity_id,
function_type,
tpi_coef_int,
tpi_coef_ext,
cycle_min,
minimal_activation_delay,
minimal_deactivation_delay,
)

# Issue 506 - check parameters
Expand All @@ -51,17 +53,19 @@ def __init__(
or not is_number(tpi_coef_ext)
or not is_number(cycle_min)
or not is_number(minimal_activation_delay)
or not is_number(minimal_deactivation_delay)
or function_type != PROPORTIONAL_FUNCTION_TPI
):
_LOGGER.error(
"%s - configuration is wrong. function_type=%s, entity_id is %s, tpi_coef_int is %s, tpi_coef_ext is %s, cycle_min is %s, minimal_activation_delay is %s",
"%s - configuration is wrong. function_type=%s, entity_id is %s, tpi_coef_int is %s, tpi_coef_ext is %s, cycle_min is %s, minimal_activation_delay is %s, minimal_deactivation_delay is %s",
vtherm_entity_id,
function_type,
vtherm_entity_id,
tpi_coef_int,
tpi_coef_ext,
cycle_min,
minimal_activation_delay,
minimal_deactivation_delay,
)
raise TypeError(
"TPI parameters are not set correctly. VTherm will not work as expected. Please reconfigure it correctly. See previous log for values"
Expand All @@ -73,6 +77,7 @@ def __init__(
self._tpi_coef_ext = tpi_coef_ext
self._cycle_min = cycle_min
self._minimal_activation_delay = minimal_activation_delay
self._minimal_deactivation_delay = minimal_deactivation_delay
self._on_percent = 0
self._calculated_on_percent = 0
self._on_time_sec = 0
Expand Down Expand Up @@ -187,6 +192,18 @@ def _calculate_internal(self):

self._off_time_sec = self._cycle_min * 60 - self._on_time_sec

# Do not stop heating when off time less than xx sec
if self._off_time_sec < self._minimal_deactivation_delay:
if self._off_time_sec > 0:
_LOGGER.info(
"%s - Force 100% heating cycle since the off duration (%f) is shorter than minimal_deactivation_delay (%f)",
self._vtherm_entity_id,
self._off_time_sec,
self._minimal_deactivation_delay,
)
self._on_time_sec = self._cycle_min * 60
self._off_time_sec = 0

def set_safety(self, default_on_percent: float):
"""Set a default value for on_percent (used for safety mode)"""
_LOGGER.info(
Expand Down
4 changes: 4 additions & 0 deletions custom_components/versatile_thermostat/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,15 @@
"description": "Configuration of advanced parameters. Leave the default values if you don't know what you are doing.\nThese parameters can lead to very poor temperature control or bad power regulation&nbsp;[![?](https://img.icons8.com/color/18/help.png)](https://github.com/jmcollin78/versatile_thermostat/blob/main/documentation/en/feature-advanced.md)",
"data": {
"minimal_activation_delay": "Minimum activation delay",
"minimal_deactivation_delay": "Minimum deactivation delay",
"safety_delay_min": "Safety delay (in minutes)",
"safety_min_on_percent": "Minimum power percent to enable safety mode",
"safety_default_on_percent": "Power percent to use in safety mode",
"use_advanced_central_config": "Use central advanced configuration"
},
"data_description": {
"minimal_activation_delay": "Delay in seconds under which the equipment will not be activated",
"minimal_deactivation_delay": "Delay in seconds under which the equipment will be kept active",
"safety_delay_min": "Maximum allowed delay in minutes between two temperature measurements. Above this delay the thermostat will turn to a safety off state",
"safety_min_on_percent": "Minimum heating percent value for safety preset activation. Below this amount of power percent the thermostat won't go into safety preset",
"safety_default_on_percent": "The default heating power percent value in safety preset. Set to 0 to switch off heater in safety preset",
Expand Down Expand Up @@ -451,13 +453,15 @@
"description": "Configuration of advanced parameters. Leave the default values if you don't know what you are doing.\nThese parameters can lead to very poor temperature control or bad power regulation&nbsp;[![?](https://img.icons8.com/color/18/help.png)](https://github.com/jmcollin78/versatile_thermostat/blob/main/documentation/en/feature-advanced.md)",
"data": {
"minimal_activation_delay": "Minimum activation delay",
"minimal_deactivation_delay": "Minimum deactivation delay",
"safety_delay_min": "Safety delay (in minutes)",
"safety_min_on_percent": "Minimum power percent to enable safety mode",
"safety_default_on_percent": "Power percent to use in safety mode",
"use_advanced_central_config": "Use central advanced configuration"
},
"data_description": {
"minimal_activation_delay": "Delay in seconds under which the equipment will not be activated",
"minimal_deactivation_delay": "Delay in seconds under which the equipment will be kept active",
"safety_delay_min": "Maximum allowed delay in minutes between two temperature measurements. Above this delay the thermostat will turn to a safety off state",
"safety_min_on_percent": "Minimum heating percent value for safety preset activation. Below this amount of power percent the thermostat won't go into safety preset",
"safety_default_on_percent": "The default heating power percent value in safety preset. Set to 0 to switch off heater in safety preset",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def post_init(self, config_entry: ConfigData):
self._tpi_coef_ext,
self._cycle_min,
self._minimal_activation_delay,
self._minimal_deactivation_delay,
self.name,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def post_init(self, config_entry: ConfigData):
self._tpi_coef_ext,
self._cycle_min,
self._minimal_activation_delay,
self._minimal_deactivation_delay,
self.name,
max_on_percent=self._max_on_percent,
)
Expand Down
1 change: 1 addition & 0 deletions custom_components/versatile_thermostat/thermostat_valve.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def post_init(self, config_entry: ConfigData):
self._tpi_coef_ext,
self._cycle_min,
self._minimal_activation_delay,
self._minimal_deactivation_delay,
self.name,
max_on_percent=self._max_on_percent,
)
Expand Down
2 changes: 2 additions & 0 deletions custom_components/versatile_thermostat/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,15 @@
"description": "Configuration of advanced parameters. Leave the default values if you don't know what you are doing.\nThese parameters can lead to very poor temperature control or bad power regulation&nbsp;[![?](https://img.icons8.com/color/18/help.png)](https://github.com/jmcollin78/versatile_thermostat/blob/main/documentation/en/feature-advanced.md)",
"data": {
"minimal_activation_delay": "Minimum activation delay",
"minimal_deactivation_delay": "Minimal deactivation delay",
"safety_delay_min": "Safety delay (in minutes)",
"safety_min_on_percent": "Minimum power percent to enable safety mode",
"safety_default_on_percent": "Power percent to use in safety mode",
"use_advanced_central_config": "Use central advanced configuration"
},
"data_description": {
"minimal_activation_delay": "Delay in seconds under which the equipment will not be activated",
"minimal_deactivation_delay": "Delay in seconds under which the equipment will be kept active",
"safety_delay_min": "Maximum allowed delay in minutes between two temperature measurements. Above this delay the thermostat will turn to a safety off state",
"safety_min_on_percent": "Minimum heating percent value for safety preset activation. Below this amount of power percent the thermostat won't go into safety preset",
"safety_default_on_percent": "The default heating power percent value in safety preset. Set to 0 to switch off heater in safety preset",
Expand Down
4 changes: 4 additions & 0 deletions custom_components/versatile_thermostat/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,15 @@
"description": "Configuration des paramètres avancés. Laissez les valeurs par défaut si vous ne savez pas ce que vous faites.\nCes paramètres peuvent induire des mauvais comportements du thermostat&nbsp;[![?](https://img.icons8.com/color/18/help.png)](https://github.com/jmcollin78/versatile_thermostat/blob/main/documentation/fr/feature-advanced.md)",
"data": {
"minimal_activation_delay": "Délai minimal d'activation",
"minimal_deactivation_delay": "Minimal deactivation delay",
"safety_delay_min": "Délai maximal entre 2 mesures de températures",
"safety_min_on_percent": "Pourcentage minimal de puissance",
"safety_default_on_percent": "Pourcentage de puissance a utiliser en mode securité",
"use_advanced_central_config": "Utiliser la configuration centrale avancée"
},
"data_description": {
"minimal_activation_delay": "Délai en secondes en-dessous duquel l'équipement ne sera pas activé",
"minimal_deactivation_delay": "Delay in seconds under which the equipment will be kept active",
"safety_delay_min": "Délai maximal autorisé en minutes entre 2 mesures de températures. Au-dessus de ce délai, le thermostat se mettra en position de sécurité",
"safety_min_on_percent": "Seuil minimal de pourcentage de chauffage en-dessous duquel le préréglage sécurité ne sera jamais activé",
"safety_default_on_percent": "Valeur par défaut pour le pourcentage de chauffage en mode sécurité. Mettre 0 pour éteindre le radiateur en mode sécurité",
Expand Down Expand Up @@ -448,13 +450,15 @@
"description": "Configuration des paramètres avancés. Laissez les valeurs par défaut si vous ne savez pas ce que vous faites.\nCes paramètres peuvent induire des mauvais comportements du thermostat&nbsp;[![?](https://img.icons8.com/color/18/help.png)](https://github.com/jmcollin78/versatile_thermostat/blob/main/documentation/fr/feature-advanced.md)",
"data": {
"minimal_activation_delay": "Délai minimal d'activation",
"minimal_deactivation_delay": "Minimal deactivation delay",
"safety_delay_min": "Délai maximal entre 2 mesures de températures",
"safety_min_on_percent": "Pourcentage minimal de puissance",
"safety_default_on_percent": "Pourcentage de puissance a utiliser en mode securité",
"use_advanced_central_config": "Utiliser la configuration centrale avancée"
},
"data_description": {
"minimal_activation_delay": "Délai en seondes en-dessous duquel l'équipement ne sera pas activé",
"minimal_deactivation_delay": "Delay in seconds under which the equipment will be kept active",
"safety_delay_min": "Délai maximal autorisé en minutes entre 2 mesures de températures. Au-dessus de ce délai, le thermostat se mettra en position de sécurité",
"safety_min_on_percent": "Seuil minimal de pourcentage de chauffage en-dessous duquel le préréglage sécurité ne sera jamais activé",
"safety_default_on_percent": "Valeur par défaut pour le pourcentage de chauffage en mode sécurité. Mettre 0 pour éteindre le radiateur en mode sécurité",
Expand Down
4 changes: 4 additions & 0 deletions documentation/en/feature-advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ The advanced configuration form looks like this:

The first delay (`minimal_activation_delay_sec`) in seconds is the minimum acceptable delay to turn on the heating. If the calculated activation time is shorter than this value, the heating remains off. This parameter only applies to _VTherm_ with cyclic triggering `over_switch`. If the activation time is too short, rapid switching will not allow the device to heat up properly.

### Minimum Deactivation Delay

The delay (`minimal_deactivation_delay_sec`) in seconds is the minimum acceptable delay to turn off the heating. If the calculated deactivation time is shorter than this value, the heating remains on.

### Safety Mode

The second delay (`safety_delay_min`) is the maximum time between two temperature measurements before the _VTherm_ switches to Safety Mode.
Expand Down
2 changes: 2 additions & 0 deletions documentation/en/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
| ``power_temp`` | Temperature during load shedding | X | X | X | X |
| ``presence_sensor_entity_id`` | Presence sensor entity id (true if someone is present) | X | X | X | - |
| ``minimal_activation_delay`` | Minimum activation delay | X | - | - | X |
| ``minimal_deactivation_delay`` | Minimum deactivation delay | X | - | - | X |
| ``safety_delay_min`` | Maximum delay between two temperature measurements | X | - | X | X |
| ``safety_min_on_percent`` | Minimum power percentage to enter security mode | X | - | X | X |
| ``auto_regulation_mode`` | Auto-regulation mode | - | X | - | - |
Expand Down Expand Up @@ -259,6 +260,7 @@ The custom attributes are as follows:
| ``last_ext_temperature_datetime`` | The date and time in ISO8866 format of the last external temperature reception |
| ``security_state`` | The security state. True or false |
| ``minimal_activation_delay_sec`` | The minimal activation delay in seconds |
| ``minimal_deactivation_delay_sec``| The minimal deactivation delay in seconds |
| ``last_update_datetime`` | The date and time in ISO8866 format of this state |
| ``friendly_name`` | The name of the thermostat |
| ``supported_features`` | A combination of all features supported by this thermostat. See the official climate integration documentation for more information |
Expand Down
2 changes: 2 additions & 0 deletions tests/commons.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@
CONF_PRESENCE_SENSOR: "binary_sensor.mock_presence_sensor",
CONF_PRESET_POWER: 14,
CONF_MINIMAL_ACTIVATION_DELAY: 11,
CONF_MINIMAL_DEACTIVATION_DELAY: 0,
CONF_SAFETY_DELAY_MIN: 61,
CONF_SAFETY_MIN_ON_PERCENT: 0.5,
CONF_SAFETY_DEFAULT_ON_PERCENT: 0.2,
Expand Down Expand Up @@ -222,6 +223,7 @@
CONF_MAX_POWER_SENSOR: "sensor.mock_max_power_sensor",
CONF_PRESET_POWER: 14,
CONF_MINIMAL_ACTIVATION_DELAY: 11,
CONF_MINIMAL_DEACTIVATION_DELAY: 0,
CONF_SAFETY_DELAY_MIN: 61,
CONF_SAFETY_MIN_ON_PERCENT: 0.5,
CONF_SAFETY_DEFAULT_ON_PERCENT: 0.2,
Expand Down
1 change: 1 addition & 0 deletions tests/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@

MOCK_ADVANCED_CONFIG = {
CONF_MINIMAL_ACTIVATION_DELAY: 10,
CONF_MINIMAL_DEACTIVATION_DELAY: 0,
CONF_SAFETY_DELAY_MIN: 5,
CONF_SAFETY_MIN_ON_PERCENT: 0.4,
CONF_SAFETY_DEFAULT_ON_PERCENT: 0.3,
Expand Down
Loading

0 comments on commit bb4d3a5

Please sign in to comment.