Compare commits

..

4 Commits

Author SHA1 Message Date
Jean-Marc Collin
e71d8dba86 Issue #820 - improve power shedding algorithm (#821)
* Issue #820 - improve power shedding algorithm

* Fix testu

* Release

* Fix cannot turn-off a VTherm in overpowering mode

---------

Co-authored-by: Jean-Marc Collin <jean-marc.collin-extern@renault.com>
2025-01-15 07:48:45 +01:00
Jean-Marc Collin
3e96247b63 Add messages 2025-01-14 09:15:14 +00:00
Jean-Marc Collin
05e31358a4 Documentation 2025-01-12 17:06:28 +00:00
Jean-Marc Collin
3af0318c2f Fix number selection for TPI in ConfigFlow 2025-01-12 16:22:01 +00:00
18 changed files with 189 additions and 28 deletions

View File

@@ -4,7 +4,10 @@ about: Create a report to help us improve
---
> Please read carefuly this instructions and fill this form before writing an issue. It helps me to help you.
# Read this carefully
> Please read carefully this instructions and fill this form before writing an issue. It helps me to help you.
> If you choose to not follow this template, you accept to have no answer from the author. The tag on the issue 'Template not respected' means you don't respect this template. Potentially, you will not have a relevant answer.
<!-- This template will allow the maintainer to be efficient and post the more accurante response as possible. There is many types / modes / configuration possible, so the analysis can be very tricky. If don't follow this template, your issue could be rejected without any message. Please help me to help you. -->
@@ -12,7 +15,7 @@ about: Create a report to help us improve
If you have a simple question or you are not sure this is an issue, don't open an issue but open a new discussion [here](https://github.com/jmcollin78/versatile_thermostat/discussions).
Check also in the [Troubleshooting](#troubleshooting) paragrah of the README if the aswer is not already given.
Check also in the [Troubleshooting] paragrah of the README if the aswer is not already given.
Issues not containing the minimum requirements will be closed:

View File

@@ -1031,6 +1031,10 @@ class BaseThermostat(ClimateEntity, RestoreEntity, Generic[T]):
return
# Remove eventual overpoering if we want to turn-off
if hvac_mode == HVACMode.OFF and self.power_manager.is_overpowering_detected:
await self.power_manager.set_overpowering(False)
self._hvac_mode = hvac_mode
# Delegate to all underlying

View File

@@ -232,7 +232,7 @@ STEP_TPI_DATA_SCHEMA = vol.Schema( # pylint: disable=invalid-name
STEP_CENTRAL_TPI_DATA_SCHEMA = vol.Schema( # pylint: disable=invalid-name
{
vol.Required(CONF_TPI_COEF_INT, default=0.6): selector.NumberSelector(selector.NumberSelectorConfig(min=0.0, max=1.0, step=0.01, mode=selector.NumberSelectorMode.BOX)),
vol.Required(CONF_TPI_COEF_EXT, default=0.01): selector.NumberSelector(selector.NumberSelectorConfig(min=0.0, max=1.0, mode=selector.NumberSelectorMode.BOX)),
vol.Required(CONF_TPI_COEF_EXT, default=0.01): selector.NumberSelector(selector.NumberSelectorConfig(min=0.0, max=1.0, step=0.001, mode=selector.NumberSelectorMode.BOX)),
}
)

View File

@@ -14,6 +14,6 @@
"quality_scale": "silver",
"requirements": [],
"ssdp": [],
"version": "7.1.3",
"version": "7.1.4",
"zeroconf": []
}

View File

@@ -499,7 +499,7 @@
"thermostat_central_config": "Configuration centrale",
"thermostat_over_switch": "Thermostat sur un switch",
"thermostat_over_climate": "Thermostat sur un autre thermostat",
"thermostat_over_valve": "Thermostat sur une valve"
"thermostat_over_valve": "Thermostat sur une vanne"
}
},
"auto_regulation_mode": {

View File

@@ -195,6 +195,16 @@ class UnderlyingEntity:
self._cancel_cycle()
await self.turn_off()
async def check_overpowering(self) -> bool:
"""Check that a underlying can be turned on, else
activate the overpowering state of the VTherm associated.
Returns True if the check is ok (no overpowering needed)"""
if not await self._thermostat.power_manager.check_power_available():
_LOGGER.debug("%s - overpowering is detected", self)
await self._thermostat.power_manager.set_overpowering(True)
return False
return True
class UnderlyingSwitch(UnderlyingEntity):
"""Represent a underlying switch"""
@@ -318,6 +328,10 @@ class UnderlyingSwitch(UnderlyingEntity):
"""Turn heater toggleable device on."""
self._keep_alive.cancel() # Cancel early to avoid a turn_on/turn_off race condition
_LOGGER.debug("%s - Starting underlying entity %s", self, self._entity_id)
if not await self.check_overpowering():
return False
command = SERVICE_TURN_ON if not self.is_inversed else SERVICE_TURN_OFF
domain = self._entity_id.split(".")[0]
try:
@@ -325,6 +339,7 @@ class UnderlyingSwitch(UnderlyingEntity):
data = {ATTR_ENTITY_ID: self._entity_id}
await self._hass.services.async_call(domain, command, data)
self._keep_alive.set_async_action(self._keep_alive_callback)
return True
except Exception:
self._keep_alive.cancel()
raise
@@ -414,10 +429,6 @@ class UnderlyingSwitch(UnderlyingEntity):
await self.turn_off()
return
# if await self._thermostat.power_manager.check_overpowering():
# _LOGGER.debug("%s - End of cycle (3)", self)
# return
# safety mode could have change the on_time percent
await self._thermostat.safety_manager.refresh_state()
time = self._on_time_sec
@@ -432,7 +443,8 @@ class UnderlyingSwitch(UnderlyingEntity):
time // 60,
time % 60,
)
await self.turn_on()
if not await self.turn_on():
return
else:
_LOGGER.debug("%s - No action on heater cause duration is 0", self)
self._async_cancel_cycle = self.call_later(
@@ -557,6 +569,10 @@ class UnderlyingClimate(UnderlyingEntity):
)
return False
# When turning on a climate, check that power is available
if hvac_mode in (HVACMode.HEAT, HVACMode.COOL) and not await self.check_overpowering():
return False
data = {ATTR_ENTITY_ID: self._entity_id, "hvac_mode": hvac_mode}
await self._hass.services.async_call(
CLIMATE_DOMAIN,

View File

@@ -11,6 +11,7 @@ The behavior of this feature is as follows:
1. When a new measurement of the home's power consumption or the maximum allowed power is received,
2. If the maximum power is exceeded, the central command will shed the load of all active devices starting with those closest to the setpoint. This continues until enough _VTherms_ are shed,
3. If there is available power reserve and some _VTherms_ are shed, the central command will re-enable as many devices as possible, starting with those furthest from the setpoint (at the time they were shed).
4. When a _VTherm_ starts, a check is performed to determine if the declared power is available. If not, the _VTherm_ is put into shed mode.
**WARNING:** This is **not a safety feature** but an optimization function to manage consumption at the expense of some heating degradation. Overconsumption is still possible depending on the frequency of your consumption sensor updates and the actual power used by your equipment. Always maintain a safety margin.

View File

@@ -25,7 +25,8 @@ The installation should look like this:
## Configuration
Click on the "Underlying Entities" option from the menu, and you will see this configuration page:
First, configure the main settings common to all _VTherms_ (see [main settings](base-attributes.md)).
Then, click on the "Underlying Entities" option from the menu, and you will see this configuration page:
![image](images/config-linked-entity2.png)

View File

@@ -26,7 +26,8 @@ The installation should look like this:
## Configuration
Click on the "Underlying Entities" option from the menu, and you will see this configuration page:
First, configure the main settings common to all _VTherms_ (see [main settings](base-attributes.md)).
Then, click on the "Underlying Entities" option from the menu, and you will see this configuration page:
![image](images/config-linked-entity.png)

View File

@@ -21,7 +21,8 @@ The installation should be similar to the `over_switch` VTherm setup, except tha
## Configuration
Click on the "Underlying Entities" option from the menu, and you will see this configuration page, you should add the `number` entities that will be controlled by VTherm. Only `number` or `input_number` entities are accepted.
First, configure the main settings common to all _VTherms_ (see [main settings](base-attributes.md)).
Then, click on the "Underlying Entities" option from the menu, and you will see this configuration page, you should add the `number` entities that will be controlled by VTherm. Only `number` or `input_number` entities are accepted.
![image](images/config-linked-entity3.png)

View File

@@ -10,6 +10,7 @@ Le comportement de cette fonction est le suivant :
1. lorsqu'une nouvelle mesure de la puissance consommée du logement ou de la puissance maximale autorisée est reçue,
2. si la puissance max est dépassée, la commande centrale va mettre en délestage tous les équipements actifs en commençant par ceux qui sont le plus près de la consigne. Il fait ça jusqu'à ce que suffisament de _VTherm_ soient délestés,
3. si une réserve de puissance est disponible et que des _VTherms_ sont délestés, alors la commande centrale va délester autant d'équipements que possible en commençant par les plus loin de la consigne (au moment où il a été mis en délestage),
4. au démarrage d'un _VTherm_, une vérification est effectuée pour savoir si la puissance déclarée est disponible. Si non, le _VTherm_ est passé en délestage.
ATTENTION: ce fonctionnement **n'est pas une fonction de sécurité** mais plus une fonction permettant une optimisation de la consommation au prix d'une dégradation du chauffage. Des dépassements sont possibles selon la fréquence de remontée de vos capteurs de consommation, la puissance réellement utilisée par votre équipements. Vous devez donc toujours garder une marge de sécurité.

View File

@@ -26,7 +26,8 @@ L'installation doit ressembler à ça :
## Configuration
Cliquer sur l'option de menu "Sous-jacents" et vous allez avoir cette page de configuration :
Configurez d'abord les paramètres principaux et communs à tous les _VTherm_ (cf. [paramètres principaux](base-attributes.md)).
Cliquez ensuite sur l'option de menu "Sous-jacents" et vous allez avoir cette page de configuration :
![image](images/config-linked-entity2.png)

View File

@@ -25,7 +25,8 @@ L'installation doit ressembler à ça :
## Configuration
Cliquer sur l'option de menu "Sous-jacents" et vous allez avoir cette page de configuration :
Configurez d'abord les paramètres principaux et communs à tous les _VTherm_ (cf. [paramètres principaux](base-attributes.md)).
Ensuite cliquez sur l'option de menu "Sous-jacents" et vous allez avoir cette page de configuration :
![image](images/config-linked-entity.png)

View File

@@ -22,11 +22,12 @@ L'installation doit ressembler à celle pour le VTherm `over_switch` sauf que l'
## Configuration
Cliquer sur l'option de menu "Sous-jacents" et vous allez avoir cette page de configuration. Vous mettez les entités `numnber` ou `input_number`qui vont être controllés par le VTherm :
Configurez d'abord les paramètres principaux et communs à tous les _VTherm_ (cf. [paramètres principaux](base-attributes.md)).
Ensuite cliquez sur l'option de menu "Sous-jacents" et vous allez avoir cette page de configuration. Vous mettez les entités `numnber` ou `input_number`qui vont être controllés par le VTherm :
![image](images/config-linked-entity3.png)
L'algorithme à utiliser est aujourd'hui limité à TPI est disponible. Voir [algorithme](#algorithme).
Il est possible de choisir un thermostat over valve qui commande une climatisation en cochant la case "AC Mode". Dans ce cas, seul le mode refroidissement sera visible.
Il est possible de choisir un thermostat `over-valve` qui commande une climatisation en cochant la case "AC Mode". Dans ce cas, seul le mode refroidissement sera visible.

View File

@@ -5,8 +5,8 @@ Ce thermostat peut piloter 3 types d'équipements :
2. une sonde de température pour la pièce (ou un input_number),
3. un capteur de température externe (pensez à l'intégration météo si vous n'en avez pas)
2. un autre thermostat qui a ses propres modes de fonctionnement (nommé ```thermostat_over_climate```). Pour ce type de thermostat la configuration minimale nécessite :
1. un équipement - comme une climatisation, une valve thermostatique - qui est pilotée par sa propre entity de type ```climate```,
3. un équipement qui peut prendre une valeur de 0 à 100% (nommée ```thermostat_over_valve```). A 0 le chauffage est coupé, 100% il est ouvert à fond. Ce type permet de piloter une valve thermostatique (cf. valve Shelly) qui expose une entité de type `number.` permetttant de piloter directement l'ouverture de la vanne. Versatile Thermostat régule la température de la pièce en jouant sur le pourcentage d'ouverture, à l'aide des capteurs de température intérieur et extérieur en utilisant l'algorithme TPI décrit ci-dessous.
1. un équipement - comme une climatisation, une vanne thermostatique - qui est pilotée par sa propre entity de type ```climate```,
3. un équipement qui peut prendre une valeur de 0 à 100% (nommée ```thermostat_over_valve```). A 0 le chauffage est coupé, 100% il est ouvert à fond. Ce type permet de piloter une vanne thermostatique (cf. TRV Shelly) qui expose une entité de type `number.` permetttant de piloter directement l'ouverture de la vanne. Versatile Thermostat régule la température de la pièce en jouant sur le pourcentage d'ouverture, à l'aide des capteurs de température intérieur et extérieur en utilisant l'algorithme TPI décrit ci-dessous.
Le type `over_climate` vous permet d'ajouter à votre équipement existant toutes les fonctionnalités apportées par VersatileThermostat. L'entité `climate` VersatileThermostat contrôlera votre entité climate sous-jacente, l'éteindra si les fenêtres sont ouvertes, la fera passer en mode Eco si personne n'est présent, etc. Voir [ici] (#pourquoi-un-nouveau-thermostat-implémentation). Pour ce type de thermostat, tous les cycles de chauffage sont contrôlés par l'entité climate sous-jacente et non par le thermostat polyvalent lui-même. Une fonction facultative d'auto-régulation permet au Versatile Thermostat d'ajuster la température donnée en consigne au sous-jacent afin d'atteindre la consigne.

View File

@@ -27,7 +27,7 @@
> * **Release 5.3** : Ajout d'une fonction de pilotage d'une chaudière centrale [#234](https://github.com/jmcollin78/versatile_thermostat/issues/234) - plus d'infos ici: [Le contrôle d'une chaudière centrale](#le-contrôle-dune-chaudière-centrale). Ajout de la possibilité de désactiver le mode sécurité pour le thermomètre extérieur [#343](https://github.com/jmcollin78/versatile_thermostat/issues/343)
> * **Release 5.2** : Ajout d'un `central_mode` permettant de piloter tous les VTherms de façon centralisée [#158](https://github.com/jmcollin78/versatile_thermostat/issues/158).
> * **Release 5.1** : Limitation des valeurs envoyées aux valves et au température envoyées au climate sous-jacent.
> * **Release 5.1** : Limitation des valeurs envoyées aux vannes et au température envoyées au climate sous-jacent.
> * **Release 5.0** : Ajout d'une configuration centrale permettant de mettre en commun les attributs qui peuvent l'être [#239](https://github.com/jmcollin78/versatile_thermostat/issues/239).
> * **Release 4.3** : Ajout d'un mode auto-fan pour le type `over_climate` permettant d'activer la ventilation si l'écart de température est important [#223](https://github.com/jmcollin78/versatile_thermostat/issues/223).
> * **Release 4.2** : Le calcul de la pente de la courbe de température se fait maintenant en °/heure et non plus en °/min [#242](https://github.com/jmcollin78/versatile_thermostat/issues/242). Correction de la détection automatique des ouvertures par l'ajout d'un lissage de la courbe de température .

View File

@@ -398,7 +398,8 @@ async def test_bug_407(
assert entity.target_temperature == 19
assert mock_service_call.call_count >= 1
# 3. if heater is stopped (is_device_active==False) and power is over max, then overpowering should be started
# 3. Evenif heater is stopped (is_device_active==False) and power is over max, then overpowering should be started
# due to check before start heating
side_effects.add_or_update_side_effect("sensor.the_power_sensor", State("sensor.the_power_sensor", 150))
with patch(
"homeassistant.core.ServiceRegistry.async_call"
@@ -413,18 +414,18 @@ async def test_bug_407(
now = now + timedelta(seconds=30)
VersatileThermostatAPI.get_vtherm_api()._set_now(now)
# change preset to Boost
# change preset to Comfort
await entity.async_set_preset_mode(PRESET_COMFORT)
# waits that the heater starts
# waits the eventual heater starts
await asyncio.sleep(0.1)
# simulate a refresh for central power (not necessary)
await do_central_power_refresh(hass)
# simulate a refresh for central power (not necessary because it is checked before start)
# await do_central_power_refresh(hass)
assert entity.power_manager.is_overpowering_detected is False
assert entity.power_manager.is_overpowering_detected is True
assert entity.hvac_mode is HVACMode.HEAT
assert entity.preset_mode is PRESET_COMFORT
assert entity.power_manager.overpowering_state is STATE_OFF
assert entity.preset_mode is PRESET_POWER
assert entity.power_manager.overpowering_state is STATE_ON
@pytest.mark.parametrize("expected_lingering_tasks", [True])

View File

@@ -825,3 +825,132 @@ async def test_power_management_energy_over_climate(
# Test the re-increment
entity.incremente_energy()
assert entity.total_energy == 2 * 100 * 3.0 / 60
@pytest.mark.parametrize("expected_lingering_tasks", [True])
@pytest.mark.parametrize("expected_lingering_timers", [True])
async def test_power_management_turn_off_while_shedding(hass: HomeAssistant, skip_hass_states_is_state, init_central_power_manager):
"""Test the Power management and that we can turn off a Vtherm that
is in overpowering state"""
temps = {
"eco": 17,
"comfort": 18,
"boost": 19,
}
entry = MockConfigEntry(
domain=DOMAIN,
title="TheOverSwitchMockName",
unique_id="uniqueId",
data={
CONF_NAME: "TheOverSwitchMockName",
CONF_THERMOSTAT_TYPE: CONF_THERMOSTAT_SWITCH,
CONF_TEMP_SENSOR: "sensor.mock_temp_sensor",
CONF_EXTERNAL_TEMP_SENSOR: "sensor.mock_ext_temp_sensor",
CONF_CYCLE_MIN: 5,
CONF_TEMP_MIN: 15,
CONF_TEMP_MAX: 30,
CONF_USE_WINDOW_FEATURE: False,
CONF_USE_MOTION_FEATURE: False,
CONF_USE_POWER_FEATURE: True,
CONF_USE_PRESENCE_FEATURE: False,
CONF_UNDERLYING_LIST: ["switch.mock_switch"],
CONF_PROP_FUNCTION: PROPORTIONAL_FUNCTION_TPI,
CONF_TPI_COEF_INT: 0.3,
CONF_TPI_COEF_EXT: 0.01,
CONF_MINIMAL_ACTIVATION_DELAY: 30,
CONF_SAFETY_DELAY_MIN: 5,
CONF_SAFETY_MIN_ON_PERCENT: 0.3,
CONF_DEVICE_POWER: 100,
CONF_PRESET_POWER: 12,
},
)
entity: ThermostatOverSwitch = await create_thermostat(hass, entry, "climate.theoverswitchmockname", temps)
assert entity
now: datetime = NowClass.get_now(hass)
VersatileThermostatAPI.get_vtherm_api()._set_now(now)
tpi_algo = entity._prop_algorithm
assert tpi_algo
await entity.async_set_hvac_mode(HVACMode.HEAT)
await entity.async_set_preset_mode(PRESET_BOOST)
assert entity.hvac_mode is HVACMode.HEAT
assert entity.preset_mode is PRESET_BOOST
assert entity.power_manager.overpowering_state is STATE_UNKNOWN
assert entity.target_temperature == 19
# make the heater heats
await send_temperature_change_event(entity, 15, now)
await send_ext_temperature_change_event(entity, 1, now)
await hass.async_block_till_done()
assert entity.power_percent > 0
side_effects = SideEffects(
{
"sensor.the_power_sensor": State("sensor.the_power_sensor", 50),
"sensor.the_max_power_sensor": State("sensor.the_max_power_sensor", 49),
},
State("unknown.entity_id", "unknown"),
)
# # fmt:off
# with patch("homeassistant.core.StateMachine.get", side_effect=side_effects.get_side_effects()):
# # fmt: on
# await send_power_change_event(entity, 50, datetime.now())
# # Send power max mesurement
# now = now + timedelta(seconds=30)
# VersatileThermostatAPI.get_vtherm_api()._set_now(now)
# await send_max_power_change_event(entity, 300, datetime.now())
#
# assert entity.power_manager.is_overpowering_detected is False
# # All configuration is complete and power is < power_max
# assert entity.preset_mode is PRESET_BOOST
# assert entity.power_manager.overpowering_state is STATE_OFF
# 1. Set VTherm to overpowering
# Send power max mesurement too low and HVACMode is on and device is active
# fmt:off
with patch("homeassistant.core.StateMachine.get", side_effect=side_effects.get_side_effects()), \
patch("custom_components.versatile_thermostat.base_thermostat.BaseThermostat.send_event"), \
patch("custom_components.versatile_thermostat.underlyings.UnderlyingSwitch.turn_on") as mock_heater_on, \
patch("custom_components.versatile_thermostat.underlyings.UnderlyingSwitch.turn_off") as mock_heater_off, \
patch("custom_components.versatile_thermostat.thermostat_switch.ThermostatOverSwitch.is_device_active", return_value="True"):
# fmt: on
now = now + timedelta(seconds=30)
VersatileThermostatAPI.get_vtherm_api()._set_now(now)
await send_max_power_change_event(entity, 49, now)
assert entity.power_manager.is_overpowering_detected is True
# All configuration is complete and power is > power_max we switch to POWER preset
assert entity.preset_mode is PRESET_POWER
assert entity.power_manager.overpowering_state is STATE_ON
assert entity.target_temperature == 12
assert mock_heater_on.call_count == 0
assert mock_heater_off.call_count == 1
# 2. Turn-off Vtherm
# fmt:off
with patch("homeassistant.core.StateMachine.get", side_effect=side_effects.get_side_effects()), \
patch("custom_components.versatile_thermostat.base_thermostat.BaseThermostat.send_event") as mock_send_event, \
patch("custom_components.versatile_thermostat.underlyings.UnderlyingSwitch.turn_on") as mock_heater_on, \
patch("custom_components.versatile_thermostat.underlyings.UnderlyingSwitch.turn_off") as mock_heater_off, \
patch("custom_components.versatile_thermostat.thermostat_switch.ThermostatOverSwitch.is_device_active", return_value="True"):
# fmt: on
now = now + timedelta(seconds=30)
VersatileThermostatAPI.get_vtherm_api()._set_now(now)
await entity.async_set_hvac_mode(HVACMode.OFF)
await VersatileThermostatAPI.get_vtherm_api().central_power_manager._do_immediate_shedding()
await hass.async_block_till_done()
# VTherm is off and overpowering if off also
assert entity.hvac_mode == HVACMode.OFF
assert entity.power_manager.is_overpowering_detected is False
assert entity.preset_mode is PRESET_BOOST
assert entity.power_manager.overpowering_state is STATE_OFF
assert entity.target_temperature == 19