Triggering Auto-Entities Refresh

I’m using auto-entities to generate a list of cards that map to ‘chores’ which have a status sensor with a particular state. These cards need to also have a tap_action that triggers a button press on a button entity which each chore has. The button press changes the state of the status sensor (this is what the issue arises from).

For example, one chore could be called MyChore, and would have a status entity called sensor.kc_kid_chore_status_mychore and a button entity called button.kc_kid_chore_approval_mychore.

As a result, my auto-entities card looks like this:

type: custom:auto-entities
card:
  type: grid
  columns: 1
  square: false
card_param: cards
filter:
  template: >-
    {% set STATES = states | selectattr('entity_id', 'in',
    integration_entities('KidsChores')) -%} {%- for STATE in STATES
      if '_chore_status_' in STATE.entity_id
      and STATE.state == 'claimed' -%}
      {%- set ENTITY_ID = STATE.entity_id -%}
      {%- set BUTTON_ID = STATE.entity_id.replace('sensor', 'button').replace("status", "approval") -%}
      {{ 
        { 
          'type': 'custom:mushroom-entity-card',
          'entity': ENTITY_ID,
          'tap_action': {
            'action': 'call-service',
            'service': 'button.press',
            'service_data': {
              'entity_id': BUTTON_ID
            }
          }
        } 
      }},
    {%- endfor %}
  exclude: []
show_empty: false

This all works, but my problem is that the template isn’t re-evaluated when the button is pressed, so the list of cards is incorrect for the next 10-20 seconds before some internal refresh timer kicks in.

Is there any way for me to tell auto-entities to re-evaluate the template in a script so that the list updates immediately, or a way to configure an include filter to have the same effect as the above code but get the advantage of auto-entities knowing to refresh the list when the status sensor changes value?

I am surprised that even works.

You have not closed your ‘for’ or opened your ‘if’ jinja2 statements.

You will also need an ‘endif’ before your ‘endfor’.

Not sure if this is the issue, but it is what I see right off.

Haha yeah it’s some sort of advanced Jinja2 that is beyond my comprehension but was aped from someone else and does work.

I did come to somewhat of a solution - I ended up generating a conditional card for each potential element and having the condition be the same as my template filter. That way the conditional reacts immediately to hide the element when it should be removed. Here’s the working card for a list of unapproved chores:

type: custom:auto-entities
card:
  type: grid
  columns: 1
  square: false
card_param: cards
filter:
  template: >-
    {% set STATES = states | selectattr('entity_id', 'in',
    integration_entities('KidsChores')) -%} {%- for STATE in STATES
      if '_chore_status_' in STATE.entity_id -%}
      {%- set ENTITY_ID = STATE.entity_id -%}
      {%- set BUTTON_ID = STATE.entity_id.replace('sensor', 'button').replace("status", "approval") -%}
      {{ 
        { 
          'type': 'conditional',
          'conditions': [
            {
              'condition': 'state',
              'entity': ENTITY_ID,
              'state': 'claimed',
            }
          ],
          'card': {
            'type': 'custom:mushroom-template-card',
            'entity': ENTITY_ID,
            'icon': "{{ state_attr('" + ENTITY_ID + "', 'icon') }}",
            'icon_color': 'light-blue',
            'primary': "{{ state_attr('" + ENTITY_ID + "', 'friendly_name') }}",
            'hold_action': {
              'action': 'call-service',
              'service': 'button.press',
              'service_data': {
                'entity_id': BUTTON_ID
              }
            }
          }
        } 
      }},
    {%- endfor %}
  exclude: []
show_empty: false