Event_template_reloaded not updating sensor

I would swear that the event used to be posted after the Template integration finished reloading (not before).

In fact, way back in 2021, I created an FR asking for such an event (signal when Template integration finished reloading) and then discovered it already existed in the form of event_template_reloaded. I used it successfully in several Trigger-based Template Sensors.

Back then, a Trigger-based Template entity’s state did not survive a restart. So I wanted an event, to trigger a Trigger-based Template Sensor, whenever the Template integration was finished reloading (like on startup and whenever the Template integration was reloaded to add a new Template entity). The Event Trigger became unnecessary after the Template integration was enhanced to store the state of a Trigger-based Template entity.

If the event now occurs during the reload phase, then that’s a Breaking/Backwards Incompatible change I don’t recall seeing in the release notes.

Maybe it was never documented in Breaking Changes and is the side-effect of some other PR. For example like when a PR sought to improve performance and expand ceased to sort its output. That seemingly innocuous change, buried in “All Changes”, quietly broke templates that relied on expand’s previous behavior.

I don’t know when, but it seems to work in core 2024.4.3.
Today I created this sensor to detect in case it would work in the future. To my surprise the sensor got initialized and the counter increases with every template reload:

# detect if the reloaded event works in the future 
- trigger:
  - platform: event
    event_type: event_template_reloaded
  binary_sensor:
  - unique_id: no_hist_last_event_reloaded
    name: no hist last event reloaded
    state: "{{ this.attributes.last|default(0) > 0 }}"
    attributes:
      last: "{{ this.attributes.last|default(0) + 1 }}"
1 Like

Yes, I also recently noticed that it now works properly (like it used to in the past) and the event is posted after Template entities are reloaded. Not sure which version corrected it.

Nice, you confirmed. I closed my core issue.

1 Like

Noticed a behaviour like “template not triggered by event” and posted this thread:
Trigger-based sensor: is it reliable to listen to event_template_reloaded?
Taras said that the issue seems to be fixed, and I wonder may be I am getting smth wrong.