🔹 Auto-entities - Automatically fill cards with entities

A simple way to show an alternative card if a filter gives an empty list:

type: custom:auto-entities
card:
  type: entities
filter:
  template: >-
    {% set lights =
    states.light|selectattr('state','==','on')|map(attribute='entity_id')|list -%}
    {%- if lights|length != 0 -%}
      {%- for LIGHT in lights -%}
        {{
          {
            'entity': LIGHT,
            'secondary_info': 'last-updated'
          }
        }},
      {%- endfor -%}
    {%- else -%}
      {{
        [
          {
            'type': 'custom:hui-element',
            'card_type': 'markdown',
            'content': 'all lights off',
            'card_mod':
            {
              'style': 'ha-card {border: none;}'
            }
          }
        ]
      }}
    {%- endif %}

изображение

изображение

OR - in most cases you may just use a native “else” option:

  - type: custom:auto-entities
    card:
      type: entities
    filter:
      template: >-
       ....
    else:
      type: markdown
      content: all lights off

some more examples

2 Likes