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

Hi,
I have created a minimalist UI popup card using auto-entities and the button card integrations that shows all power and light switches in a specified area (the area name is passed as a variable) and turn them on/off. This works great so thank you for the awesome integration.

I would like to enhance this by grouping the entities by their respective device. A light or power outlet is represented as device in HA which contains an entity for each individual switch (between 1 and 4 per device).

I can create the a custom button card that uses auto-entities to populate a grid with a button card for each switch. I can then enhance it with information from sensors that are also part of the device, such as the amount of power being consumer.

However, to do this I need to populate a list of devices (not entities) in the specified area. I noticed that auto-entities can be nested by passing a list of entities. Is there any way to have auto-entities return a list of devices (instead of entities) and then pass it into another instance of auto-entities?

I am guessing that it canā€™t (because then it would be called ā€œauto-entities-or-devicesā€ but thought I would ask.

hope, someone can help me with templating.
ive setup a rest sensor to retrieve current connected teamspeak clients:

sensor:
  - platform: rest
    scan_interval: 5
    resource: http://ts3.example.url:10080/1/?clientlist
    verify_ssl: false
    headers:
      x-api-key: "{{ states('input_text.api') }}"
    name: "TS3 Online"
    value_template: "{{ value_json.body | map(attribute='client_nickname') | join(', ') }}"
    json_attributes:
      - body

with these results as attributes:

image

then i have setup some template sensors for up to 5 online clients generated automatically:

template:
  - sensor:
      - name: "{{ state_attr('sensor.ts3_online', 'body')[0]['client_nickname'] }}"
        unique_id: "ts3_0"
        state: "{% if not state_attr('sensor.ts3_online', 'body')[0]['client_nickname'] or state_attr('sensor.ts3_online', 'body')[0]['client_nickname'] == 'serveradmin' %}OFF{% else %}ON{% endif %}"
        attributes:
          image: /local/images/ts3_{{ state_attr('sensor.ts3_online', 'body')[0]['client_nickname'] }}.jpg
      - name: "{{ state_attr('sensor.ts3_online', 'body')[1]['client_nickname'] }}"
        unique_id: "ts3_1"
        state: "{% if not state_attr('sensor.ts3_online', 'body')[1]['client_nickname'] or state_attr('sensor.ts3_online', 'body')[1]['client_nickname'] == 'serveradmin' %}OFF{% else %}ON{% endif %}"
        attributes:
          image: /local/images/ts3_{{ state_attr('sensor.ts3_online', 'body')[1]['client_nickname'] }}.jpg
      - name: "{{ state_attr('sensor.ts3_online', 'body')[2]['client_nickname'] }}"
        unique_id: "ts3_2"
        state: "{% if not state_attr('sensor.ts3_online', 'body')[2]['client_nickname'] or state_attr('sensor.ts3_online', 'body')[2]['client_nickname'] == 'serveradmin' %}OFF{% else %}ON{% endif %}"
        attributes:
          image: /local/images/ts3_{{ state_attr('sensor.ts3_online', 'body')[2]['client_nickname'] }}.jpg
      - name: "{{ state_attr('sensor.ts3_online', 'body')[3]['client_nickname'] }}"
        unique_id: "ts3_3"
        state: "{% if not state_attr('sensor.ts3_online', 'body')[3]['client_nickname'] or state_attr('sensor.ts3_online', 'body')[3]['client_nickname'] == 'serveradmin' %}OFF{% else %}ON{% endif %}"
        attributes:
          image: /local/images/ts3_{{ state_attr('sensor.ts3_online', 'body')[3]['client_nickname'] }}.jpg
      - name: "{{ state_attr('sensor.ts3_online', 'body')[4]['client_nickname'] }}"
        unique_id: "ts3_4"
        state: "{% if not state_attr('sensor.ts3_online', 'body')[4]['client_nickname'] or state_attr('sensor.ts3_online', 'body')[4]['client_nickname'] == 'serveradmin' %}OFF{% else %}ON{% endif %}"
        attributes:
          image: /local/images/ts3_{{ state_attr('sensor.ts3_online', 'body')[0]['client_nickname'] }}.jpg

so they got these attributes:

image: /local/images/ts3_rog.jpg
friendly_name: rog

i have tried to use auto-entities to filter out these clients, but im unable to pass the ā€œimageā€ attributes to use the image as badge image. Currently im trying entity-filter with badge-cards, but the image url does not workā€¦only if i type the url directly:

type: entity-filter
entities:

  - entity: sensor.template_ts3_0
    image: "{{ state_attr('sensor.template_ts3_0', 'image') }}"

state_filter:
  - 'ON'
card:
  type: custom:badge-card
  card_mod:
    style: |
      div#badges {
        display: flex;
        justify-content: space-around;
        font-size: 1.5em;
      }

resulting in an empty badge.

hopefully anyone help me to pass the ā€œimageā€ attribute to a card, eventually with auto-entities?

