Combine HACS frontend plugins auto-entities with custom secondaryinfo-entity-row ..?

Hi,

I have a card that lists all my “discord_user*” sensors. Now I want to combine this with the “secondaryinfo-entity-row”.

I came this far:

type: custom:auto-entities
card:
  type: entities
filter:
  include:
    - entity_id: /sensor.discord_user_*/
      options:
        type: custom:secondaryinfo-entity-row
        secondary_info: >
          <b>{% set game =  state_attr('sensor.discord_user_345507118276673547',
          'game') %} {{ game if game is not none else ' ' }}</b>
  exclude:
    - state: offline

It looks close to what I am aiming for:

Only problem is that in the code I referenced the entity ID manually:

        secondary_info: >
          <b>{% set game =  state_attr('sensor.discord_user_345507118276673547',
          'game') %} {{ game if game is not none else ' ' }}</b>

Is there a different way to write that code so I do not manually have to add the sensor id to get the game attribute?

I managed to derive from another script to adopt the template like this and also remove the “#1234” custom id in the friendly name:

What would be the correct syntax in that example now to include the “game” attribute if set?

I tried this without success:

type: custom:auto-entities
card:
  type: entities
filter:
  template: |-
    {% for state in states.sensor -%}
      {%- if state.entity_id | regex_match("sensor.discord_user_", ignorecase=False) -%}
        {{
          {
            'entity': state.entity_id,
            'name': state.attributes.friendly_name.split('#')[0],
            'type': custom:secondaryinfo-entity-row,
            'secondary_info': >
              <b>{% set game =  state_attr('state.entity_id', 'game') %} {{ game if
              game is not none else ' ' }}</b>
          }
        }},
      {%- endif -%}
    {%- endfor %}
  exclude:
    - state: offline
    - state: unavailable

You got this construction which is not working:

{{
  ..
  {% set xyz = ... %}
  {{ ...xyz... }}
}}

a template in template.
You should specify all expressions outside this {{…}}}:

{% set xyz = ... %}
{{
  ...xyz...
}}

Got it actually working now with this code:

type: custom:auto-entities
card:
  type: entities
  title: Discord Online
filter:
  template: |-
    {% for state in states.sensor -%}
      {%- if state.entity_id | regex_match("sensor.discord_user_", ignorecase=False) -%}
        {{
          {
            'entity': state.entity_id,
            'name': state.attributes.friendly_name.split('#')[0],
            'type': "custom:secondaryinfo-entity-row",
            'secondary_info': state_attr(state.entity_id, 'game')
          }
        }},
      {%- endif -%}
    {%- endfor %}
  exclude:
    - state: offline
    - state: unavailable
show_empty: false
2 Likes