jmcollin78 / versatile_thermostat

A full featured Thermostat for Home Assistant: presets, window, motion, presence and overpowering management
MIT License
327 stars 34 forks source link

HVAC Never Resets Back to Heat When Restarting Home Assistant With a Window Open #504

Closed rjosborne closed 2 weeks ago

rjosborne commented 1 month ago

Version of the custom_component

6.2.9

Configuration

My VTherm attributes are the following:

hvac_modes: heat, off
min_temp: 10
max_temp: 32
target_temp_step: 0.5
preset_modes: none, frost, eco, comfort, boost
current_temperature: 20.8
temperature: 19
hvac_action: idle
preset_mode: comfort
is_on: true
hvac_mode: heat
type: null
is_controlled_by_central_mode: true
last_central_mode: null
frost_temp: 10
eco_temp: 15
boost_temp: 22
comfort_temp: 19
frost_away_temp: 10
eco_away_temp: 10
boost_away_temp: 10
comfort_away_temp: 10
power_temp: null
target_temperature_step: 0.5
ext_current_temperature: 10.9
ac_mode: false
current_power: null
current_power_max: null
saved_preset_mode: comfort
saved_target_temp: 19
saved_hvac_mode: heat
motion_sensor_entity_id: null
motion_state: null
power_sensor_entity_id: null
max_power_sensor_entity_id: null
overpowering_state: null
presence_sensor_entity_id: binary_sensor.home_is_occupied
presence_state: on
window_state: off
window_auto_state: off
window_bypass_state: false
window_sensor_entity_id: binary_sensor.doors_and_windows
window_delay_sec: 30
window_auto_enabled: false
window_auto_open_threshold: null
window_auto_close_threshold: null
window_auto_max_duration: null
window_action: window_turn_off
security_delay_min: 60
security_min_on_percent: 0.5
security_default_on_percent: 0.1
last_temperature_datetime: 2024-09-24T21:41:30.172966+01:00
last_ext_temperature_datetime: 2024-09-24T22:01:02.831758+01:00
security_state: false
minimal_activation_delay_sec: 10
device_power: 1
mean_cycle_power: null
total_energy: 0
last_update_datetime: 2024-09-24T22:01:26.150432+01:00
timezone: Europe/London
temperature_unit: °C
is_device_active: false
ema_temp: 20.76
is_used_by_central_boiler: false
is_over_climate: true
start_hvac_action_date: null
underlying_climate_0: climate.lounge
underlying_climate_1: null
underlying_climate_2: null
underlying_climate_3: null
auto_fan_mode: auto_fan_none
current_auto_fan_mode: auto_fan_none
auto_activated_fan_mode: null
auto_deactivated_fan_mode: null
auto_regulation_use_device_temp: false
friendly_name: Home Thermostat
supported_features: 401

Describe the bug

I'm trying to:

And I expect:

But I observe this ....

I read the documentation on the README.md file and I don't find any relevant information about this issue.

I have taken a quick look at the code and can see the attribute "saved_hvac_mode" being written to / read from when a window opens and. closes.

I suspect the value of this may be getting reset to "off" as a result of the home assistant restart, meaning when the window is closed, the VTherm restores the incorrect "off" value.

jmcollin78 commented 1 month ago

Hello, yes this is common kwown limitation of VTherm. At restart, all dynamic states (the open window state in your case) is not restored and I'm not sure it is a good idea to implement this:

  1. Many people, does restart, when something goes wrong. And then you need to restore to a stable state.
  2. the automatic open window detection need to memorize the previous sets of temperature to work. And this previous temperatures are no more available at restart.
  3. when window close, we need to restore the old settings. Old settings are not available at restart.
  4. for other state like overpowering or safety state, they will be recalculated at next sensor values received.

So my opinion is to NOT store and restore the dynamic states like window open state.

tristone-cz commented 3 weeks ago

I wanted to open the same issue but found this one. So started to elaborate different way :)

@rjosborne The way to go is and automation done at HA startup. I tried several combination and sequences but this one works and does what we want - to restore the state to off and after windows close to heat.

alias: Thermostats preparation on startup
description: ""
triggers:
  - trigger: homeassistant
    event: start
conditions: []
actions:
  - delay:
      hours: 0
      minutes: 0
      seconds: 20
      milliseconds: 0
  - action: versatile_thermostat.set_window_bypass
    metadata: {}
    data:
      window_bypass: true
    target:
      entity_id:
        - climate.thermostat_bedroom
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
  - action: climate.set_hvac_mode
    metadata: {}
    data:
      hvac_mode: heat
    target:
      entity_id:
        - climate.thermostat_bedroom
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
  - action: versatile_thermostat.set_window_bypass
    metadata: {}
    data:
      window_bypass: false
    target:
      entity_id:
        - climate.thermostat_bedroom
mode: single

