How to prevent automation triggering on HA startup or config reload?

Hi all,

I have an automation triggered by a sensor’s state change. The issue is it fires every time Home Assistant restarts or the configuration reloads, even when the sensor’s value hasn’t truly changed.

I want to avoid these unwanted triggers caused by startup or reload.

Here’s what I’ve tried and my thoughts:

  • Adding for: in the trigger delays the action until the state remains stable for that duration, but it doesn’t prevent triggering if the state changes on startup or reload. The automation triggers once the new state has been stable for the specified time.
  • Using not_from: and not_to: to exclude certain states isn’t a good fit because I need the automation to trigger even if the state becomes unavailable legitimately. So excluding states could block valid triggers.
  • Disabling the automation by default and enabling it via another automation after startup avoids the issue on restart, but it doesn’t solve triggers caused by config reloads when the automation stays enabled and still fires.
  • Adding delays or using wait_for_trigger to filter out startup events didn’t help.

Is there a reliable method to stop automations from firing during Home Assistant startup or configuration reload — when entity states are just restored or haven’t actually changed?

Thanks in advance!

Set up an Uptime sensor then use that as a condition.

condition: template
value_template: |
  {{ now() > states('sensor.uptime')|as_datetime 
  + timedelta(seconds=5) }}

Unfortunately, it doesn’t cover the case when I reload automations or config from the UI or Developer Tools. In that case, the uptime sensor doesn’t change, and the automation still runs due to restored or unchanged states.

maybe something like this?

trigger:
  - platform: state
    entity_id: sensor.your_sensor
condition:
  - condition: template
    value_template: >
      {{ not is_state('homeassistant', 'starting') }}
  - condition: template
    value_template: >
      {{ trigger.from_state.state != trigger.to_state.state }}
action:
  - service: your.service

the
{{ trigger.from_state.state != trigger.to_state.state }}

its a extra precaution

The first condition only works during full HA startup because homeassistant isn’t set to starting on config reload. The second doesn’t help if the sensor temporarily goes unavailable and then restores its previous state — it still counts as a state change. Still looking for a more reliable solution.

condition:
  - condition: template
    value_template: >
      {% set from = trigger.from_state.state %}
      {% set to = trigger.to_state.state %}
      {{ from not in ['unavailable', 'unknown', None] and
         to not in ['unavailable', 'unknown', None] and
         from != to }}

The problem is that HA will not recognise that it’s restoring its “previous” state, because the actual previous state in the state engine is unavailable, while you want the state before that.

The fact that you still want the automation to trigger in cases where it genuinely goes unavailable complicates matters a bit, because you need a way to distinguish between a restart/reload and an actual issue.

This is untested, but might work. Set up 2 triggers in your automation:

  • First one with not_from: and not_to: unavailable/unknown.
  • Second one with to: unavailable for 30s (or some value more than it takes for states to restore after a restart).

That should cover your requirements and avoid unnecessary triggers with restarts, while also triggering if the entity is actually unavailable (after a slight delay).

2 Likes

You’re right in theory, but in practice I ran into issues.

Your suggestion:

trigger:
  - platform: state
    entity_id: sensor.example
    not_from:
      - unavailable
      - unknown
    not_to:
      - unavailable
      - unknown
  - platform: state
    entity_id: sensor.example
    to: unavailable
    for: 30s

This is effectively the same as:

trigger:
  - platform: state
    entity_id: sensor.example
    not_from:
      - unavailable
      - unknown
    for: 30s

But with this config, I lose the trigger when the sensor changes from unavailable to a real value.

To fix that, I tried adding a third trigger:

  - platform: state
    entity_id: sensor.example
    from: unavailable
    for: 30s

In reality, the third trigger still fire after 30s during config reload. The second trigger works correctly — it doesn’t fire on restarts because the sensor is unavailable for less than 30 seconds, so the condition is never met.

No, it is not effectively the same. The single trigger above (and the third trigger you posted) will lead to the issues you reported under those scenarios.

Can you try my suggestion of the 2 triggers and let me know if it works?

I tried your suggestion:

trigger:
  - platform: state
    entity_id: sensor.example
    not_from:
      - unavailable
      - unknown
    not_to:
      - unavailable
      - unknown
  - platform: state
    entity_id: sensor.example
    to: unavailable
    for: 30s

With this setup, the automation doesn’t fire on config reload, which is good — but I lose the trigger when the sensor changes from unavailable to a valid state.

It’s going to be next to impossible to achieve that, because using something like your third trigger will lead to false alerts.

The good news is that you will still get a trigger when your entity changes to unavailable for 30s. This is what you originally listed as a requirement, and my proposal meets those criteria:

Create a timer, e.g.

  timertemplate:
    name: Timer voor template reload
    duration: '00:10:00'    

create an automation

- id: 07c2eb0d-4c45-4d17-a20e-e6ff47376e98
  alias: start timertemplate
  triggers:
  - platform: event
    event_type: event_template_reloaded
    id: "reload"
  - platform: homeassistant
    event: start  
  - platform: event
    event_type: automation_reloaded      
  actions:    
  - action: timer.start
    target:
      entity_id: timer.timertemplate

add condition in your other automation

  - condition: state
    entity_id: timer.timertemplate
    state: idle    

2 Likes

Thanks to everyone who helped — I truly appreciate the insights and suggestions.
Special thanks to ShadowFist for taking the time to dive into the details and share solutions. :pray:

I’ve already implemented the following:

alias: HA Ready Status on Template Reload
description: Sets ha_ready false on template reload and resets it to true after 5 seconds
triggers:
  - trigger: event
    event_type: event_template_reloaded
  - trigger: homeassistant
    event: start
actions:
  - target:
      entity_id: input_boolean.ha_ready
    action: input_boolean.turn_off
    data: {}
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
  - target:
      entity_id: input_boolean.ha_ready
    action: input_boolean.turn_on
    data: {}
mode: restart

This was the only working solution I found to prevent false triggers during reboots or config reloads, without losing the ability to track unavailable and unknown states.
Took me more than 10 hours to get this right — honestly frustrating that Home Assistant doesn’t handle this natively.

Upd…
Additional requirement: delay: in the “ha_ready” automation must be greate then for: in the main automation trigger.

Yes, I wish HA had a native way to avoid false triggers during upgrades and reloads.

I get an alert that the garage door is opening whenever the Z-WaveJS is updating.

I get an alert that someone is ringing the G4 Pro doorbell whenever the UniFi Protect integration gets an update.

Rather than use an automation and an Input Boolean, you may wish to consider implementing it as a single, self-contained entity: a Trigger-based Template Binary Sensor.

2 Likes

Thanks! I’ll give that a try — this sounds like a cleaner solution.

What would this “native way” look like?

In other words, how would you configure the State Trigger to not trigger for a particular state-change if, and only if, that state-change occurs at startup?

You’ll probably need to experiment with its delay_on option.

Thanks. Working example. It’s much cleaner than using automation with input_boolean

template:
  - trigger:
      - platform: event
        event_type: event_template_reloaded
      - platform: homeassistant
        event: start
    binary_sensor:
      - name: "HA Initializing"
        unique_id: ha_initializing
        state: "true"
        auto_off: 10
4 Likes

wow - I have had this problem for years.

I have always been able to stop triggering on HA restarts and template reloads bar my shades automation.

I have tried just about everything in this thread (trigger.from_state.state, trigger.to_state.state, using for: etc etc).

event_type: event_template_reloaded worked brilliantly - thanks to all who contributed here!