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:
Jean-Marc Collin
2023-08-05 20:02:54 +02:00
parent aa3b87762d
commit 2bebe3e210
2 changed files with 193 additions and 193 deletions

View File

@@ -1,196 +1,196 @@
default_config: default_config:
logger: logger:
default: info default: info
logs: logs:
custom_components.versatile_thermostat: info custom_components.versatile_thermostat: info
custom_components.versatile_thermostat.underlyings: debug custom_components.versatile_thermostat.underlyings: debug
custom_components.versatile_thermostat.climate: debug custom_components.versatile_thermostat.climate: debug
# If you need to debug uncommment the line below (doc: https://www.home-assistant.io/integrations/debugpy/) # If you need to debug uncommment the line below (doc: https://www.home-assistant.io/integrations/debugpy/)
debugpy: debugpy:
start: true start: true
wait: false wait: false
port: 5678 port: 5678
input_number: input_number:
fake_temperature_sensor1: fake_temperature_sensor1:
name: Temperature name: Temperature
min: 0 min: 0
max: 35 max: 35
step: .1 step: .1
icon: mdi:thermometer icon: mdi:thermometer
unit_of_measurement: °C unit_of_measurement: °C
mode: box mode: box
fake_external_temperature_sensor1: fake_external_temperature_sensor1:
name: Ext Temperature name: Ext Temperature
min: -10 min: -10
max: 35 max: 35
step: .1 step: .1
icon: mdi:home-thermometer icon: mdi:home-thermometer
unit_of_measurement: °C unit_of_measurement: °C
mode: box mode: box
fake_current_power: fake_current_power:
name: Current power name: Current power
min: 0 min: 0
max: 1000 max: 1000
step: 10 step: 10
icon: mdi:flash icon: mdi:flash
unit_of_measurement: kW unit_of_measurement: kW
fake_current_power_max: fake_current_power_max:
name: Current power max threshold name: Current power max threshold
min: 0 min: 0
max: 1000 max: 1000
step: 10 step: 10
icon: mdi:flash icon: mdi:flash
unit_of_measurement: kW unit_of_measurement: kW
input_boolean: input_boolean:
# input_boolean to simulate the windows entity. Only for development environment. # input_boolean to simulate the windows entity. Only for development environment.
fake_window_sensor1: fake_window_sensor1:
name: Window 1 name: Window 1
icon: mdi:window-closed-variant icon: mdi:window-closed-variant
# input_boolean to simulate the heater entity switch. Only for development environment. # input_boolean to simulate the heater entity switch. Only for development environment.
fake_heater_switch3: fake_heater_switch3:
name: Heater 3 name: Heater 3
icon: mdi:radiator icon: mdi:radiator
fake_heater_switch2: fake_heater_switch2:
name: Heater 2 name: Heater 2
icon: mdi:radiator icon: mdi:radiator
fake_heater_switch1: fake_heater_switch1:
name: Heater 1 name: Heater 1
icon: mdi:radiator icon: mdi:radiator
fake_heater_4switch1: fake_heater_4switch1:
name: Heater (multiswitch1) name: Heater (multiswitch1)
icon: mdi:radiator icon: mdi:radiator
fake_heater_4switch2: fake_heater_4switch2:
name: Heater (multiswitch2) name: Heater (multiswitch2)
icon: mdi:radiator icon: mdi:radiator
fake_heater_4switch3: fake_heater_4switch3:
name: Heater (multiswitch3) name: Heater (multiswitch3)
icon: mdi:radiator icon: mdi:radiator
fake_heater_4switch4: fake_heater_4switch4:
name: Heater (multiswitch4) name: Heater (multiswitch4)
icon: mdi:radiator icon: mdi:radiator
# input_boolean to simulate the motion sensor entity. Only for development environment. # input_boolean to simulate the motion sensor entity. Only for development environment.
fake_motion_sensor1: fake_motion_sensor1:
name: Motion Sensor 1 name: Motion Sensor 1
icon: mdi:run icon: mdi:run
# input_boolean to simulate the presence sensor entity. Only for development environment. # input_boolean to simulate the presence sensor entity. Only for development environment.
fake_presence_sensor1: fake_presence_sensor1:
name: Presence Sensor 1 name: Presence Sensor 1
icon: mdi:home icon: mdi:home
climate: climate:
- platform: generic_thermostat - platform: generic_thermostat
name: Underlying thermostat1 name: Underlying thermostat1
heater: input_boolean.fake_heater_switch3 heater: input_boolean.fake_heater_switch3
target_sensor: input_number.fake_temperature_sensor1 target_sensor: input_number.fake_temperature_sensor1
- platform: generic_thermostat - platform: generic_thermostat
name: Underlying thermostat2 name: Underlying thermostat2
heater: input_boolean.fake_heater_switch3 heater: input_boolean.fake_heater_switch3
target_sensor: input_number.fake_temperature_sensor1 target_sensor: input_number.fake_temperature_sensor1
- platform: generic_thermostat - platform: generic_thermostat
name: Underlying thermostat3 name: Underlying thermostat3
heater: input_boolean.fake_heater_switch3 heater: input_boolean.fake_heater_switch3
target_sensor: input_number.fake_temperature_sensor1 target_sensor: input_number.fake_temperature_sensor1
- platform: generic_thermostat - platform: generic_thermostat
name: Underlying thermostat4 name: Underlying thermostat4
heater: input_boolean.fake_heater_switch3 heater: input_boolean.fake_heater_switch3
target_sensor: input_number.fake_temperature_sensor1 target_sensor: input_number.fake_temperature_sensor1
- platform: generic_thermostat - platform: generic_thermostat
name: Underlying thermostat5 name: Underlying thermostat5
heater: input_boolean.fake_heater_switch3 heater: input_boolean.fake_heater_switch3
target_sensor: input_number.fake_temperature_sensor1 target_sensor: input_number.fake_temperature_sensor1
- platform: generic_thermostat - platform: generic_thermostat
name: Underlying thermostat6 name: Underlying thermostat6
heater: input_boolean.fake_heater_switch3 heater: input_boolean.fake_heater_switch3
target_sensor: input_number.fake_temperature_sensor1 target_sensor: input_number.fake_temperature_sensor1
- platform: generic_thermostat - platform: generic_thermostat
name: Underlying thermostat7 name: Underlying thermostat7
heater: input_boolean.fake_heater_switch3 heater: input_boolean.fake_heater_switch3
target_sensor: input_number.fake_temperature_sensor1 target_sensor: input_number.fake_temperature_sensor1
- platform: generic_thermostat - platform: generic_thermostat
name: Underlying thermostat8 name: Underlying thermostat8
heater: input_boolean.fake_heater_switch3 heater: input_boolean.fake_heater_switch3
target_sensor: input_number.fake_temperature_sensor1 target_sensor: input_number.fake_temperature_sensor1
- platform: generic_thermostat - platform: generic_thermostat
name: Underlying thermostat9 name: Underlying thermostat9
heater: input_boolean.fake_heater_switch3 heater: input_boolean.fake_heater_switch3
target_sensor: input_number.fake_temperature_sensor1 target_sensor: input_number.fake_temperature_sensor1
recorder: recorder:
include: include:
domains: domains:
- input_boolean - input_boolean
- input_number - input_number
- switch - switch
- climate - climate
- sensor - sensor
template: template:
- binary_sensor: - binary_sensor:
- name: maison_occupee - name: maison_occupee
unique_id: maison_occupee unique_id: maison_occupee
state: "{{is_state('person.jmc', 'home') }}" state: "{{is_state('person.jmc', 'home') }}"
device_class: occupancy device_class: occupancy
- sensor: - sensor:
- name: "Total énergie switch1" - name: "Total énergie switch1"
unique_id: total_energie_switch1 unique_id: total_energie_switch1
unit_of_measurement: "kWh" unit_of_measurement: "kWh"
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
unit_of_measurement: "kWh" unit_of_measurement: "kWh"
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
unit_of_measurement: "kWh" unit_of_measurement: "kWh"
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:
- platform: template - platform: template
switches: switches:
pilote_sdb_rdc: pilote_sdb_rdc:
friendly_name: "Pilote chauffage SDB RDC" friendly_name: "Pilote chauffage SDB RDC"
value_template: "{{ is_state_attr('switch_seche_serviettes_sdb_rdc', 'sensor_state', 'on') }}" value_template: "{{ is_state_attr('switch_seche_serviettes_sdb_rdc', 'sensor_state', 'on') }}"
turn_on: turn_on:
service: select.select_option service: select.select_option
data: data:
option: comfort option: comfort
target: target:
entity_id: select.seche_serviettes_sdb_rdc_cable_outlet_mode entity_id: select.seche_serviettes_sdb_rdc_cable_outlet_mode
turn_off: turn_off:
service: select.select_option service: select.select_option
data: data:
option: comfort-2 option: comfort-2
target: target:
entity_id: select.seche_serviettes_sdb_rdc_cable_outlet_mode entity_id: select.seche_serviettes_sdb_rdc_cable_outlet_mode
frontend: frontend:
themes: themes:
versatile_thermostat_theme: versatile_thermostat_theme:
state-binary_sensor-safety-on-color: "#FF0B0B" state-binary_sensor-safety-on-color: "#FF0B0B"
state-binary_sensor-power-on-color: "#FF0B0B" state-binary_sensor-power-on-color: "#FF0B0B"
state-binary_sensor-window-on-color: "rgb(156, 39, 176)" state-binary_sensor-window-on-color: "rgb(156, 39, 176)"
state-binary_sensor-motion-on-color: "rgb(156, 39, 176)" state-binary_sensor-motion-on-color: "rgb(156, 39, 176)"
state-binary_sensor-presence-on-color: "lightgreen" state-binary_sensor-presence-on-color: "lightgreen"

View File

@@ -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"""