How does "initial_state" for automations work?

Hi all,

I am confused by the initial_state that can be set for automations. I noticed some behaviour changes after upgrading to 0.42 (issues #6911 and possibly #6936 were related to this) and have been trying to figure out what “on” and “off” mean with regard to automations.

Does ON mean, the automation can be triggered if the right conditions are met, and OFF means it will never be triggered even if the specified conditions are met?

Or does it turn ON when it is triggered and turn off again when it is ready executing?

I am asking because I cannot figure out how to set the initial state for several automations. I have multiple involving switching/dimming the same light. and it seems one keeps overrulling the other or something, but I can’t find the pattern of what is doing what when setting different initial_states.

Hope someone can shed a light?

You’re correct. An automation can be turned “OFF”, which will disable it, even if it’s trigger condition is met.

initial_state allows you to have the automation disabled on startup.

lh8gates is correct. You should paste in your automations and tell us what is going wrong.

Yes, this. An automation in the “off” state is inactive no matter the conditions. They are all on by default. If you have initial_state: 'off' in the automation you need to turn it on before it will work.

You can also control this state with the services automation.turn_on/turn_off/toggle or by simply adding the automation to a group and controlling it like any other switch.


Ah thanks for the replies! @chrio 's explanation made me realize that I can use those states for activating different automations. not sure how to use that, but thanks for explaining!

Is there a way to setup initial_status to be the last state? So if the automation was turned off it will remain off after a restart and if it was on remain on? Thank you!

UPDATE: confirmed it is working properly and remember last state if no initial_state in the config and recorder is configured.

If you don’t add initial_state to the automation it will keep the state it had before the restart.

More information here:

I tried that, but for me it is always coming back on if no initial_state added. Thank you!

do you have recorder: enabled? I think the restore_state only works if recorder: is active (but I could be wrong)

Hi, Thanks, yes I have it enabled and saving into a PostgreSQL…

  db_url: !secret homeassistant_db
  purge_keep_days: 60

Totally my bad!!! I am sorry, I commented out the initial_state from a different automation. Ashamed… Thank you Guys and confirmed it is working properly and remember last state if no initial_state in the config and recorder is configured.

1 Like