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

Is there a good way to sort lights according to their features.
Like:

  1. Lights with color modes
  2. Lights with brightness control
  3. Lights with on/off only?

OK, so one last thing Iā€™m struggling with here if anyone can point the right way:

type: custom:auto-entities
show_empty: false
card:
 type: entities
filter:
 template: |
   [
   {% for theplayer in states.media_player 
        | selectattr('state', 'eq', 'playing') 
        | selectattr('attributes.group_members', 'defined')
        if theplayer.attributes.group_members[0] == theplayer.entity_id %} 
        {{
           {
             'type': 'custom:sonos-card',
             'startSection' : 'player',
             'entityId' : theplayer.entity_id,
             'sections' : ['player'],
             "card_mod": {
               "style": {
                 "sonos-player$": ".controls { display: none !important;}" "div.artwork { 
                 background-image:
                 {% if state_attr('media_player.living_room', 'source') == 'TV') %} 
                   url(/local/images/firetv.png) !important;
                 {% endif %}
                 }",
               }          
             },
           }
        }},
   {% endfor %}
   ]

In the above code, instead of evaluating this:

{% if state_attr('media_player.living_room', 'source') == 'TV' %} 
  url(/local/images/firetv.png) !important;
{% endif %}

Is there a way to use template variable to detect the current card instead?
e.g.

