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 ?
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.
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…
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.)
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.
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)