šŸ”¹ Auto-entities - Automatically fill cards with entities

It appears if use the template method of filtering, I canā€™t apply options to the generated glance or chip. (see my example trying to apply the tap_action)

Iā€™m trying to figure out what Iā€™m doing wrong here applying the options a filter type of template.

Iā€™ve tried this with mushroom ā€œchipsā€ and no luck there either.

Iā€™m trying to show recently turned off devices, and then just have a single tap to turn them back on if they were turned off by mistake and removed from a similar card that has only lights that are currently on.

Iā€™ve tried everything I can think of and I need some help.

type: custom:auto-entities
view_layout:
  grid-area: footer
show_empty: false
card:
  type: glance
filter:
  template: |
    {% for light in states.light %}
      {% if light.state == "off" and
        as_timestamp(now()) - as_timestamp(light.last_changed) < 60 
      %}
        {{ light.entity_id}},
      {% endif %}
    {% endfor %}
  options:
    tap_action:
      action: toggle
sort:
  method: last_updated
  reverse: true
  ignore_case: true

Edit: I should note this options section works for me when I use a include filter instead of a template filter.

Not possible ?

Similar question here on template filter and having options to be passed to the card.

I want to show all playing sonos players which are not in a group, or master of a group. Those playing in a group, but being no master should not show up.

This is what I got so far with @123 help:

type: custom:auto-entities
show_empty: false
card:
  type: entities
filter:
  template: |
    {% set ns = namespace(players = []) %}
    {% for player in states.media_player 
         | selectattr('state', 'eq', 'playing') 
         | selectattr('attributes.group_members', 'defined')
         if player.attributes.group_members[0] == player.entity_id %} 
      {% set ns.players = ns.players + [player.entity_id] %}
    {% endfor %}
    {{ ns.players }}

This works like a charm.

Now I want this to work with mini-media-player which expects the entity to be passed as entity and not as entities. Just replacing type: entities with type: custom:mini-media-player is not working.

Passing the option entitiy: this.entity_id is not possible as the template part seems not to accept an options section, as @zimmer62 has pointed out above.

Any hint appreciated how to the auto-entity card to play with the mini-media-player card.

1 Like

Untested:

  template: |
    {% for player in states.media_player 
         | selectattr('state', 'eq', 'playing') 
         | selectattr('attributes.group_members', 'defined')
         if player.attributes.group_members[0] == player.entity_id %} 
         {{
           {
             'type': 'your_card',
             'entity:' player.entity_id
           }
         }},
    {% endfor %}
1 Like

Check your code:
image
You cannot use the ā€œfilterā€ option inside another ā€œfilterā€ option.

This is genius. It was nearly there. I was able to figure that out.

This worked for me:

type: custom:auto-entities
show_empty: false
card:
  type: entities
filter:
  template: |
    [
    {% for player in states.media_player 
         | selectattr('state', 'eq', 'playing') 
         | selectattr('attributes.group_members', 'defined')
         if player.attributes.group_members[0] == player.entity_id %} 
         {{
            {
              'type': 'custom:mini-media-player',
              'entity' : player.entity_id,
              'artwork' : 'full-cover',
              'hide': {
                'power': true,
                'icon': true
              },
              'speaker_group': {
                'platform': 'sonos',
                'show_group_count': true,
                'entities': [
                  {
                    'entity_id': 'media_player.ralf',
                    'name': 'Ralf'
                  },
                  {
                    'entity_id': 'media_player.bad',
                    'name': 'Bad'
                  },
                  {
                    "entity_id": "media_player.kuche",
                    "name": "KĆ¼che"
                  },
                  {
                    "entity_id": "media_player.wohnzimmer",
                    "name": "Wohnzimmer"
                  },
                  {
                    "entity_id": "media_player.eltern",
                    "name": "Eltern"
                  },
                  {
                    "entity_id": "media_player.annika",
                    "name": "Annika"
                  },
                  {
                    "entity_id": "media_player.gaste",
                    "name": "GƤste"
                  }
                ]
              }
            }
         }},
    {% endfor %}
    ]

1 Like

Please help. This is kinda working in Developer tools > Template, but not in auto-entities card:

type: custom:auto-entities
card:
  type: entities
