đŸ”č Auto-entities - Automatically fill cards with entities

Responding to myself here, because after digging some more I found a rather simple solution to this.

I added the “availability_topic” attribute to my MQTT cameras and made sure that Blu Iris sends the payload “online” as well as the image whenever it detects motion. My MQTT cameras will then have the state “unavailable” if no motion has been detected, this will change to “idle” as soon as it gets an image and “online” as its “availability_topic”. The latter was the key to the solution. Now the “picture-glance” cards for each of my MQTT cameras will only show if any movement has been detected, in which case it shows the snapshot from the last alert. Not sure if this is the easiest way to achieve this, but it works. :slight_smile:

Working code:

type: custom:auto-entities
card:
  type: picture-glance
  camera_view: auto
  entities: []
  camera_image: camera.front_door_mqtt
filter:
  include:
    - entity_id: camera.front_door_mqtt
      state: idle
show_empty: false

Thanks, yes that’s how it works. :slight_smile:

My issue was that I didn’t have something suitable to use as a filter, which I have now solved as per my post below (or above). Thanks again!

This is not a case for auto-entities.
If you have only ONE camera entity and you need to show the card for this only entity_id conditionally - use a standard conditional card.

I don’t know if there was an update, but suddenly this doesn’t work anymore:

type: vertical-stack
cards:
  - type: custom:mushroom-title-card
    subtitle: Lights switched on ({{states('sensor.aantal_ingeschakelde_lichten')}})
  - type: custom:auto-entities
    show_empty: false
    card:
      type: entities
    sort:
      method: name
      numeric: false
    filter:
      include:
        - domain: light
          options:
            type: custom:mushroom-template-card
            primary: '{{ states[''this.entity_id''].name.replace(''lights'', ''Lights'') }}'
            secondary: '{{ states[''this.entity_id''].state }}'
            icon: mdi:lightbulb
            icon_color: |-
              {% if states['this.entity_id'].state == 'on' %}
                orange
              {% else %}
                grey
              {% endif %}
            tap_action:
              action: toggle
            double_tap_action:
              action: none
      exclude:
        - state: 'off'
        - state: unavailable
        - attributes:
            friendly_name: Group -*
        - attributes:
            friendly_name: Sun blinds
        - attributes:
            friendly_name: LED*
        - attributes:
            type: browser_mod

When I remove the “options” part, it works
but I want the mushroom part.
Any idea ?

2 Likes

I have the exact same problem. It works without the options section included. It also only seems to not work for lights. I have another card that shows active motion sensors and it still works just fine.

1 Like

So nice! I was looking for something like this for so long :partying_face: !! But what I didn’t liked about it was the hardcoded speaker_group entities.

‘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”}]
}

The first part of the code is dynamic, so why not the speaker_group entities part?
Secondly, what I didn’t liked about it is that the “Master” is also shown :confused: :thinking::
Screenshot 2022-12-29 225202

So what I wanted is just to show the other speakers :grinning::
Screenshot 2022-12-29 225220

So here is my version :partying_face: :partying_face: :partying_face::

type: custom:auto-entities
show_empty: true
card:
  type: entities
filter:
  template: >-
    {%- set speakers=expand(integration_entities("sonos"))|selectattr("domain","eq","media_player")|map(attribute="entity_id")|list %}
    [ {% for speaker in expand(speakers) if speaker.attributes.group_members[0] == speaker.entity_id %}
    {%- set speaker_group = namespace(entities=[]) %}
    {%- for member in speakers if member!=speaker.entity_id %}
    {%- set speaker_group.entities=speaker_group.entities+[{'entity_id' : member,'name': state_attr(member,'friendly_name')}] %}
    {%- endfor %}
         {{
            {
              'type': 'custom:mini-media-player',
              'entity' : speaker.entity_id,
              'artwork' : 'cover',
              'group': false,
              'hide': {
                'power': true,
                'icon': true,
                'source': true
              },
              'speaker_group': {
                'platform': 'sonos',
                'sync_volume': true,
                'show_group_count': true,
                'entities': speaker_group.entities
              }
            }
         }},
    {%- endfor %} ]

And here in action :film_strip::
msedge_HLd12zqF61

2 Likes

Please let me know if you find a solution


Solved with the update of today :grinning:

How to change the name of an included entity? Using the options: option with name: ABC or friendly_name: ABC etc. did not work (while it does for secondary_level: xxx etc.).

“options” is a proper name

Just a typo. What’s the solution?

@Ildar_Gabdullin I have 7 camera entities, and I only want to show those that have an active alert. auto-entities now does that perfectly - despite you declaring that “this is not a case for auto-entities”. :slight_smile:

For one entity (as it was in your 1st post) I would use a conventional conditional card.
But if you have 7 cameras - agree absolutely, auto-entities is a good choice! Saves a lot of code, no problems with margins between hidden conditional cards.

so experimenting with the new Tile card, and aware this might not be the best card to show inside an entities card.

My hope is to auto populate all of my Area subviews with Tile cards of lights, switches, covers and media players.

started out simple, with a auto-entities/cluttering card that can be used on any of these subviews, only using the domain and the area, so the auto-entities in that decluttering card can do the works.

