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

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.

1 Like

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.

All,

I am looking for guidance how I can adjust the below code to change the fixed value (ā€˜100ā€™) for ā€œstate:ā€ to the an input_number I have defined ('input_number.battery_low_threshold).
This would allow me to easily change the threshold at what battery charge level the devices get listed.

type: custom:auto-entities
show-empty: false
filter:
  include:
    - attributes:
        device_class: battery
      state: '<= 100'
      options:
        tap_action:
          action: none
  exclude:
    - entity_id: '*iphone*'
card:
  type: custom:battery-state-card
  title: ''
  sort_by_level: asc
  icon: 'mdi:signal'
  unit: '%'
  color_gradient:
    - "#ff0000" # red
    - "#ffff00" # yellow
    - "#00ff00" # green

I have read many posts, threads, ā€¦ but cannot find how to change the

ā€¦state: ā€˜<= 100ā€™ to something along the lines of
ā€¦state: ā€˜<= input_number.battery_low_thresholdā€™

Any help is greatly appreciated.

For future reference in case anyone is looking for the solution, please find my code (with the help of many more reads and q&aā€™s). I needed to transform the auto-entities into a template-based include.

              - type: custom:auto-entities
                show-empty: false
                filter:
                  template: >
                    {% set sensors = states.sensor 
                      | rejectattr('state', 'in', ['unavailable', 'unknown']) 
                      | selectattr('attributes.device_class', 'defined') 
                      | selectattr('attributes.device_class', '==', 'battery') 
                      | selectattr('attributes.unit_of_measurement', 'defined') 
                      | selectattr('attributes.unit_of_measurement', '==', '%') 
                      | list %}
                    {% set low = sensors 
                      | map(attribute='state') 
                      | map('int') 
                      | select('<=', int(states('input_number.battery_low_threshold'))) 
                      | map('string') | list %}
                    {{ sensors 
                      | selectattr('state', 'in', low) 
                      | map(attribute='entity_id') | list }}

are you sure this couldnā€™t be used?

        {% set threshold = states('input_number.battery_alert_level')|float(0) %}
        {% for s in states.sensor
           |selectattr('attributes.device_class', 'defined') 
           |selectattr('attributes.device_class','eq','battery')
           if s.state|is_number and s.state|float(0) < threshold %}
          {{s.entity_id}}
        {%- endfor %}

itā€™s what I have and works for me.

or, do this:

        {% set threshold = states('input_number.battery_alert_level')|float(0) %}
        {% for s in expand('group.battery_sensors_auto')
           if s.state|is_number and s.state|float(0) < threshold %}
          {{s.entity_id}}
        {%- endfor %}

based on an auto-created group at startup

secret: even this works:

    filter:
      template: >

       {% set threshold = states('input_number.battery_alert_level')|float(0) %}
       {% for s in states.sensor|selectattr('attributes.device_class','eq','battery')
          if s.state|is_number and s.state|float(0) < threshold %}
         {{s.entity_id}}
       {%- endfor %}

though in dev tools template that errors (because of the |selectattr('attributes.device_class', 'defined') not being used)

I have created an auto-entities (which is awesome!) driven dashboard for my docker images, which starts as follows:

type: custom:auto-entities
card:
  type: entities
  title: Containers
filter:
  template: |
    {% for CONTAINER in states.sensor -%}
      {%- if CONTAINER.entity_id | regex_match('sensor.docker.*state') -%}
        {{
          {
            'type': 'custom:vertical-stack-in-card',
            'title': CONTAINER.entity_id.replace('sensor.docker_', '').replace('_state',''),
            'cards':
              [
                {
                'type': 'horizontal-stack',
                'cards':
                  [
                    {
                      'type': 'gauge',
                      'entity': CONTAINER.entity_id.replace('state', 'cpu'),
                      'min': 0,
                      'max': 100,
                      'name': 'CPU (Cores)',
                      'severity':
                        {
                          'green': 0,
                          'yellow': 20,
                          'red': 40
                        },  
                    },

I want to hide the gauge if it is not running, so tried to put in code like the following:

type: custom:auto-entities
card:
  type: entities
  title: Containers
filter:
  template: |
    {% for CONTAINER in states.sensor -%}
      {%- if CONTAINER.entity_id | regex_match('sensor.docker.*state') -%}
        {{
          {
            'type': 'custom:vertical-stack-in-card',
            'title': CONTAINER.entity_id.replace('sensor.docker_', '').replace('_state',''),
            'cards':
              [
      {%- if CONTAINER.entity_id == 'running') -%}
                {
                'type': 'horizontal-stack',
                'cards':
                  [
                    {
                      'type': 'gauge',
                      'entity': CONTAINER.entity_id.replace('state', 'cpu'),
                      'min': 0,
                      'max': 100,
                      'name': 'CPU (Cores)',
                      'severity':
                        {
                          'green': 0,
                          'yellow': 20,
                          'red': 40
                        },  
                    },
      {%- endif -%} 

But however I have tried formatting it isnā€™t working. Is it possible to do what I am trying to do as an approach, and any examples, or do I need to perform the ā€˜ifā€™ at the top and then have duplicated code for the other entities I want to show?

Thanks for any advice!

does anyone know of a template filter or other way that I can handle media player groups? for example, I have 3 sonos speakers grouped right now, and all 3 show on my auto-entities ā€˜playing mediaā€™ card:


anyone else have a similar card or situation and have an idea to use auto entities to show just what is playing, but only one group? I was thinking to only show the group controller/master (should be first in the group attribute list, right?) but not sure how to template that out

Two questions I canā€™r find the answer to:

  • I seem to be able to only use options: within an include: and not if I filter by template: . This causes some issues if you want to use custom cards for the layout. Is this by design? Any workaround for that (beside trying to replicate the filter in the include section)?

  • group: can be used as a filter. But only when the group is also called group.xxxxx. I have for instance a sensor created by ā€˜powercalcā€™ that declares as a group in the attributes. Is this by design? Any workaround for that ?

options: template

you need to include the options inside your template filter. no way around that, but it can be done :wink:

check something like:

    - type: custom:auto-entities
      card:
        type: grid
        title: Threshold buttons template
        columns: 4
      card_param: cards
      filter:
        template: >-
          [{% set threshold = states('input_number.power_threshold')|float(0) -%}
          {% for s in states.sensor|selectattr('entity_id','search','_actueel')
           if s.state|float(0) > threshold -%}
            {{
              {
                'type': 'custom:button-card',
                'entity': s.entity_id,
                'template': 'custom_ui_hack_for_button_card_template'
              }
            }},

          {%- endfor %}]
      sort:
        method: state
        numeric: true

Not explicit options: configured, but it shows how to build the object you need. note I made an extra button-card template to throw in all cofiguration I needed for that card:

custom_ui_hack_for_button_card_template:
  aspect_ratio: 1/1
  template:
    - support_custom_ui
    - styles_name_left
    - styles_card
    - styles_cf_notification
    - styles_img_cell
    - plot
    - support_custom_ui_notification_border
  styles:
    card:
      - background-color: var(--card-background-color)
      - color: var(--primary-color)
  custom_fields:
    notification: >
      [[[ var unit = (entity.entity_id.includes('_actueel')) ? ' W' : ' %';
          return entity.state + unit; ]]]

powercalc:

no workaround possible. we explored that and its because of the way the expand functionality is implemented in HA. btw, you can also expand light groups, with domain light.

This is the HA code causing that: core/template.py at d22e670334be90c84bc3f2d446e170d28b0f44b0 Ā· home-assistant/core Ā· GitHub

if statement checking whether the entity belongs to group. or is created by the group integration (core integration HA). (which is the case for light groups.)

I have one solution which is described here.

Very cool!!, could you show the code of the button_scene template?

This is not entirely true. This was specifically about the code for the expand functionality in templates.
In auto-entities card the relevant code is here, lovelace-auto-entities/src/filter.ts at ddff75935810065a110337621b4334f111fddf22 Ā· thomasloven/lovelace-auto-entities Ā· GitHub. Which looks at the entity_id attribute. This can relatively easy be extended by also looking at entities I assume, but I donā€™t know if thomas would like that.
Alternatively I could change powercalc code attribute from entities to entity_id, but that would break a lot of installations of users depending on that, and will cause a lot of support questions.

ofc, that is more precise.

we should also add, that using the template function in Powercalc was covered, and that too has its quirks, because at startup those are evaluated not in time for the sensors to be initialized correctly.

All in all, if the latter would be an issue, it might be optimal if you would be able to do what you dread mostā€¦understandably.
Then again, you might have more leverage with Thomas than we do here, so it wouldnā€™t hurt to discuss that privately :wink:

sure:

button_scene:
  template: round_button
  tap_action:
    action: call-service
    service: scene.turn_on
    service_data:
      entity_id: entity

which uses:

round_button:
#   template: styles_tooltip
  show_entity_picture: true
  size: 100%
  show_name: false
  tooltip: >
    [[[ return entity.attributes.friendly_name; ]]]
  styles:
    card:
      - border-radius: 100%
      - padding: 0

List is not sortedā€¦what am I missing ?

impossible to seeā€¦

dont post screenshots of your config, but code correctly formatted in a code block (use </> in editor)

type: horizontal-stack
cards:
  - type: custom:auto-entities
    show_empty: false
    card:
      type: picture-entity
      show_state: true
      show_name: true
      camera_view: live
    filter:
      include:
        - entity_id: camera.backyard01

So Iā€™ve recently set up home assistant and am planing on using auto-entities to show the ā€œcurrentā€ camera when motion is detected. Unfortunately I canā€™t seem to use this with the picture-entity card since auto-entities creates things formatted ā€œ- entity: entity_idā€ and I am not sure on how to just get the entity_id since picture-entity accepts only a single entity (I have it set to match one thing now just for testing before dealing with filters).
Does anyone have this working with picture-entity and can share your config? Or explain how to get just the entity_id for the things that auto-entities finds?