Issue #95 - the integration would switch ac on and off rapidly and lock up home assistant if outside temp is NaN
This commit is contained in:
@@ -141,9 +141,9 @@ template:
|
|||||||
device_class: energy
|
device_class: energy
|
||||||
state_class: total_increasing
|
state_class: total_increasing
|
||||||
state: >
|
state: >
|
||||||
{% set energy = state_attr('climate.thermostat_switch_1', 'total_energy') %}
|
{% set energy = state_attr('climate.thermostat_switch_1', 'total_energy') | float(default=-1) %}
|
||||||
{% if energy == 'unavailable' or energy is none%}unavailable{% else %}
|
{% if energy < 0 %}{{none}}{% else %}
|
||||||
{{ ((energy | float) / 1.0) | round(2, default=0) }}
|
{{ energy | round(2, default=0) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
- name: "Total énergie climate 2"
|
- name: "Total énergie climate 2"
|
||||||
unique_id: total_energie_climate2
|
unique_id: total_energie_climate2
|
||||||
@@ -151,9 +151,9 @@ template:
|
|||||||
device_class: energy
|
device_class: energy
|
||||||
state_class: total_increasing
|
state_class: total_increasing
|
||||||
state: >
|
state: >
|
||||||
{% set energy = state_attr('climate.thermostat_climate_2', 'total_energy') %}
|
{% set energy = state_attr('climate.thermostat_climate_2', 'total_energy') | float(default=-1) %}
|
||||||
{% if energy == 'unavailable' or energy is none%}unavailable{% else %}
|
{% if energy < 0 %}{{none}}{% else %}
|
||||||
{{ ((energy | float) / 1.0) | round(2, default=0) }}
|
{{ energy | round(2, default=0) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
- name: "Total énergie chambre"
|
- name: "Total énergie chambre"
|
||||||
unique_id: total_energie_chambre
|
unique_id: total_energie_chambre
|
||||||
@@ -161,9 +161,9 @@ template:
|
|||||||
device_class: energy
|
device_class: energy
|
||||||
state_class: total_increasing
|
state_class: total_increasing
|
||||||
state: >
|
state: >
|
||||||
{% set energy = state_attr('climate.thermostat_chambre', 'total_energy') %}
|
{% set energy = state_attr('climate.thermostat_chambre', 'total_energy') | float(default=-1) %}
|
||||||
{% if energy == 'unavailable' or energy is none%}unavailable{% else %}
|
{% if energy < 0 %}{{none}}{% else %}
|
||||||
{{ ((energy | float) / 1.0) | round(2, default=0) }}
|
{{ energy | round(2, default=0) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
switch:
|
switch:
|
||||||
|
|||||||
@@ -1611,6 +1611,7 @@ class VersatileThermostat(ClimateEntity, RestoreEntity):
|
|||||||
HVACMode.DRY,
|
HVACMode.DRY,
|
||||||
HVACMode.AUTO,
|
HVACMode.AUTO,
|
||||||
HVACMode.FAN_ONLY,
|
HVACMode.FAN_ONLY,
|
||||||
|
None
|
||||||
]:
|
]:
|
||||||
self._hvac_mode = new_state.state
|
self._hvac_mode = new_state.state
|
||||||
|
|
||||||
@@ -2098,9 +2099,17 @@ class VersatileThermostat(ClimateEntity, RestoreEntity):
|
|||||||
switch_cond,
|
switch_cond,
|
||||||
)
|
)
|
||||||
|
|
||||||
ret = False
|
shouldClimateBeInSecurity = temp_cond and climate_cond
|
||||||
if mode_cond and temp_cond and climate_cond:
|
shouldSwitchBeInSecurity = temp_cond and switch_cond
|
||||||
if not self._security_state:
|
shouldBeInSecurity = shouldClimateBeInSecurity or shouldSwitchBeInSecurity
|
||||||
|
|
||||||
|
shouldStartSecurity = mode_cond and not self._security_state and shouldBeInSecurity
|
||||||
|
# attr_preset_mode is not necessary normaly. It is just here to be sure
|
||||||
|
shouldStopSecurity = self._security_state and not shouldBeInSecurity and self._attr_preset_mode == PRESET_SECURITY
|
||||||
|
|
||||||
|
# Logging and event
|
||||||
|
if shouldStartSecurity:
|
||||||
|
if shouldClimateBeInSecurity:
|
||||||
_LOGGER.warning(
|
_LOGGER.warning(
|
||||||
"%s - No temperature received for more than %.1f minutes (dt=%.1f, dext=%.1f) and underlying climate is %s. Set it into security mode",
|
"%s - No temperature received for more than %.1f minutes (dt=%.1f, dext=%.1f) and underlying climate is %s. Set it into security mode",
|
||||||
self,
|
self,
|
||||||
@@ -2109,10 +2118,7 @@ class VersatileThermostat(ClimateEntity, RestoreEntity):
|
|||||||
delta_ext_temp,
|
delta_ext_temp,
|
||||||
self.hvac_action,
|
self.hvac_action,
|
||||||
)
|
)
|
||||||
ret = True
|
elif shouldSwitchBeInSecurity:
|
||||||
|
|
||||||
if mode_cond and temp_cond and switch_cond:
|
|
||||||
if not self._security_state:
|
|
||||||
_LOGGER.warning(
|
_LOGGER.warning(
|
||||||
"%s - No temperature received for more than %.1f minutes (dt=%.1f, dext=%.1f) and on_percent (%.2f) is over defined value (%.2f). Set it into security mode",
|
"%s - No temperature received for more than %.1f minutes (dt=%.1f, dext=%.1f) and on_percent (%.2f) is over defined value (%.2f). Set it into security mode",
|
||||||
self,
|
self,
|
||||||
@@ -2122,9 +2128,7 @@ class VersatileThermostat(ClimateEntity, RestoreEntity):
|
|||||||
self._prop_algorithm.on_percent,
|
self._prop_algorithm.on_percent,
|
||||||
self._security_min_on_percent,
|
self._security_min_on_percent,
|
||||||
)
|
)
|
||||||
ret = True
|
|
||||||
|
|
||||||
if mode_cond and temp_cond and not self._security_state:
|
|
||||||
self.send_event(
|
self.send_event(
|
||||||
EventType.TEMPERATURE_EVENT,
|
EventType.TEMPERATURE_EVENT,
|
||||||
{
|
{
|
||||||
@@ -2140,8 +2144,8 @@ class VersatileThermostat(ClimateEntity, RestoreEntity):
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
if not self._security_state and ret:
|
if shouldStartSecurity:
|
||||||
self._security_state = ret
|
self._security_state = True
|
||||||
self.save_hvac_mode()
|
self.save_hvac_mode()
|
||||||
self.save_preset_mode()
|
self.save_preset_mode()
|
||||||
await self._async_set_preset_mode_internal(PRESET_SECURITY)
|
await self._async_set_preset_mode_internal(PRESET_SECURITY)
|
||||||
@@ -2167,18 +2171,14 @@ class VersatileThermostat(ClimateEntity, RestoreEntity):
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
if (
|
if shouldStopSecurity:
|
||||||
self._security_state
|
|
||||||
and self._attr_preset_mode == PRESET_SECURITY
|
|
||||||
and not ret
|
|
||||||
):
|
|
||||||
_LOGGER.warning(
|
_LOGGER.warning(
|
||||||
"%s - End of security mode. restoring hvac_mode to %s and preset_mode to %s",
|
"%s - End of security mode. restoring hvac_mode to %s and preset_mode to %s",
|
||||||
self,
|
self,
|
||||||
self._saved_hvac_mode,
|
self._saved_hvac_mode,
|
||||||
self._saved_preset_mode,
|
self._saved_preset_mode,
|
||||||
)
|
)
|
||||||
self._security_state = ret
|
self._security_state = False
|
||||||
# Restore hvac_mode if previously saved
|
# Restore hvac_mode if previously saved
|
||||||
if self._is_over_climate or self._security_default_on_percent <= 0.0:
|
if self._is_over_climate or self._security_default_on_percent <= 0.0:
|
||||||
await self.restore_hvac_mode(False)
|
await self.restore_hvac_mode(False)
|
||||||
@@ -2201,7 +2201,7 @@ class VersatileThermostat(ClimateEntity, RestoreEntity):
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
return ret
|
return shouldBeInSecurity
|
||||||
|
|
||||||
async def _async_control_heating(self, force=False, _=None):
|
async def _async_control_heating(self, force=False, _=None):
|
||||||
"""The main function used to run the calculation at each cycle"""
|
"""The main function used to run the calculation at each cycle"""
|
||||||
|
|||||||
Reference in New Issue
Block a user