Autmation based on Automation reload event does not complete

I had this automation for a long time and recently I noticed that it was not working correctly anymore.

---
#
# Automation is Reloaded
#
alias: Automation is Reloaded
description: ''
trigger:
  - platform: event
    event_type: call_service
    event_data:
      domain: automation
      service: reload
condition: []
action:
  - service: input_boolean.turn_on
    data: {}
    entity_id: input_boolean.automation_is_reloaded
  - delay: '10'
  - service: input_boolean.turn_off
    data: {}
    entity_id: input_boolean.automation_is_reloaded
mode: single

Basically, an input boolean is set to true while automation is reloading and then it is set to false again after 10 seconds.

I check this input_boolean value in other automations so that my automations don’t unnecessary trigger on automation reload otherwise mqtt based automations (and some others) would trigger.

Long story short this used to work fine, but recently it isn’t.
After some troubleshooting, I can confirm that when automation is reloaded, the input boolean is set to true, but the 10 second delay and then setting off is never completed.
If I manually trigger this automation, the input boolean is properly set back to off. (ie the automation works as designed)

So it looks like, during a true automation reload event, this one completes half way and then somehow aborts silently.

Is this a design change or a regression.
Either way, can one think of a workaround?

Thanks
BB

alias: Automation is Reloaded
trigger:
  platform: event
  event_type: automation_reloaded
action:
  - service: input_boolean.turn_on
    entity_id: input_boolean.automation_is_reloaded
  - delay: '10'
  - service: input_boolean.turn_off
    entity_id: input_boolean.automation_is_reloaded

It’s was changed a very long time ago.

1 Like

Awesome thanks,
I must have been under a rock to only notice it now (I guess I wasn’t reloading automations)

Your code does exactly what I want,
On, delay Off

But now I’m having a problem with my other automation being triggered even though according to these conditions it shouldn’t

condition:
  condition: and
  conditions:
    - condition: template
      value_template: >
        {%- if states.sensor.hass_uptime.last_changed -%}
          {{ (as_timestamp(now()) - as_timestamp(states.sensor.hass_uptime.last_changed)) > 30 }}
        {%- else -%}
          true
        {%- endif -%}
    - condition: state
      entity_id: input_boolean.automation_is_reloaded
      state: 'off'

I can’t figure out why it is triggered, since I have an and condition and input_boolean.automation_is_reloaded should be off
Unless the other automation is triggered before the boolean value is set to true, which would be odd.

I confirmed the behavior of your script doing exactly what it is supposed to do.

Dunno :man_shrugging:

Personally I have all of my automations except one set to initial_state false, then the one that isn’t triggers on startup and automation reloads, does a few checks, waits for devices to come online etc, and then turns all the other automations on. Then it fires a custom event that any of the other automations that would normally be run ‘on startup’ get triggered by.

Works well.

1 Like

Thanks, sounds like a good approach.
I’ll give that a shot,
Thanks for your ideas.

BB

1 Like

Sadly, the suggested approach did not work.
I set the specific automation in question to initial_state false
and enabled it at the end of the above automation_reload script (after the 10 second delay)

  - service: automation.turn_on
    data: {}
    entity_id: automation.phone_call

Everything works as expected, but the minute the second automation is enabled, it is triggered.
I’m beginning to think that it has something to do it being mqtt trigger based.

alias: Phone Call
initial_state: false
trigger:
  - platform: mqtt
    topic: ncid/pi
condition:

Is it possible that MQTT based triggers are always fired when the automation is turned on?

@anon43302295 I marked your answer as the solution because it addressed the Original issue.
Although I don’t understand why turning on automation with MQTT trigger always fires, I worked around the issue by checking the timestamp of last phone call and only triggering the automation if it is less than 30 seconds.
It solves my problem, but curious me ultimately wants to know what is up with MQTT triggers.

Thanks
BB

1 Like

Yeah I don’t know about the mqtt trigger unfortunately, so can’t help much more - sorry.