[SOLVED] Upgrade to 0.88 - Automations turned off

Since I upgraded my Hass.IO version to the latest build of 0.88 I have been working my way through a number of things that just seemed to stop working. As I have been going through this I have noticed that any automations that involve using ‘sun’ in particular sunrise or sunset have just not been running.

Below is an example of an automation that has been running fine for months and the minute I upgraded it has failed to trigger

- alias: 'Turn Off Back Garden Lights at Sunrise -4'
  trigger:
    - platform: sun
      event: sunrise
      offset: '-04:00:00'
  action:
    - service: notify.all
      data:
        message: 'Back Garden Lights Turned Off'
    - service: homeassistant.turn_off
      entity_id: switch.garden_lights

Can I ask if anyone else has experienced this and if so what they did to fix it ?

Thanks

Well, that’s very interesting. Do you use my (or someone else’s) custom sun component by any chance?

Or maybe I should ask a more basic question – are you sure the automation is still on? Lately a lot of people seem to have been finding their automations turned off for some reason.

you have a fair point … they may be off …. I have only been using Home Assistant for a couple of weeks so still a bit of a newbie.

I just assumed they were on by default …

When first created they are on by default. But automations can be turned off. And if turned off they will stay off, even across restarts.

And there is some sort of scenario that seems to be turning them off lately. The docs say if you restart HA multiple times too fast, that can turn them off. (When starting they actually do get turned off, and then after a “short” bit the ones that were on before the restart get turned back on. But if you restart again before they get turned on, they will stay off.)

To deal with this you can do one of two things: 1) Add initial_state: true to the automation configuration (so it will always be turned back on after restart), or 2) don’t restart HA too fast multiple times. Still, I wonder if that’s the only scenario that is somehow turning automations off, because I seem to see too many people getting into this situation.

Of course, don’t know if any of this applies to you, but just in case…

1 Like

@pnbruckner you were correct looked like all the automations had been turned off, very strange behaviour.

However I followed your suggestion of changing intial_state: true on them all and it appears to be working as expected.

Thanks for the pointers.

1 Like

I’m not sure that is true anymore. It used to be that way but I think the default state is off.

I put in a document change a few weeks ago about the confusion everyone was having over the new automation situation. it was implemented but now it looks like someone else has changed it again.

I’m not sure that’s correct. I just looked at the code in 0.88.1 and if initial_state is not set, then the default is True.

Also, whenever HA starts (or, I suppose, whenever an automation is first created), for each automation it prints a DEBUG message to the log that shows what the initial state is, and where it came from (i.e., recorder, config, or default.)

Maybe they changed it back again.

if it defaults to true then why would the automations ever be off after a restart without intitial_state set to true? Wouldn’t the state be reset to the default value if there was no state to restore to?

I haven’t gone through all the code involved, so I can’t say for sure. All I can say is based on what I’ve seen and read so far. And what I’ve seen is, all automations are off when HA starts. (You can see this in home-assistant.log.) Then at some point the “appropriate” ones are turned on, based on whether or not they have an initial_state setting, and if not, whether or not a state was saved (which, BTW, is no longer retrieved from the recorder, but from .storage/core.restore_state.)

So the theory is, I believe, if HA is restarted in that time between all the automations being turned off, and the appropriate ones being turned back on, then their states – all off at this point – will be saved and restored during the restart process.

EDIT:

E.g., from my recent restart:

pi@raspberrypi:/home/homeassistant/.homeassistant $ grep -e homeassistant_start -e 'new_state=<state automation' home-assistant.log
2019-02-24 17:37:27 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: new_state=<state automation.xxx=off; last_triggered=None, friendly_name=xxx @ 2019-02-24T17:37:27.264323-06:00>, entity_id=automation.xxx, old_state=None>
...
2019-02-24 17:37:27 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: new_state=<state automation.yyy=off; last_triggered=None, friendly_name=yyy @ 2019-02-24T17:37:27.501173-06:00>, entity_id=automation.yyy, old_state=None>
2019-02-24 17:37:33 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event homeassistant_start[L]>
2019-02-24 17:37:34 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: new_state=<state automation.xxx=on; last_triggered=None, friendly_name=xxx @ 2019-02-24T17:37:34.311992-06:00>, entity_id=automation.xxx, old_state=<state automation.xxx=off; last_triggered=None, friendly_name=xxx @ 2019-02-24T17:37:27.264323-06:00>>
...
2019-02-24 17:37:34 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: new_state=<state automation.yyy=on; last_triggered=None, friendly_name=yyy @ 2019-02-24T17:37:34.713976-06:00>, entity_id=automation.yyy, old_state=<state automation.yyy=off; last_triggered=None, friendly_name=yyy @ 2019-02-24T17:37:27.501173-06:00>>

So you can see, in my case, there is a window of up to about seven seconds where automations are off at startup before they are turned back on.

Great tips, thanks!

I had grouped my automations so I could turn them back on with one switch but initial_state: true is a much better solution.

1 Like

If I put initial state true I get an error

If you post exactly what you did (i.e., share the relevant config), and the error you got, we might be able to help.

1 Like

Thank you, I will but I have downgraded to 86.4 since any upgrade after this breaks my MQTT and automations and alexa media (but for alexa there is actually an update for use on 0.88 and later)