Auto Entities Template including dynamically add additional entities Multiple-Entity-Row

Hi, maybe this can help some people:

I have configured sensors in groups (motion, window, etc…) and a top level group containing all groups.
This configuratio will list all these sensor and dynamically add additional ententies if available…

type: custom:auto-entities
card:
  type: entities
  title: Rörelse 2
filter:
  template: >
    {%- set groups = states.group.motion_multi_group.attributes.entity_id | list
    -%}

    {% for g in groups -%}
      {%- set sensors = expand(g) -%}
      {%- set sensorPrimaryList = sensors | selectattr('attributes.device_class', 'defined') | selectattr('attributes.device_class', 'search', 'opening|motion') | list -%}
      {%- set sensorAdditionalList = sensors | selectattr('attributes.device_class', 'defined') | selectattr('attributes.device_class', 'search', 'battery|illuminance|temperature') | list -%}
      
      {% for sp in sensorPrimaryList -%}
        {%- set nsAdditionalEntities = namespace(c = []) -%}
        {%- if sensorAdditionalList | count > 0 -%}
          {% for sa in sensorAdditionalList -%}
            {%- set sName = sa.attributes.device_class if 'device_class' in sa.attributes else 'n/a' -%}
            {%- set nsAdditionalEntities.c = nsAdditionalEntities.c + [
                                                        {
                                                          'entity': sa.entity_id,
                                                          'name': sName
                                                        }
                                                      ] 
            -%}
          {%- endfor %}
        {%- endif -%}
      {{
          {
            'entity': sp.entity_id,
            'type': 'custom:multiple-entity-row',
            'show_state': false,
            'state_color': true,
            'secondary_info': 'last-changed',
            'entities': nsAdditionalEntities.c
          }
        }},
      {%- endfor %}
    {%- endfor %}
sort:
  method: friendly_name
  numeric: true
4 Likes