Trigger based on when automation is updated

I have a blueprint that sets a bunch of template sensor attributes. Right now when the user creates an automation with the blueprint these values are stored but not set until a restart occurs.

I know that an event happens when this automation is saved:

event_type: call_service
data:
  domain: automation
  service: reload
  service_data:
    id: "1731166216636"
origin: LOCAL
time_fired: "2024-11-13T19:22:11.445106+00:00"
context:
  id: 01JCKFKS3N0C394Q2BTXDBC1CQ
  parent_id: null
  user_id: null

Is the id value available as a variable within the automation that I can then use with an event trigger where I can check specifically for:

data:
  domain: automation
  service: reload
  service_data:
    id: "1731166216636"

That would then trigger the same call I am making to set the variables on start? Is that id value available as a variable? If so, can someone mock up how this would look?

On further inspection, I saw this in the trace changed variables:

this:
  entity_id: automation.view_assist_control_display_masterbedroom_rework_again
  state: 'on'
  attributes:
    id: '1731166216636'

can this.attributes.id be used as a condition for a trigger that would match the event with data:

event_type: call_service
data:
  domain: automation
  service: reload

The template for the condition would be:

{{ trigger.event.data.service_data.id == this.attributes.id }}

But, I don’t think that’s going to work timing-wise.

Interesting. So trigger is something like:

    event_type: call_service
    event_data:
      domain: automation
      service: reload

Then condition using your template. What are the timing concerns?

The self-triggering you are looking for doesn’t happen in a basic test automation… I assume it’s something to do with the timing of the event being posted to the Event bus and the Automation actually being fully instantiated. It still requires a restart or edit & save.

Test Automation
alias: Test self triggering event
description: ""
triggers:
  - trigger: event
    event_type: call_service
    event_data:
      domain: automation
      service: reload
conditions:
  - condition: template
    value_template: "{{ trigger.event.data.service_data.id == this.attributes.id }}"
actions:
  - action: persistent_notification.create
    metadata: {}
    data:
      message: >
        Success. 
mode: single
conditions:
  - condition: trigger
    id:
      - set_attributes_on_save
  - condition: template
    value_template: '{{ trigger.event.data.service_data.id == this.attributes.id }}'
sequence:
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
    enabled: true
  - data:
      entity_id: '{{ satellite }}'
      default_background: '{{ default_background }}'
      mode: '{{ mode }}'
      weather_entity: '{{ weather_entity }}'
      view_timeout: '{{ view_timeout }}'
      do_not_disturb: '{{ do_not_disturb }}'
      status_icons: '{{ status_icons }}'
      assist_prompt: '{{ assist_prompt }}'
      mic_type: '{{ mic_type }}'
      status_icons_size: '{{ status_icons_size }}'
      font_style: '{{ font_style }}'
      use_24_hour_time: '{{ use_24_hour_time }}'
    enabled: true
    action: python_script.set_state

I am using this and it is triggered by the automation save event. I had this in place without the delay as the value changed in the blueprint input was not reflected. I added the delay in the hopes that things were happening too fast. Unfortunately it does not get past the delay on the trace which is odd but more importantly, the changed variables are not updated so this was for nothing.

I have found that if I make another change without the delay it will save the previous iteration. It is always one change behind. I am unsure what to do to get things in sync. I think this is still doable but I am going about it the wrong way. Any suggestions are most appreciated.