thank you!

From my own use, and examples on here, it appears that this card ā€˜forcesā€™ a line break between each row.

Is there any way of removing that whitespace within the card configuration?

Auto-entities Card

Markdown card with whitespace removed
Screenshot 2023-05-24 at 07.38.18

Further to my question in my last post above, about removing whitespace between rows, it appears that altering the font size only alters the spacing between the icons and not the font size or row spacing of the text (examples below).
So, to bump my original question, is it possible to remove whitespace/line breaks between rows and how can I solve this issue of custom font size only resizing space between icons and not text?

Font size = 12px
Screenshot 2023-05-29 at 08.18.45

Font size = 8px
Screenshot 2023-05-29 at 08.18.05

card-mod thread ā†’ 1st post ā†’ link at the bottom ā†’ how to manage space between rows

1 Like

Do you mean this thread? card-mod

I canā€™t find any link or post with that reference in the whole thread.

EDIT: Found the link credited to you. Thank you.

Iā€™ve added the code suggested but itā€™s not having any effect on the card row spacing.

This is my card code:

type: custom:auto-entities
card:
  card_mod:
    style: |
      hui-sensor-entity-row $: 
        hui-generic-entity-row {
          height: 14px;
          }
  show_header_toggle: false
  title: Average
  type: entities
  state_color: true
filter:
  include:
    - attributes:
        device_class: battery
      state: < 70
  exclude:
    - name: /[Ll]ow/
    - name: /[Ss]tate/
    - state: < 20
sort:
  method: state
  numeric: true
show_empty: false

Start testing new things with a SIMPLER case - just an Entities card (w/o auto-entities).
And check again your card-mod code, it was not copied /pasted correctly & has errors.

Iā€™ve got a sensor (specifically a RESTful Sensor) thatā€™s pulling data on my CNC, but most of the time the laptop itā€™s pulling the data from is off and thus the sensor doesnā€™t get created in HA whenever I happen to restart it.

Is there any way to filter it out when this is the case? Iā€™ve used the following filters:

filter:
  include: []
  exclude:
    - state: unavailable
    - state: unknown
    - state: none

But it still shows this on my card:
image

Thanks in advance!

Iā€™d like to sort based on the state of the entity or the attribute days_until. I wonā€™t get it to work:

type: custom:auto-entities
card:
  type: entities
  title: AFVAL
entities:
  - sensor.rmn_pmd
  - sensor.rmn_papier
  - sensor.rmn_gft
  - sensor.rmn_restafval
show_empty: 'yes'
unique: 'yes'
sort:
  method: attribute
  attribute: days_until
  numeric: false
  reverse: false

Am I supposed to use the friendly name of the attribute or the one in the code : ATTR_DAYS_UNTIL ? I tried both.

The sorting by date/state seems the easiest way to go, but I canā€™t find the correct code for that

You need to use an attribute name which is displayed in Dev tools ā†’ set state.

forgot my brain fluke in the deleted post, so entangled in getting custom_template to work, I forgot we are seeking for entity_idā€™s only in auro-entities :wink:

why cant I do this:

    - type: custom:auto-entities
      card:
        type: entities
      filter:
        include:
          - integration: nederlandse_spoorwegen

while I can do

{{integration_entities('nederlandse_spoorwegen')}}

and:

      filter:
        template: >
          {{integration_entities('nederlandse_spoorwegen')}}

this is not a config_entry integration, still in yaml, but since the dev tools template shows fine, I would have expected auto-entities to list these too?

optimally, I would even set option on the entities

    - type: custom:auto-entities
      card:
        type: entities
      filter:
        include:
          - integration: nederlandse_spoorwegen
            options:
              type: custom:template-entity-row
              secondary: >
                Aankomst: {{state_attr(config.entity,'arrival_time_planned')}}

but first need to get the entitiesā€¦

using a template filter is somewhat complexer:

      filter:
        template: >
          {%- for train in expand(integration_entities('nederlandse_spoorwegen')) -%}
          {{
            {
              'type': 'custom:template-entity-row',
              'entity': train.entity_id,
              'secondary': 'Aankomst: ' + train.attributes.arrival_time_planned
            }
          }},
          {%- endfor -%}
2 Likes

I know this is a year and a half old. But, I am currently in the same situation.

I have a need to pass attribute information of the object being passed to a decluttering card. I have been searching for days.

Were you able to get an answer on this? ID might be enough and I could possibly work with that. But, if I could go further here, it would simplify the other end :slight_smile:

1 Like

Hey Guys,
I am struggeling with the style of Mushroom Chips within the auto-entities card. Does anyone have any pointers as to how I can style the chips card? Iā€™ve tried any combination of classes that I can think of (and Inspect in Chrome shows me).