filter:
  template: |
    {% for zone in
      [
        {
          'friendly_name': '000001',
          'valve_position': states('sensor.04_000001_heat_demand'),
          'climate': states.climate.ramses_cc_01_154356_00
        },
        {
          'friendly_name': '000002',
          'valve_position': states('sensor.04_000002_heat_demand'),
          'climate': states.climate.ramses_cc_01_154556_00
        }
      ] | sort(attribute='valve_position', reverse=true)
    %}{{ zone.climate }},{% endfor %}

So Iā€™m sorting by one attribute, but I want to show another entity as the correct one in the end.

and no cardā€™s type specified.

first 3 lines?

type: custom:auto-entities
card:
  type: entities

My bad. Awfully sorry.

Show output of dev tools.

When I finally get the courage to ask for help after 2 days of trying a gazillion of things, I just solved it.
It was missing entity_id in zone.climate.entity_id.

So this works as wanted:

type: custom:auto-entities
card:
  type: entities
filter:
  template: |
    {% for zone in
      [
        {
          'friendly_name': '000001',
          'valve_position': states('sensor.04_000001_heat_demand'),
          'climate': states.climate.ramses_cc_01_154356_00
        },
        {
          'friendly_name': '000002',
          'valve_position': states('sensor.04_000002_heat_demand'),
          'climate': states.climate.ramses_cc_01_154556_00
        }
      ] | sort(attribute='valve_position', reverse=true)
    %}{{ zone.climate.entity_id }},{% endfor %}

Now the last and final and hardest part:
I want to rename this entity (only in card)
Im totally clueless now.

This creates a list of ids, kind of:

- sensor.entity_1
- sensor.entity_2
...

What you need is:

- entity: sensor.entity_1
  name: name_1
- entity: sensor.entity_2
  name: name_2
...

Find examples here with generated cards (mine, for instance).
Even the last example of another person may be used.

Is this somehow possible with template: instead of include:?

EDIT: Holy jesus, I think I just managed it:

type: custom:auto-entities
card:
  type: vertical-stack
card_param: cards
filter:
  template: |
    {%- for x in ... -%}
      {{ { 'type': 'history-graph',
           'hours_to_show': 12,
           'entities': [x.entity_id], } }},
    {%- endfor -%}

If it works, it works no?

The big question is how to pass name: to change entityā€™s name?

EDIT2: Holy moly I did it! This should be pinned somewhere: (dynamic/ā€œthere when need themā€ history-graphs)

type: custom:auto-entities
card:
  type: vertical-stack
card_param: cards
filter:
  template: |
    {%- for x in ... -%}
      {{ { 'type': 'history-graph',
           'hours_to_show': 12,
           'entities':
        [ { 'entity': x.entity_id,
            'name': 'new_name' } ] } }},
    {%- endfor -%}

EDIT3: This is how to do it, if you want a clickable entity before each history-graph (so entity list>history_graph>entity list>history_graph>ā€¦:

type: custom:auto-entities
card:
  type: vertical-stack
card_param: cards
filter:
  template: |
    {%- for x in ... -%}
      {{- { 'type': 'entities',
            'title': 'title',
            'entities':
        [ { 'entity': x.entity_id,
            'name': 'new_name' } ] } -}},
      {{- { 'type': 'history-graph',
            'title': 'title',
            'hours_to_show': '12',
            'entities':
        [ { 'entity': x.entity_id,
            'name': 'new_name' } ] } -}},
    {%- endfor -%}

Hello,
Is it possible to show an attribute of a filtered entity ?
I want to display the firmware version of all my Shelly devices, i can get every ā€œfirmware updateā€ entities in my list but it show me ā€œup to dateā€ instead of the version of the firmware.
Thanks !

I guess itā€™s not possible ?

Assume you have ONE entity (let it be sensor.xxxx) - so there is no need to filter.
Post a short code (MWE) for the card you need with an attribute.
Then I will tell you what to do next.

This one for exemple :

type: entities
entities:
  - type: attribute
    entity: update.antenne_firmware_update
    attribute: installed_version

Great.
Post a code for auto-entities card displaying your ā€œupdateā€ entities - without showing attributes.
Then I will show you where to add attribute ))

Sorry. :sweat_smile:

type: custom:auto-entities
card:
  type: entities
  title: Mise Ć  jour
  icon: mdi:download-network-outline
  show_header_toggle: false
sort:
  method: name
unique: true
filter:
  include:
    - name: /Update/
      integration: shelly

Now add this as a part of filter:

    - name: /Update/
      integration: shelly
      options:
        type: attribute
        attribute: installed_version
1 Like

THANKS ! :heart_eyes: :heart_eyes: :heart_eyes:

1 Like