With all features + testu ok

This commit is contained in:
Jean-Marc Collin
2024-01-26 19:49:04 +00:00
parent 85dcac9530
commit de47a3ffe1
11 changed files with 213 additions and 31 deletions

View File

@@ -143,7 +143,7 @@ STEP_THERMOSTAT_CLIMATE = vol.Schema( # pylint: disable=invalid-name
mode="dropdown",
)
),
vol.Optional(CONF_AUTO_REGULATION_USE_INTERNAL_TEMP, default=False): cv.boolean,
vol.Optional(CONF_AUTO_REGULATION_USE_DEVICE_TEMP, default=False): cv.boolean,
}
)

View File

@@ -105,7 +105,7 @@ CONF_AUTO_REGULATION_STRONG = "auto_regulation_strong"
CONF_AUTO_REGULATION_EXPERT = "auto_regulation_expert"
CONF_AUTO_REGULATION_DTEMP = "auto_regulation_dtemp"
CONF_AUTO_REGULATION_PERIOD_MIN = "auto_regulation_periode_min"
CONF_AUTO_REGULATION_USE_INTERNAL_TEMP = "auto_regulation_use_internal_temp"
CONF_AUTO_REGULATION_USE_DEVICE_TEMP = "auto_regulation_use_device_temp"
CONF_INVERSE_SWITCH = "inverse_switch_command"
CONF_AUTO_FAN_MODE = "auto_fan_mode"
CONF_AUTO_FAN_NONE = "auto_fan_none"
@@ -256,7 +256,7 @@ ALL_CONF = (
CONF_AUTO_REGULATION_MODE,
CONF_AUTO_REGULATION_DTEMP,
CONF_AUTO_REGULATION_PERIOD_MIN,
CONF_AUTO_REGULATION_USE_INTERNAL_TEMP,
CONF_AUTO_REGULATION_USE_DEVICE_TEMP,
CONF_INVERSE_SWITCH,
CONF_AUTO_FAN_MODE,
CONF_USE_MAIN_CENTRAL_CONFIG,

View File

@@ -53,10 +53,10 @@ class PITemperatureRegulator:
self.accumulated_error = 0
def calculate_regulated_temperature(
self, internal_temp: float, external_temp: float
self, room_temp: float, external_temp: float
): # pylint: disable=unused-argument
"""Calculate a new target_temp given some temperature"""
if internal_temp is None:
if room_temp is None:
_LOGGER.warning(
"Temporarily skipping the self-regulation algorithm while the configured sensor for room temperature is unavailable"
)
@@ -68,7 +68,7 @@ class PITemperatureRegulator:
return self.target_temp
# Calculate the error factor (P)
error = self.target_temp - internal_temp
error = self.target_temp - room_temp
# Calculate the sum of error (I)
self.accumulated_error += error
@@ -83,22 +83,16 @@ class PITemperatureRegulator:
offset = self.kp * error + self.ki * self.accumulated_error
# Calculate the exterior offset
# For Maia tests - use the internal_temp vs external_temp and not target_temp - external_temp
offset_ext = self.k_ext * (internal_temp - external_temp)
offset_ext = self.k_ext * (room_temp - external_temp)
# Capping of offset_ext
# Capping of offset
total_offset = offset + offset_ext
total_offset = min(self.offset_max, max(-self.offset_max, total_offset))
# If temperature is near the target_temp, reset the accumulated_error
# Issue #199 - don't reset the accumulation error
# if abs(error) < self.stabilization_threshold:
# _LOGGER.debug("Stabilisation")
# self.accumulated_error = 0
result = round(self.target_temp + total_offset, 1)
_LOGGER.debug(
# TODO Change to debug after experimental
_LOGGER.info(
"PITemperatureRegulator - Error: %.2f accumulated_error: %.2f offset: %.2f offset_ext: %.2f target_tem: %.1f regulatedTemp: %.1f",
error,
self.accumulated_error,

View File

@@ -59,7 +59,7 @@
"auto_regulation_mode": "Self-regulation",
"auto_regulation_dtemp": "Regulation threshold",
"auto_regulation_periode_min": "Regulation minimal period",
"auto_regulation_use_internal_temp": "Use internal temperature of the underlying",
"auto_regulation_use_device_temp": "Use internal temperature of the underlying",
"inverse_switch_command": "Inverse switch command",
"auto_fan_mode": " Auto fan mode"
},
@@ -81,7 +81,7 @@
"auto_regulation_mode": "Auto adjustment of the target temperature",
"auto_regulation_dtemp": "The threshold in ° (or % for valve) under which the temperature change will not be sent",
"auto_regulation_periode_min": "Duration in minutes between two regulation update",
"auto_regulation_use_internal_temp": "Use the eventual internal temperature sensor of the underlying to speedup the self-regulation",
"auto_regulation_use_device_temp": "Use the eventual internal temperature sensor of the underlying to speedup the self-regulation",
"inverse_switch_command": "For switch with pilot wire and diode you may need to inverse the command",
"auto_fan_mode": " Automatically activate fan when huge heating/cooling is necessary"
}
@@ -296,7 +296,7 @@
"auto_regulation_mode": "Self-regulation",
"auto_regulation_dtemp": "Regulation threshold",
"auto_regulation_periode_min": "Regulation minimal period",
"auto_regulation_use_internal_temp": "Use internal temperature of the underlying",
"auto_regulation_use_device_temp": "Use internal temperature of the underlying",
"inverse_switch_command": "Inverse switch command",
"auto_fan_mode": " Auto fan mode"
},
@@ -318,7 +318,7 @@
"auto_regulation_mode": "Auto adjustment of the target temperature",
"auto_regulation_dtemp": "The threshold in ° (or % for valve) under which the temperature change will not be sent",
"auto_regulation_periode_min": "Duration in minutes between two regulation update",
"auto_regulation_use_internal_temp": "Use the eventual internal temperature sensor of the underlying to speedup the self-regulation",
"auto_regulation_use_device_temp": "Use the eventual internal temperature sensor of the underlying to speedup the self-regulation",
"inverse_switch_command": "For switch with pilot wire and diode you may need to invert the command",
"auto_fan_mode": " Automatically activate fan when huge heating/cooling is necessary"
}

