AssertionError in an automation with state_change trigger

since I updated HA from version 2024.1.6 to version 2024.2.1 I have problems with an automation triggered by a change of state; completely randomly after a few hours it starts generating AssertionErrors hundreds of times per second, when I noticed it I had almost 5GB of log files.
The automation in question is the following:

alias: Media players - Event - Backup volume_level
mode: queued
max: 25
  - platform: event
    event_type: state_changed
  - condition: template
    value_template: >-
      {{'media_player.') }}
  - condition: template
    value_template: "{{ 'volume_level' in }}"
  entity_id: "{{ }}"
  - variables:
      volume_level: >-
        {{['volume_level'] | float(0.5)
        | round(2, default=2) }}
  - service: saver.set_variable
      name: "{{ entity_id }}.volume_level"
      value: "{{ volume_level }}"

The error log is as follows:

Logger: homeassistant
Source: helpers/
First occurred: 20:00:03 (1252 occurrences)
Last logged: 20:00:27

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/automation/", line 637, in async_trigger
    and not self._cond_func(variables)
  File "/usr/src/homeassistant/homeassistant/components/automation/", line 1009, in if_action
    if check(hass, variables) is False:
  File "/usr/src/homeassistant/homeassistant/helpers/", line 179, in wrapper
    result = condition(hass, variables)
  File "/usr/src/homeassistant/homeassistant/helpers/", line 787, in template_if
    return async_template(hass, value_template, variables)
  File "/usr/src/homeassistant/homeassistant/helpers/", line 767, in async_template
    info = value_template.async_render_to_info(variables, parse_result=False)
  File "/usr/src/homeassistant/homeassistant/helpers/", line 686, in async_render_to_info
    assert self.hass and _render_info.get() is None

The line that generates the error is the following:

{{'media_player.') }}

I don’t understand why it completely randomly starts to cause problems at a certain point.
I’ve been using that automation for over a year and it has never given me any problems.
Has anyone else encountered the same problem as me?

Whoever suggested you do that has played a mean trick on you. That Event Trigger will fire for every state-change produced by every entity in your system.

After it fires, the conditions check if the entity’s domain is media_player and if it was a volume change. Even if the entity isn’t a media_player, a trace is still produced. By default, a maximum of 10 traces are stored for each automation. However, it’s the error message produced by each failed triggering (for every state-change by every entity) that is bloating your log.

I suggest you consider re-designing the trigger.