After HomeAssistant start the automation turns ON the window bypass. To ignore opened window. Then set mode to HEAT. Which tells Versatile Thermostat to turn the heating on, in real. And then turn OFF the window bypass. After some seconds Versatile Thermostat will notice the window is opened and set mode to OFF as if you manually open the window. Once window is closed HEAR mode is automatically restored.

jmcollin78 commented 3 weeks ago

After some seconds Versatile Thermostat will notice the window is opened and set mode to OFF as if you manually open the window.

Great way to solve the issue. The only think is that you will not restore the previous state but it is something valuable as you did. One more thing, is that you seems to run this automation even if window is closed. This will force to heat each time you restart HA. Think about in summer. You will force heating your VTherm after restarting HA.

rjosborne commented 3 weeks ago

I did something similar, but I use two automation for mine - one at shutdown which records that the saved HVAC mode is heat and a window is open, then a second at startup that restores everything. The startup automation also needs an extra little "trick" via a switch to temporarily trick VTherm into thinking I've closed the window.

Automations are below for anybody who's interested...

alias: Persist Saved HVAC Mode
description: ""
mode: single
triggers:
  - event: shutdown
    trigger: homeassistant
conditions:
  - condition: state
    entity_id: binary_sensor.home_thermostat_doors_and_windows
    state: "on"
  - condition: state
    entity_id: climate.home_thermostat
    attribute: saved_hvac_mode
    state: heat
actions:
  - action: switch.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: switch.home_thermostat_saved_hvac_mode
alias: Restore Saved HVAC Mode
description: ""
mode: single
triggers:
  - event: start
    trigger: homeassistant
conditions:
  - condition: state
    entity_id: switch.home_thermostat_saved_hvac_mode
    state: "on"
actions:
  - action: switch.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: switch.home_thermostat_force_doors_and_windows_off
  - delay:
      hours: 0
      minutes: 0
      seconds: 35
      milliseconds: 0
  - action: climate.set_hvac_mode
    metadata: {}
    data:
      hvac_mode: heat
    target:
      entity_id: climate.home_thermostat
  - action: switch.turn_off
    metadata: {}
    data: {}
    target:
      entity_id: switch.home_thermostat_force_doors_and_windows_off
  - action: switch.turn_off
    metadata: {}
    data: {}
    target:
      entity_id: switch.home_thermostat_saved_hvac_mode
jmcollin78 commented 3 weeks ago

I'm so sad people have to do some automations to avoid this limitation. The objective of VTherm was precisely to avoid these automations.

tristone-cz commented 3 weeks ago

After some seconds Versatile Thermostat will notice the window is opened and set mode to OFF as if you manually open the window.

Great way to solve the issue. The only think is that you will not restore the previous state but it is something valuable as you did. One more thing, is that you seems to run this automation even if window is closed. This will force to heat each time you restart HA. Think about in summer. You will force heating your VTherm after restarting HA.

I intentionally simplified the automation YAML as much as possible, just to demonstrate the approach. There are eg. more rooms. And of course also a conditions taking into account heating season and vacations 😉

rjosborne commented 3 weeks ago

I'm so sad people have to do some automations to avoid this limitation. The objective of VTherm was precisely to avoid these automations.

It would be great if VTherm could handle this one for us, that's why I thought it might be a bug initially.

However - I can equally understand as a developer myself the position that these are meant to be temporary variables and that persisting them across startup could be a risk, hence I fully understand the "will not fix" decision.

Something that only occurs when Home Assistant restarts is a relative edge case. The only reason I've configured around it is for the reverse of your "think about having the heating stuck on in summer" point above... In winter, if I happen to restart Home Assistant while a door / window is open, the heating is then stuck off until I realise and intervene what's happened and the house gets cold.

jmcollin78 commented 3 weeks ago

t would be great if VTherm could handle this one for us, that's why I thought it might be a bug initially.

I will think more over this. I very rarely have the case of restarting HA with an open window on winter, but I image If you have done automation for this, that means it is a real case.

Maybe one solution is to store also the saved_hvac_mode (before window opens) and window_state and restore it after restart. But if the is closed during the stop of HA, the VTherm will stay off. I'm pretty sure, VTherm will NOT receive an event if there is no window change. So I will have to deal with startup, check current stat of window, compare with the saved one and one trap is that all is not necessary available at startup - specially with battery powered device like window sensor. So I will surely be not able to determine the window state at startup.

All of this sounds like a mess for an edge case. I will think more or if you have ideas don't hesitate.

jmcollin78 commented 2 weeks ago

Hello, I have good news around this topic.

While implementing #585 i ran exactly on the same issue and I have to find a solution. So I have the solution and it is implemented now.

I will release it soon, I wonder if you can give it a try.

jmcollin78 commented 2 weeks ago

https://github.com/jmcollin78/versatile_thermostat/releases/tag/6.5.0

tristone-cz commented 2 weeks ago

It works 👍

jmcollin78 commented 2 weeks ago

Yes I know ;-) I made many tests and It seems to work as expected.

Thank you for your report, it forces me to reconsider the issue !