Here is the code:

  - type: custom:auto-entities
    show_empty: false
    card:
      type: custom:mushroom-chips-card
      alignment: center
      card_mod:
        style: |
          ha-card {
          margin-top: 1px;
          margin-bottom: 1px;
          border: 0px !important;
          background: none !important;
          }
    card_param: chips
    sort: name
    filter:
      include:
        - options:
            type: light

Outcome is:
image

What I want it to look like:
image

Whatā€™s odd to me is that the style in working for margin but not for border och background. Mushroom Chips that are not within the auto-entities card I can style with the css above.

Thanks for all your ideas!
Rob

I have this code:

- type: 'custom:auto-entities'

    card:
      type: entities
    filter:
      include:
        - entity_id: sensor.recycleapp_vuilnis_restafval
        - entity_id: sensor.recycleapp_vuilnis_papier
        - entity_id: sensor.recycleapp_vuilnis_pmd
          options:
            type: custom:button-card
    sort:
      method: state

This is my result

How can I change pmd so it is like the other 2 ?

Hi @Ildar_Gabdullin,

i hope its ok to ping you. I see you are very advanced when it comes to templating.
I want to have an auto entities card which shows all turned on lights grouped by the area.

This is what i have so far:

type: custom:auto-entities
show_empty: false
card:
  type: entities
filter:
  template: |-
    {% set filter = ['light.light'] %}
    {% set area_filter = ['area'] %}
    {% set areas = states
      | selectattr('attributes.device_class', 'defined')
      | map(attribute='entity_id')
      | map('area_id') | unique | reject('none') | list %}
    {%- for area in areas -%}  
        {%- if area not in area_filter -%}{{
        { 'type': 'custom:mushroom-title-card',
          'title': area, }}},
      {%- endif -%}    
    {% set lights = expand(states.light) 
      | selectattr('state', 'eq', 'on')
      | selectattr('entity_id', 'in', area_entities(area)) 
      | rejectattr('entity_id', 'in',filter)       
      |list -%}   
    {%- for light in lights -%}
      {{{'type': 'custom:mushroom-light-card',
          'entity': light.entity_id,
          'use_light_color': 'true',
          'show_brightness_control': 'true',
          'show_color_control': 'true',
          'collapsible_controls': 'true',
          'show_color_temp_control': 'true', 
        }}},     
    {%- endfor %} {%- endfor %}

Problem with this is that the mushroom title card is always shown even when no light is turned on there. Of course because its not the same loop. i thought of creating some vertical stacks which contains the light cards. with this i could have a grouped card with titles which will hide when no light is turned on.

i tried many things and searched the whole topic here but couldnt find anything. is there a way to have nested cards in this templates?

big thanks!

Hi! Actually pinging is not allowed here in general.
Anyway, the template you created before the ā€œ{%- for light in lights -%}ā€ part you may check in ā€œDev tools ā†’ Templateā€; about the ā€œmushroomā€ part I cannot say a thing - never used them (((

What does that yield when no lights are on? Change that so it returns nothing if no lights are on. You are saying:

  1. Give me the areas and create a title card
  2. Now give me all lights ā€œonā€ in that area and show them.

Of course areas that have no lights on will have titles shown.

Perhaps a better logic would be:

  1. Create a list of all lights on and their areas
  2. Create something for each unique area and show the lights on

The script itself works. But the problem is that I have two loops. One for areas and one for lights.

I think easiest way to fix this would be to have only one loop which gives me a vertical-stack-in-card which has other cards in it (doesnā€™t need to be a custom card like mushroom)

But I donā€™t know what the syntax is. I saw some posts here which have [{ in it to put other cards behind the stack card.

Any idea?

treid a bit and came to something new (still not perfect):

type: custom:auto-entities
show_empty: false
card:
  type: entities
filter:
  template: |-
    {% set filter = ['light.steckdose_wohnzimmer','light.hue_smart_plug_1'] %}
    {% set area_filter = ['wohnung','steckdose_wohnzimmer'] %}
    {% set areas = states
      | selectattr('attributes.device_class', 'defined')
      | map(attribute='entity_id')
      | map('area_id') | unique | reject('none') | list %}  
    {%- for area in areas -%}
    {% set lights = states.light
      | selectattr('state', 'eq', 'on')
      | selectattr('entity_id', 'in', area_entities(area)) 
      | rejectattr('entity_id', 'in',filter)     
      | list %}   
    {%- for light in lights -%}
       {{{ 'type': 'custom:vertical-stack-in-card',
          'title': area,
          'cards': 
            [ 
            { 'type': 'custom:mushroom-light-card',
              'entity': light.entity_id }]}}},   
    {%- endfor %} {%- endfor %}

i loop through all lights now so every light card is wrapped in its own vertical-stack-in-card. but i want one vertical-stack-card which shows the area title and then all assigned lights to it.
i dont know how to combine these two loops in this section:

       {{{ 'type': 'custom:vertical-stack-in-card',
          'title': area,
          'cards': 
            [ 
            { 'type': 'custom:mushroom-light-card',
              'entity': light.entity_id }]}}},