View File

@@ -36,6 +36,7 @@ from .const import (
CONF_AUTO_REGULATION_EXPERT,
CONF_AUTO_REGULATION_DTEMP,
CONF_AUTO_REGULATION_PERIOD_MIN,
CONF_AUTO_REGULATION_USE_DEVICE_TEMP,
CONF_AUTO_FAN_MODE,
CONF_AUTO_FAN_NONE,
CONF_AUTO_FAN_LOW,
@@ -90,6 +91,7 @@ class ThermostatOverClimate(BaseThermostat):
"current_auto_fan_mode",
"auto_activated_fan_mode",
"auto_deactivated_fan_mode",
"auto_regulation_use_device_temp",
}
)
)
@@ -284,6 +286,10 @@ class ThermostatOverClimate(BaseThermostat):
else CONF_AUTO_FAN_NONE
)
self._auto_regulation_use_device_temp = config_entry.get(
CONF_AUTO_REGULATION_USE_DEVICE_TEMP, False
)
def choose_auto_regulation_mode(self, auto_regulation_mode: str):
"""Choose or change the regulation mode"""
self._auto_regulation_mode = auto_regulation_mode
@@ -492,6 +498,10 @@ class ThermostatOverClimate(BaseThermostat):
"auto_deactivated_fan_mode"
] = self._auto_deactivated_fan_mode
self._attr_extra_state_attributes[
"auto_regulation_use_device_temp"
] = self.auto_regulation_use_device_temp
self.async_write_ha_state()
_LOGGER.debug(
"%s - Calling update_custom_attributes: %s",
@@ -770,6 +780,11 @@ class ThermostatOverClimate(BaseThermostat):
"""Get the auto fan mode"""
return self._auto_fan_mode
@property
def auto_regulation_use_device_temp(self) -> bool | None:
"""Returns the value of parameter auto_regulation_use_device_temp"""
return self._auto_regulation_use_device_temp
@property
def regulated_target_temp(self) -> float | None:
"""Get the regulated target temperature"""

View File

@@ -59,7 +59,7 @@
"auto_regulation_mode": "Self-regulation",
"auto_regulation_dtemp": "Regulation threshold",
"auto_regulation_periode_min": "Regulation minimal period",
"auto_regulation_use_internal_temp": "Use internal temperature of the underlying",
"auto_regulation_use_device_temp": "Use internal temperature of the underlying",
"inverse_switch_command": "Inverse switch command",
"auto_fan_mode": " Auto fan mode"
},
@@ -81,7 +81,7 @@
"auto_regulation_mode": "Auto adjustment of the target temperature",
"auto_regulation_dtemp": "The threshold in ° (or % for valve) under which the temperature change will not be sent",
"auto_regulation_periode_min": "Duration in minutes between two regulation update",
"auto_regulation_use_internal_temp": "Use the eventual internal temperature sensor of the underlying to speedup the self-regulation",
"auto_regulation_use_device_temp": "Use the eventual internal temperature sensor of the underlying to speedup the self-regulation",
"inverse_switch_command": "For switch with pilot wire and diode you may need to inverse the command",
"auto_fan_mode": " Automatically activate fan when huge heating/cooling is necessary"
}
@@ -296,7 +296,7 @@
"auto_regulation_mode": "Self-regulation",
"auto_regulation_dtemp": "Regulation threshold",
"auto_regulation_periode_min": "Regulation minimal period",
"auto_regulation_use_internal_temp": "Use internal temperature of the underlying",
"auto_regulation_use_device_temp": "Use internal temperature of the underlying",
"inverse_switch_command": "Inverse switch command",
"auto_fan_mode": " Auto fan mode"
},
@@ -318,7 +318,7 @@
"auto_regulation_mode": "Auto adjustment of the target temperature",
"auto_regulation_dtemp": "The threshold in ° (or % for valve) under which the temperature change will not be sent",
"auto_regulation_periode_min": "Duration in minutes between two regulation update",
"auto_regulation_use_internal_temp": "Use the eventual internal temperature sensor of the underlying to speedup the self-regulation",
"auto_regulation_use_device_temp": "Use the eventual internal temperature sensor of the underlying to speedup the self-regulation",
"inverse_switch_command": "For switch with pilot wire and diode you may need to invert the command",
"auto_fan_mode": " Automatically activate fan when huge heating/cooling is necessary"
}

