Restore climate hvac mode after restart

Hello all,

I am trying to setup the climate integration and I am making a lot of progress but I am stuck now with the following problem:

I have setup the integration with the initial_hvac_mode: "off" thinking that if I am away and the server restarts I do not want it to turn on the heating. But now I realized that the reverse problem might be happening. I could be home and after the server restarts the hvac mode is off!

So I thought of creating the following automation:

- id: '1609826347595'
  alias: restore heating state after restart
  description: ''
  trigger:
  - platform: homeassistant
    event: start
  condition:
  - condition: state
    entity_id: climate.home
    state: 'off'
    attribute: hvac_modes
  action:
  - service: climate.set_hvac_mode
    data:
      hvac_mode: heat
    entity_id: climate.home
  mode: single

I will add the location based data later, but for the moment this doesn’t work. I restart the homeassistant server from the configuration section, and the hvac mode is never set to heat. What am I doing wrong?

Cheers

I have an update to this. It appears that the automation doesn’t even trigger when I reset the Home Assistant Server.

Why is that?

another update:

It appears that if the operation mode of the climate integration is heat when the restart occurs, with the automation I have above the operation mode is maintained. I tested it by turning off the automation and restarting home assistant and the operation mode is set to off.

I will have to figure out how to remember the state of heater before the restart so I can restore it. Anyway! Progress!

Did you ever get this figured out? This is a significant problem that I have had since beginning with HA about two years ago. Anytime I update HA, I have to make sure that all climate instances are doing what they should be doing at that time. It’s a giant PITA.

no i haven’t figured out the problem above. what I did is to set the default to heat so that if I set the state to off and I restart then it will be in a heating state. but this is still not ok because I would like to absolutely control the state even after a restart.

To be honest I haven’t had much luck with automations for the climate component. For example I would like to start heating in the morning for 1 hour, at noon for 1 hour and in the evening. The rest of the day should be on a per request basis. But the automation doen’t do anything! Everything is controlled by the threshold temperature. If the target temp dips below threshold, heating starts (if the state is heat) and it will keep going until the target temp is equal to target_temp+hot_tolerance then it stops. But such a thing can last 4 hours to reach…

I still have some figuring out to do…

Did you get this working? I have the same problem. Climate devices goes from heat to off after HA restart.

EDIT: My bad. I had the HAVC mode set to ‘off’ as the default state.

Hi!
I would also be interested in fixing this.
My main concern is that if there is a power outage, the state is not preserved.

I was thinking if an option could be to make the initial_hvac_mode variable dynamic by storing in a local file the state of it and reading this at HA restart.

But I am new to HA so it’s maybe not that simple?

Cheers!

1 Like

I am also interested in this

The generic thermostat now remembers his last situation, heating or off and cooling or off. Only if you set a hvac mode in the yaml config file, it will restore to that condition on HA restart.

But it does not remember its mode, so any temps set by away, or comfort or so, are gone after a restart… it will always go to the condition “none”.

Any ideas how to fix that?

My first thought would be to use input helpers - those have a state maintained by HA.

1 Like

MY suggestion would be to implement storing into a hidden file (.storage directory ?) or into in DB all the states for the generic thermostat after each change and loading them back after a restart.
Is there anyone able to implement such a change?

1 Like

I have no clue as to how I would accomplish any of those two solutions suggested by @gerosaf and @Edwin_D

I just know that I wasted quite some energy and money this week end when my heating started on Sunday morning after a HA reboot with nobody in the office and kept going until today (Monday) 5pm.

You can create a boolean or enumeration variable form the settings user interface, under the helpers section. Those keep their states after a reboot. So you can either use that directly as the hvac mode and build your automations from that, or you can use it as persistent storage for the actual hvac mode by copying all mode changes to it. Then you can use an automation like the one you started your post with to restore the mode on reboot.

But instead of restoring the mode to what it was before the reboot, the best way would be to make an automation that determines the required mode based on environmental conditions. Let’s say the power is killed when the hvac is heating, and when the power comes back a while later there is no longer a need for heat. My thinking is the hvac should not restore to the heating state it had before the power outage. Who knows how long it’s been.

On reboot it should instead perform an automation that sais something like: if it is cold and it is a working day and working hours: turn on, else turn off. Or in this case probably something like: working hours: mode is auto, weekend or night: mode is off.

Or maybe use something like this to do the heavy lifting for you?
https://hass-apps.readthedocs.io/en/schedy/apps/schedy/index.html

3 Likes

You need to toggle the mode on start to bring in the corrdct temp or it will use the default temp set in the config file but leave the last mode set which wont allow it to reload the same mode.

I have mine set to toggle to none mode then back to the correct mode after 5 seconds if triggered by home assistant starting flag.