{% if ([theplayer.entity_id] == 'media_player.living_room' %} 
  url(/local/images/firetv.png) !important;
{% endif %}

OR

{% if theplayer.attributes.source == 'TV' %} 
 url(/local/images/firetv.png) !important;
{% endif %}

All templates must be moved on a higher level - do smth like

"style": {
                 "sonos-player$": ".controls { display: none !important;}" "div.artwork { 
                 background-image: {{BACKGROUND_IMAGE}}

and define BACKGROUND_IMAGE on a higher level.

Well, I got there, by a roundabout way - itā€™s pretty inefficient thoughā€¦

type: custom:auto-entities
show_empty: false
card:
  type: entities
filter:
  template: |
    [
    {% for theplayer in states.media_player 
         | selectattr('state', 'eq', 'playing') 
         | selectattr('attributes.group_members', 'defined')
      if theplayer.attributes.group_members[0] == theplayer.entity_id
      if theplayer.entity_id != 'media_player.living_room'
    %}
         {{
            {
              'type': 'custom:sonos-card',
              'startSection' : 'player',
              'entityId' : theplayer.entity_id,
              'sections' : ['player'],
              'heightPercentage': 70,
              'widthPercentage': 85,
              "card_mod": {
                "style": {
                  "sonos-player$":
                  ".controls { display: none !important;}",
                  "sonos-player$ sonos-player-header$": 
                  ".song { display: none !important;}"
                  ".artist-album { display: none !important;}",
                  "sonos-player$ sonos-player-header$ sonos-progress$": "|"
                  ".progress-bar { display: none !important;}" 
                  ".progress { display: none !important;}",
                }          
              },
            }
         }},
    {% endfor %}
    {% for theplayer in states.media_player 
         | selectattr('state', 'eq', 'playing') 
         | selectattr('attributes.group_members', 'defined')
      if theplayer.attributes.group_members[0] == theplayer.entity_id
      if theplayer.entity_id == 'media_player.living_room'
      if states('select.hublivingroom_activities') != 'power_off'
    %}
         {{
            {
              'type': 'custom:sonos-card',
              'startSection' : 'player',
              'entityId' : theplayer.entity_id,
              'sections' : ['player'],
              'heightPercentage': 70,
              'widthPercentage': 85,
              "card_mod": {
                "style": {
                  "sonos-player$":
                  ".controls { display: none !important;}" "div.artwork { 
                  background-image: 
                    {% if state_attr('media_player.living_room', 'source') == 'TV' %}
                      {% if is_state('media_player.living_room', 'playing') %}
                        {% if state_attr('remote.hublivingroom', 'current_activity') == 'Fire TV' %}
                          url(/local/images/firetv.png) !important;
                        {% elif state_attr('remote.hublivingroom', 'current_activity') == 'Virgin TV' %}
                          url(/local/images/virgin.jpg) !important;
                        {% elif state_attr('remote.hublivingroom', 'current_activity') == 'BluRay' %}
                          url(/local/images/bluray.png) !important;
                        {% elif state_attr('remote.hublivingroom', 'current_activity') == 'MAME' %}
                          url(/local/images/mame.png) !important;
                        {% elif state_attr('remote.hublivingroom', 'current_activity') == 'Nintendo' %}
                          url(/local/images/nintendo.png) !important;              
                        {% endif %}
                      {% endif %}
                    {% endif %};
                  }",
                  "sonos-player$ sonos-player-header$":
                  ".song { display: none !important;}"
                  ".artist-album { display: none !important;}",
                  "sonos-player$ sonos-player-header$ sonos-progress$":
                  ".progress-bar { display: none !important;}" 
                  ".progress { display: none !important;}",
                  
                }          
              },
            }
         }},
    {% endfor %}
    ]

I was going to use a template sensor for the images, but background image: requires a string, not object and it all got tricky - this doesnā€™t work.

background-image: 
{% if not is_state('select.hublivingroom_activities', 'power_off') %}
  {% if state_attr('media_player.living_room', 'source') == 'TV' %}
    url({{ states('sensor.tvsourceimage') }})
  {% endif %}
{% endif %};

hello everyone,
i fill an auto entities card with data from GTFS2

type: custom:auto-entities
filter:
  include:
    - entity_id: "*1262_0_3_local_stop_zone_wiener_linien_meidling"
card:
  type: custom:flex-table-card
  clickable: true
  max_rows: 30
  title: Meidling
  strict: true
  sort_by:
    - next_departures_lines
  columns:
    - hidden: true
      data: next_departures_lines
      modify: x.departure
    - name: Linie
      data: next_departures_lines
      modify: "'<ha-icon icon=' + x.icon + '></ha-icon>' + x.route"
    - name: Abfahrt
      data: next_departures_lines
      modify: x.departure
    - name: Richtung
      data: next_departures_lines
      modify: x.headsign
  css:
    table+: "padding: 0px 12px 12px 12px !important; width: 100%;"
    tbody tr td:first-child: "width: 60px;"
    tbody tr td:nth-child(2): "width: 55px;"
  card_mod:
    style:
      .: |
        ha-card {
          overflow: auto;
          max-height: 500px;
        }
      $: |
        h1.card-header {
          padding: 12px 0px 0px 12px !important;
          color: #727272 !important;
          line-height: 40px;
          font-weight: 500;
          font-size: 16px !important;
        }

this works but i need to filter out some data

sensor.at_49_1262_0_3_local_stop_zone_wiener_linien_meidling contains those attributes (simplified)

gtfs_updated_at: 2024-12-23T16:36:00.000897+00:00
device_tracker_id: zone.wiener_linien_meidling
offset: 0
next_departures_lines: 
- departure: '17:37'
  ...
  route: 62A
  ...
- departure: '17:44'
  ...
  route: 8A
  ...

how can i filter out all routes for 8A to only show 62A ?

Does anyone have an example of how to only show a particular entity without any label? While building out my environment, I want to highlight certain devices [edit: entities] that have not been labeled.

Entity & device are different things.

Try this:

{% set ns = namespace(ENTITIES_WITH_LABELS=[]) -%}
{%- for LABEL in labels() -%}
  {%- set ns.ENTITIES_WITH_LABELS = ns.ENTITIES_WITH_LABELS + label_entities(LABEL) -%}
{%- endfor -%}
{{states|rejectattr('entity_id','in',ns.ENTITIES_WITH_LABELS)|map(attribute='entity_id')|list}}
1 Like

Sweet, thanks. Will give it a try. And apologies, I am thinking ā€˜devicesā€™ that I want to classify, but using an availability entity to do so (and determine if it is critical, test, etc.).

There is also a native ā€œlabelā€ filter but users complained about it. So - use jinja.

1 Like

ā€˜Tryingā€™ to use Auto entities but is the GUI filter part broke?

I create a new card
Click on add filter group
In the Select property box I click something/anything from the dropdown but a few seconds later it vanishes and I have to pick it again and it wonā€™t progress past this.

Same on Edge and Chrome.

If I edit the code directly and say enter:-
filter:
include:
- domain: light

go back to visual editor it now shows:-
Property Entity domain
Value light

If I then try and select from the dropdown they seem to revert back to Entity domain or light, if I select property on the next box this again vanishes whatever I pick.

Itā€™s like itā€™s constantly updating but reading from the yaml code.

I want to use the visual editor as I donā€™t know all the code and options even though Iā€™ve just tried and frustratingly got nowhere :unamused:

Also if I enter something quicky say in value field click save it says saved but when I go back itā€™s notā€¦
Whereas if I do it via the code editor it saves it.

Same issue? Cannot add new filtering properties on old cards Ā· Issue #483 Ā· thomasloven/lovelace-auto-entities

1 Like

@thomasloven : Many thanks for this great development.

Iā€™m using auto-entities to show all timers/alarms that are currently set. Using the auto-entities card, everything looks normal.
However, to save space and combine these entities with other related information, I want to display them inside a regular entities card. Here, when I use auto-entities as the entity card type, the border and margin of the regular card is preserved:

Is there a way to configure auto-entities so that the entities from auto-entities embed into the standard entities card like regular entities? Alternatively, does someone know how to use card-mod correctly in this case?

type: custom:auto-entities
card:
  type: entities
entities:
  - entity: sun.sun
    name: xxx
  - entity: sun.sun
    name: yyy
filter:
  include:
    - domain: counter

As far as I can see, thatā€™s still a card inside a card:

image

YAML:

type: entities
entities:
- type: section
  label: entities
- entity: sun.sun
- type: section
  label: auto-entities
- type: custom:auto-entities
  card:
    type: entities
  entities:
    - entity: sun.sun
      name: xxx
    - entity: sun.sun
      name: yyy
  filter:
    include:
      - domain: counter
title: Auto-entities in entities card

I want the auto-entities to look just like the top where I simply put the entity as normal

No need to paste auto-entities inside entities card.

Can auto-entities show a dynamic list of sensors based on an input_number?

With a template trigger I have generated calender-events that are shown in template editor correct.
{{ state_attr(ā€˜sensor.calendar_eventsā€™, ā€˜scheduled_eventsā€™) | list }}

With a template sensor I have generated a list of single sensors based on the array above.
These sensors are named: sensor.calendar_event1, 2, 3, ā€¦ , 9

With the following regex filter I can show the hole list in a correct way.

filter:
  include:
    - entity_id: /^sensor.calendar_event[1-9]$/

My goal is now to show a dynamic list based on input_number.calendar_count
So, when this count is 1, only 1 entry shall be shown, when itā€™s 9, all entries shall be shown.
Is it possible to define this via a template, or is there a better solution?

Kind of

        {{ (
             states.sensor |
             selectattr('entity_id','search',.......) |
             map(attribute='entity_id') | list
           )[:states('input_number.xxxx') | int(0)] }}

FYI if you attempt to use auto-entities with grid section (not grid card) for section views, it royally screws up your browser. ~50 exceptions a second or so.

Because of dynamic height?
Some people reported similar about a stock entity-filter card in sections.

Not sure, I didnā€™t dig into it as it took firefox to itā€™s knees. Going to use the regular grid card to get the job done instead.