View File

@@ -59,7 +59,7 @@
"auto_regulation_mode": "Auto-régulation",
"auto_regulation_dtemp": "Seuil de régulation",
"auto_regulation_periode_min": "Période minimale de régulation",
"auto_regulation_use_internal_temp": "Utiliser la température interne du sous-jacent",
"auto_regulation_use_device_temp": "Utiliser la température interne du sous-jacent",
"inverse_switch_command": "Inverser la commande",
"auto_fan_mode": " Auto ventilation mode"
},
@@ -81,7 +81,7 @@
"auto_regulation_mode": "Ajustement automatique de la température cible",
"auto_regulation_dtemp": "Le seuil en ° (ou % pour les valves) en-dessous duquel la régulation ne sera pas envoyée",
"auto_regulation_periode_min": "La durée en minutes entre deux mise à jour faites par la régulation",
"auto_regulation_use_internal_temp": "Utiliser la temperature interne du sous-jacent pour accélérer l'auto-régulation",
"auto_regulation_use_device_temp": "Utiliser la temperature interne du sous-jacent pour accélérer l'auto-régulation",
"inverse_switch_command": "Inverse la commande du switch pour une installation avec fil pilote et diode",
"auto_fan_mode": "Active la ventilation automatiquement en cas d'écart important"
}
@@ -308,7 +308,7 @@
"auto_regulation_mode": "Auto-regulation",
"auto_regulation_dtemp": "Seuil de régulation",
"auto_regulation_periode_min": "Période minimale de régulation",
"auto_regulation_use_internal_temp": "Utiliser la température interne du sous-jacent",
"auto_regulation_use_device_temp": "Utiliser la température interne du sous-jacent",
"inverse_switch_command": "Inverser la commande",
"auto_fan_mode": " Auto fan mode"
},
@@ -330,7 +330,7 @@
"auto_regulation_mode": "Ajustement automatique de la consigne",
"auto_regulation_dtemp": "Le seuil en ° (ou % pour les valves) en-dessous duquel la régulation ne sera pas envoyée",
"auto_regulation_periode_min": "La durée en minutes entre deux mise à jour faites par la régulation",
"auto_regulation_use_internal_temp": "Utiliser la temperature interne du sous-jacent pour accélérer l'auto-régulation",
"auto_regulation_use_device_temp": "Utiliser la temperature interne du sous-jacent pour accélérer l'auto-régulation",
"inverse_switch_command": "Inverse la commande du switch pour une installation avec fil pilote et diode",
"auto_fan_mode": "Active la ventilation automatiquement en cas d'écart important"
}

View File

@@ -567,9 +567,24 @@ class UnderlyingClimate(UnderlyingEntity):
"""Set the target temperature"""
if not self.is_initialized:
return
# issue 348 - use device temperature if configured as offset
offset_temp = 0
if self._thermostat.auto_regulation_use_device_temp and hasattr(
self._underlying_climate, "current_temperature"
):
device_temp = self._underlying_climate.current_temperature
offset_temp = device_temp - self._thermostat.current_temperature
_LOGGER.debug(
"%s - the device offset temp for regulation is %.2f - internal temp is %.2f",
self,
offset_temp,
device_temp,
)
data = {
ATTR_ENTITY_ID: self._entity_id,
"temperature": self.cap_sent_value(temperature),
"temperature": self.cap_sent_value(temperature + offset_temp),
"target_temp_high": max_temp,
"target_temp_low": min_temp,
}