Since not all of the Tile cards have (the same) features, I struggled at first setting a manual line for those in the entities card (always start verbosely), but then wanted to add that to the auto-entities (via the decluttering
)

can not make it happen though, as on any test I did, the dashboard returns an error. this is what I tried in the end:

default:
  - features: null

card:
  type: custom:auto-entities
  card:
    type: entities
    title: '[[title]]'
    card_mod:
      class: class-header-margin
    show_header_toggle: false
  filter:
    include:
      - domain: '[[domain]]'
        area: '[[area]]'
        options:
          type: custom:hui-element
          card_type: tile
          features:
            - type: '[[features]]'

and this is what I get:

Is there a syntax issue I overlook, or cant we simply use the auto-entities card for this feature. Or, should I maybe try to add the whole line to a default value in the decluttering


  - type: custom:decluttering-card
    template: area_domain
    variables:
      - title: Library lights
      - area: library
      - domain: light
#       - features:
#           - type: '[[features]]' #light-brightness

fwiw, the auto-entities can better be combined with layout card in this case:

card:
  type: custom:auto-entities
  card:
    type: custom:layout-card
    layout_type: masonry
  filter:
    include:
      - domain: '[[domain]]'
        area: '[[area]]'
        options:
          type: tile

showing the Tile cards individually

Is it possible to only show groups? I put all my lights into groups. I only want to list groups.
Setting the domain as “groups” doesnt work :frowning: Any ideas?

I don’t use tile card myself, but I did test around before in my dev environment to auto-populate using auto-entities and layout-card and grid card. Here’s a snippet of auto-entities with 4 column grid card.

              - type: custom:auto-entities
                card:
                  type: grid
                  columns: 4
                  square: false
                card_param: cards
                unique: entity
                filter:
                  include:
                    - entity_id: "cover.*"
                      options:
                        type: 'tile'
                        features:
                          - type: cover-open-close
                        icon_tap_action:
                          action: more-info
                        tap_action:
                          action: toggle
                        color: var(--switch-entity-color)
                sort:
                  method: entity_id
                  ignore_case: true 

Or if you want them to each take one card space under eachother, then with grid column option 1 will get you this:

Not sure if this is what you’re after, but I figured I’d chime in what I tested with before.

thx, nice.

my specific issue was with the features of the Tile.

given the fact those auto-configured views, or even cards show way to many cards, or other cards without those options, I move back to a more carefully manually curated view


tbh, I was trying to use as much core as possible, but since Tile is still very basic, changed most of those to Mushroom already
 and still not sure I like those better than my long standing custom:button-cards views (and for some even the plain entities card)

that being said, my issue was with auto-entities auto-creating these views, and what I use it mostly for now is finding all the correct entities in an area
 then select and pick these for the manually configured cards


thx for your configs, Ill probably find some niceties there :wink:

did you ever resolve this?

I am also trying to auto fill a swiper, and it does work. With 1 caveat
 the swiper shows a button per swipe, and Id love to have 8 columns
 like in the grid above:

  - type: vertical-stack
    cards:

        - type: custom:button-card
          template: button_header
          name: Eettafel scenes

        - type: custom:auto-entities
          card:
            type: grid
            columns: 8
          card_param: cards
          filter:
            include:
              - domain: scene
                area: dining
                options:
                  type: custom:button-card
                  template: button_scene

  - type: vertical-stack
    cards:

        - type: custom:button-card
          template: button_header
          name: Buffet scenes

        - type: custom:auto-entities
          card:
            type: custom:swipe-card
            parameters:
              pagination:
                type: fraction #bullets #progressbar
              navigation:
              simulateTouch: true
              spaceBetween: 12
              preloadImages: false
              preventInteractionOnTransition: true
              preventClicks: true
              freeMode: true
              grabCursor: true
#               slidesPerView: auto
          card_param: cards
          filter:
            include:
              - domain: scene
                area: buffet
                options:
                  type: custom:button-card
                  template: button_scene

dont believe we should use a grid in that auto-entities swiper, because those interfere.

probably should take the route Thomas shows here: Template filters · thomasloven/lovelace-auto-entities Wiki · GitHub but I admit not having found the correct combination yet.

would be cool to finally be able to do so

edit/update

well isnt that rediculous
 reading that I find the solution, and it was there in front of my eyes. I had it even commented


slidesPerView: 8

!!!

1 Like

Thanks thomasloven for this wonderful custom card.

I`ve got a question. When it comes to rendering the different cards, I can use “this.entity_id” for the entity_id within an auto-entities “loop”.

I`m wondering how I can get the “loop index”, e. g. when I

include:
  - entity_id: sensor.waste_collection_*

and auto-enties “sees” 4 of this kind, how can I get the index auto-entities is currently working on.

In my special case Im using custom:button-cards within a horizontal-stack. To the cards I`m applying a border-left and border-right style, but I want to have only a border-right for the first card (first loop) and a border-left for the last card (last loop).

Sample Image:

I see two options 


You use the template option from auto-entities. Here you write JSON object which represents the array of card definitions. Here you can do anything in your jinja code and calc this “loop index”.

Another option would be to reduce the “space” between the cards to zero with card_mod. Thus red lines overlap and look like one.