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

Can anyone tell me why this template is not working in my auto-entities card? It works to produce a list in developer tools so Iā€™m at a loss.

type: custom:auto-entities
card:
  type: entities
  state_color: true
  title: ''
filter:
  template: |
    {{ states
    | selectattr('entity_id', 'in', integration_entities('zha'))
    | selectattr('state', 'in', ['off'])
    | map(attribute='entity_id')
    | map('device_attr', 'name_by_user') 
    | reject('match', 'None')
    | unique
    | list 
    }}

I am getting this as the card output:

The developer tools output is this:

As you are effectively using the standard HA entities card, you need to provide the entity_id under the entity: key, not the friendly name. Thatā€™s what the error is telling you anyway.

Test removing | map('device_attr', 'name_by_user')

Yes, that does produce something. I was hoping to have a list that would just show unique devices, though, and not the various entities for each device.

Appreciate it. I removed the "| map(ā€˜device_attrā€™, ā€˜name_by_userā€™) " as suggested by another commenter and it produces something. I was ultimately wanting a list of unique devices but maybe that is not possible with the auto-entities card.

You could build a list of the entities and include device_id. Then, get them by unique id.

Use the second code section in this post as an example
Devices and Areas - Configuration / Frontend - Home Assistant Community (home-assistant.io)

can it be that the Action-Taps in templtes doenst work any more? (you use it right? @Mariusthvdb )
when i add it, no enteties are there, without all fine

  template: |-
    {% for state in states.climate %}
      {%- if state.entity_id | regex_match("climate.*_klimaanlage", ignorecase=False) 
        and state.state in ["auto", "cool", "heat", "dry"] -%}
        {{
          {
            'type': "tile",
            'entity': state.entity_id,
            'name': state.attributes.friendly_name.split(' Klimaanlage')[0]
            'icon_tap_action': {'action':'toggle'}
          }
        }},
      {%- endif -%}
    {% endfor %}

@stephanschleichstr13 not sure why youā€™re tagging me, but you are missing a comma at the end of the name line

sorry for that, i tagged you because i saw it in your example :slight_smile:
The comma fixed it thank you.

Pulling my hair out a bit but think I may be missing something obvious.

Iā€™m trying to get a card that functions as follows:

A vertical stack containing a mushroom title card and an auto-entities card. When the auto-entities card is empty, the whole vertical stack should be hidden.

Any ideas as to how I can achieve this?

Possible solutions:

  1. Use a ā€œtemplateā€ option which contains a code for that mushroom card + code for a card with generated list. (could be rather cumbersome)
  2. Use card-mod to hide the whole stack: if list is empty ā†’ hide.
1 Like

depending on your auto-entities include filter/template, my suggestion would be to use a type: conditional and show/hide the stack based on that condition.

if youā€™d provide us with something to go on (what is your include filter) , we could actually help you :wink:

1 Like

Yep apologies @Mariusthvdb I was a bit vague.

This is the card I have at the moment which shows lights that are on in the office:

type: vertical-stack
cards:
  - type: custom:mushroom-title-card
    subtitle: Office
  - type: custom:auto-entities
    filter:
      include:
        - domain: light
          area: office
          state: 'on'
          options:
            tap_action:
              action: toggle
            type: glance
            entities:
              - this.entity_id
      exclude: []
    show_empty: false
    card:
      show_name: true
      show_icon: true
      show_state: true
      type: glance
      columns: 2

It returns a card that looks like this:
image

So I would like to hide the whole card including the subtitle.

My difficulty with your suggestion is that I donā€™t know what the condition would be. I suppose I could count the entities returned by my filter and save them to a helper, which would then be referenced by a conditional card?

Perhaps Iā€™m overcomplicating it with the vertical stack and can add a customisable title some other way?

this would be the template for the card: lights in the office are on.

{{area_entities('office')
  |select('match','light')
  |select('is_state','on')|list}}

You might even have a light.office without knowing it. If not, itā€™s easily created either as a template entity (see Ildar suggestion) or as a binary. Or a light even.

Ofc I can not comment on this being a good solution or not. If it is what you want, then just make it. simple as that

you mean something like this?:

again, that is possible yes, and requires some templating in JavaScript (as this is a custom:button-card).

In the end it only depends on what you want.

1 Like

with your help I landed on this configuration which works exactly as I hoped

type: vertical-stack
cards:
  - type: custom:mushroom-title-card
    subtitle: Office
  - type: custom:auto-entities
    filter:
      include:
        - domain: light
          area: office
          state: 'on'
          options:
            tap_action:
              action: toggle
            type: glance
            entities:
              - this.entity_id
      exclude: []
    show_empty: true
    card:
      type: custom:layout-card
      layout: custom:vertical-layout
visibility:
  - condition: template
    value_template: >
      {{ (area_entities('office') | select('match','light') |
      select('is_state','on') | list) | length > 0 }}
    state: 'True'

thank you!

1 Like

I really want the Mushroom Chips card to work for scenes. Now that we can use sections to filter for rooms I am not going to bother with using the selector like I was trying to do when I asked about this last year.

Here is the code I have:

type: custom:auto-entities
filter:
  include:
    - domain: scene
      area: Living room
  exclude: []
sort:
  method: friendly_name
card:
  type: custom:mushroom-chips-card
show_empty: true
card_param: chips

What am I missing for this to work?

try:

type: custom:auto-entities
card:
  type: custom:mushroom-chips-card
filter:
  include:
    - domain: scene
      area: dorm # replace with your area id
      options:
        type: light
card_param: chips
sort:
  method: friendly_name

I admit this was a terrible thing to test, and it seems to suffer the same lag as I experience using the new label option. Practically unusable.

However, I believe you should add the options: field with the type.

it will end up like this:

so not yet card_modded, or even repeating the icons I have customized for the scenesā€¦

which probably is a mushroom bug, as the icons are set using core customize, and should show like this:

is there a way to show the Device names per area? not entities by the actual device name? Im trying to use the new labels option in the drop down but nothing i type is working?

post what youā€™ve tried, and post screenshots of the name you want to show.

be careful to use the new label option, it is a real dashboard killer.
If you want to use labels, youā€™re better off using them in a template filter