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

Nearlly, but I see the options-tag is within the regular ā€œincludeā€ tag in the template :thinking:

This gave me an idea or two, so thanks! :slight_smile:

Thank you for your help!
I have already tried that, but that still gives me the same result. (see picture).
Maybe there is something wrong with my code?

no, you are still listing all entities under the include filter.

just use:

filter:
  include:
    entity_id: sensor.almere_*

it will re-list the 2 already included entities from the top entities list, so either take those out also, or, exclude them under

exclude:
  entity_id:

either verbosely, or yet again using wild cards:

      filter:
        exclude:
          - entity_id: sensor.afvalwijzer*next*
          - entity_id: sensor.afvalwijzer*to*
        include:
          - entity_id: sensor.afvalwijzer_*

also, If you want to be in complete control, and always need those 2 entities at the top, just take them out of the auto-entities and list them in the containing entities card

    - type: entities
      title: Entities
      entities:
        - sun.sun
        - sensor.moon
        - type: custom:auto-entities
          card:
            type: entities
            card_mod:
              style: |
                ha-card {
                  box-shadow: none;
                  margin: 0px -16px
                }
          filter:
            exclude:
              - entity_id: sensor.afvalwijzer*next*
              - entity_id: sensor.afvalwijzer*to*
            include:
              - entity_id: sensor.afvalwijzer_*
1 Like

Thank you so much for your help! This worked!

Gotten anywhere with this?:sweat_smile:

Working on the same thing currently!

I did find a way. I described my project here Food in the Freezer Tracker - Share your Projects! - Home Assistant Community (home-assistant.io)

This works if all of the info you need can be derived from the entity being sent by auto-entities. There is an example in there of me using one entity to get another because they are named similar.

As many of you I use the auto-entities card for battery levels and use the yaml below:

type: custom:auto-entities
card:
  show_header_toggle: false
  title: Battery low
  type: entities
  state_color: true
filter:
  include:
    - attributes:
        device_class: battery
      state: <=10
  exclude:
    - name: /[Ll]ow/
    - name: /[Ss]tate/
    - name: Lux*
sort:
  methode: state
  numeric: true
show_empty: false

Is there a way to send a notification if a battery entityā€™s state is ā€˜triggeredā€™ and becomes visible in the card?

I have a input number slider in a vertical stack card with the auto-entities card. I want the input numberā€™s value as input of the state attribute. For some reason this is not functioning. What am I missing? See code:

type: vertical-stack
cards:
  - type: entities
    entities:
      - entity: input_number.slider_battery_level
        name: Battery level min.
  - type: custom:auto-entities
    card:
      show_header_toggle: false
      title: Battery low
      type: entities
      state_color: true
    filter:
      include:
        - attributes:
            device_class: battery
          state: >-
            {{"<=" + states('input_number.slider_battery_level') | int | string
            }}
      exclude:
        - name: /[Ll]ow/
        - name: /[Ss]tate/
        - name: Lux*
    sort:
      methode: state
      numeric: true
    show_empty: false

Templates are not supported for this option.
Your possible way is using a ā€œtemplateā€ option which does support jinja templates.
You will have to define in this ā€œtemplateā€ option a code to include & exclude required entities.

1 Like

How to define Markdown cards in auto-entities

If a markdown card is used to show a static content:

  - type: custom:auto-entities
    card_param: cards
    card:
      type: vertical-stack
    filter:
      include:
        - entity_id: input_boolean.test_boolean_*         ### define your own mask
          options:
            type: conditional
            conditions:
              - entity: this.entity_id
                state_not: 'off'
            card:
              type: markdown
              content: some content

Note: to make the task a bit more complex, a Conditional card is used here ))).

Same when the content is dynamic (i.e. some jinja templates used) & does NOT depend of the currently processing entity_id:

            ...
            card:
              type: markdown
              content: >-
                {{ .... }}

or when the processed entity_id is NOT a part of a template:

            ...
            card:
              type: markdown
              content: >-
                {{ ... }}
                xxx: this.entity_id
                {{ ... }}

The problem is that that this.entity_id variable is not resolved inside these templates.

If your templates DO depend on the currently processed entity_id (as you have in your case) - then you need to use the template option:

  - type: custom:auto-entities
    card_param: cards
    card:
      type: vertical-stack
    filter:
      template: >-
        {% for entity in states.input_boolean|selectattr('entity_id','search','input_boolean.test_boolean_') -%}
          {%- if (entity.entity_id.split('test_boolean_')[1])|int(0) > 4 -%}
            {%- set CONTENT = 'xx: ' + entity.entity_id -%}
          {%- else -%}
            {%- set CONTENT = 'yy: ' + entity.entity_id -%}
          {%- endif -%}
          {{
            {
              'type': 'conditional',
              'conditions': [
                {
                  'entity': entity.entity_id,
                  'state_not': 'off'
                }
              ],
              'card': {
                'type': 'markdown',
                'content': CONTENT
              }
            }
          }},
        {%- endfor %}

That part simulates a dynamically defined content:

          {%- if .... -%}
            {%- set CONTENT = ... -%}
          {%- else -%}
            {%- set CONTENT = ... -%}
          {%- endif -%}

Hello, it would be possible to make an autoentities or mushroom card that indicates the sensors of a specific integration in my mqtt case (the majority are from z2mqtt) that do not update for more than 1 hour, in order to know if there is any sensor in house that has lost connectivity or has run out of batteryā€¦ Thank you!!!

I just managed to get this badge card sorted that way I wantā€¦

image

type: custom:auto-entities
card: 
  type: custom:badge-card
card_param: badges
entities:
  - entity: sensor.time
  - entity: sensor.period_of_day
filter: 
  include:
    - entity_id: sensor.next_s*
      sort:
        method: attribute
        attribute: timestamp
        reverse: false

I had to modify my templated entities and added a timestamp of the sun.sun attribute since my state is just HH:MM with nothing else useful to sort by. last_updated, last_changed and last_triggered were useless!

  - name: "Next Solar Midnight"
    unique_id: next_solar_midnight
    state: '{{ as_timestamp(state_attr("sun.sun","next_midnight")) | timestamp_custom("%H:%M", true)}}'
    icon: mdi:weather-sunset-up
    attributes:
      timestamp: '{{ as_timestamp(state_attr("sun.sun","next_midnight")) }}'
    
  - name: "Next Dawn"
    unique_id: next_dawn
    state: '{{ as_timestamp(state_attr("sun.sun","next_dawn"),0) | timestamp_custom("%H:%M", true)}}'
    icon: mdi:weather-sunset-up
    attributes:
      timestamp: '{{ as_timestamp(state_attr("sun.sun","next_midnight")) }}'
  
  - name: "Next Sunrise"
    unique_id: next_sunrise
    state: '{{ as_timestamp(state_attr("sun.sun","next_rising"),0) | timestamp_custom("%H:%M", true) }}'
    icon: mdi:weather-sunset-up
    attributes:
      timestamp: '{{ as_timestamp(state_attr("sun.sun","next_rising")) }}'

  - name: "Next Solar Noon"
    unique_id: next_solar_noon
    state: '{{ as_timestamp(state_attr("sun.sun","next_noon"),0) | timestamp_custom("%H:%M", true)}}'
    icon: mdi:weather-sunset-up
    attributes:
      timestamp: '{{ as_timestamp(state_attr("sun.sun","next_noon")) }}'
    
  - name: "Next Sunset"
    unique_id: next_sunset
    state: '{{ as_timestamp(state_attr("sun.sun","next_setting"),0) | timestamp_custom("%H:%M", true) }}'
    icon: mdi:weather-sunset-down  
    attributes:
      timestamp: '{{ as_timestamp(state_attr("sun.sun","next_setting")) }}'

  - name: "Next Dusk"
    unique_id: next_dusk
    state: '{{ as_timestamp(state_attr("sun.sun","next_dusk"),0) | timestamp_custom("%H:%M", true)}}'
    icon: mdi:weather-sunset-up
    attributes:
      timestamp: '{{ as_timestamp(state_attr("sun.sun","next_dusk")) }}'

Quick question: I can see back in 2019 an enhancement was made to specify a max number of entities: ā€œDisplay up to a maximum number of entities (e.g. display the first 10 matches)ā€

Iā€™m having trouble locating this option in the GitHub page. Does anyone know the best way to accomplish this? I have a fixed-height card that Iā€™m populating with auto-entities. It works great, but occasionally it finds too many entities that spill over outside the card. Iā€™d like to limit it (or maybe somehow allow scrolling within the card?). Thanks in advance!

sort - count

Thank you, and sure enough I can see it now in the doc. I must be tired.

Hi,

Iā€™m trying to optimize a media player dashboard, and Iā€™m hoping that I can use auto-entities to solve it. However, I have not had the luck to succeed yet; I would like to know if itā€™s possible to populate the card based on an attribute of an entity.

Hereā€™s the attributes of the media_player (cleaned up):

group_members:
  - media_player.kitchen_2
  - media_player.lego_vaerelset
volume_level: 0.23

Can I make a template to show the entities provided in Group members attribute?

EDIT: Nevermind, it was very easy, must have made a typo earlier.

type: custom:auto-entities
card:
  type: entities
filter:
  template: >
    {{ state_attr("media_player.kitchen_2", "group_members") | list }}


1 Like

Hi, I am working on showing scenes as chips using mushroom-chips-card:

I read this thread and I try multiple variant proposed in thread and none of them is working.

Has anybody idea, what I am doing wrong?

type: custom:auto-entities
card:
  type: custom:mushroom-chips-card
show_empty: true
card_param: chips
filter:
  include:
    - entity_id: scene.*
      area: Ložnice
      options:
        card:
          type: entity
          content_info: name
          icon_color: |-
            {% if is_state("this.entity", "on") %}
              amber
            {% else %}
              red
            {% endif %}
          tap_action:
            action: toggle

How would I go to get ONE entity from each of my areas?

I wish to use a predefined card with lots of templating specified to the area an entity is assigned, but I have trouble to get just one of each ā€œareaā€

How would i use card_param: cards with a filter as a template?

What i am trying to achieve is this:

Current Code
type: custom:auto-entities
card:
  type: custom:stack-in-card
  card_mod:
    style: |
      ha-card {
        padding-top: 5px;
        padding-bottom: 5px !important;
      }
filter:
  include:
    - entity_id: sensor.office**battery
      options:
        type: custom:bar-card
        card_mod:
          style: |
            bar-card-currentbar, bar-card-backgroundbar {
              border-radius: 13px !important;
              height: 43px !important;
              margin-top: -8px !important;
            }
            bar-card-row {
              margin-bottom: 14px !important;
            }
            bar-card-name {
              color: black !important;
              margin-top: -10px !important;
            }
            bar-card-value {
              color: black !important;
              margin-top: -10px !important;
            }
            ha-icon{
              padding: 9px;
              border-radius: 100px;
              --mdc-icon-size: 28px;
              margin-top: -12px;
            }
            bar-card-row bar-card-currentbar,
            ha-icon, bar-card-backgroundbar {
              --bar-color:
              {% if states(config.entity) | int <= 10 %}
                #ff0026 !important;
                --card-mod-icon: mdi:battery-10 !important;
              {% elif states(config.entity) | int <= 20 %}
                #ff4d00 !important;
                --card-mod-icon: mdi:battery-20 !important;
              {% elif states(config.entity) | int <= 30 %}
                #ff9900 !important;
                --card-mod-icon: mdi:battery-30 !important;
              {% elif states(config.entity) | int <= 40 %}
                #ffcc00 !important;
                --card-mod-icon: mdi:battery-40 !important;
              {% elif states(config.entity) | int <= 50 %}
                #e7fc03 !important;
                --card-mod-icon: mdi:battery-50 !important;
              {% elif states(config.entity) | int <= 60 %}
                #aaff00 !important;
                --card-mod-icon: mdi:battery-60 !important;
              {% elif states(config.entity) | int <= 70 %}
                #aaff00 !important;
                --card-mod-icon: mdi:battery-70 !important;
              {% elif states(config.entity) | int <= 80 %}
                #22c402 !important;
                --card-mod-icon: mdi:battery-80 !important;
              {% elif states(config.entity) | int <= 90 %}
                #22c402 !important;
                --card-mod-icon: mdi:battery-90 !important;
              {% elif states(config.entity) | int <= 100 %}
                #22c402 !important;
                --card-mod-icon: mdi:battery !important;
              {% else %}
                blue
                mdi:bug
              {% endif %}
            }
            bar-card-row ha-icon {
              color: color-mix(in srgb, var(--bar-color) 100%, transparent);
              background: color-mix(in srgb, var(--bar-color) 20%, transparent);
            }
            bar-card-row bar-card-indicator {
              color: color-mix(in srgb, var(--bar-color) 100%, transparent);
            }
            ha-card {
              padding: 0px !important;
              margin: -4px 0px !important;
              height: 60px;
            }
sort:
  method: state
  numeric: true
  ip: false
  ignore_case: false
  reverse: false
show_empty: true
card_param: cards

But instead using a template filter like this for example:

Desired Code
              filter:
                template: |-
                  {% for state in states.sensor -%}
                    {%- if state.entity_id | regex_match("sensor.*battery*", ignorecase=False) and "SM" not in state.attributes.friendly_name and "Dimitri" not in state.attributes.friendly_name and 'unknown' not in state.state and 'unavailable' not in state.state and state.state | int <= 10-%}
                      {{
                        {
                          'entity': state.entity_id,
                          'name': state.attributes.friendly_name.split(' battery')[0]
                        }
                      }},
                    {%- endif -%}
                  {%- endfor %}

I cant inject each entity into the same card like you normally would as the colors dont show up correctly if so as i cant use config.entity. So i have to use card_param: cards but i cant for the life of me figure out where to put the card information with the template option.

EDIT: Nevermind, got it with the below! :slight_smile:

Final Code
type: custom:auto-entities
card:
  type: custom:stack-in-card
  card_mod:
    style: |
      ha-card {
        padding-top: 5px;
        padding-bottom: 5px;
      }
card_param: cards
filter:
  template: >-
    {%- for state in states.sensor|selectattr('entity_id','search','battery') |
    selectattr('entity_id','search','office')-%}
      {{
        {
          'type': 'custom:bar-card',
          'entity': state.entity_id,
          'name': state.attributes.friendly_name.split(' Battery')[0].split(' battery')[0],
          'style': 'bar-card-currentbar, bar-card-backgroundbar {
                    border-radius: 13px !important;
                    height: 43px !important;
                    margin-top: -8px !important;
                  }
                  bar-card-row {
                    margin-bottom: 14px !important;
                  }
                  bar-card-name {
                    color: black !important;
                    margin-top: -10px !important;
                  }
                  bar-card-value {
                    color: black !important;
                    margin-top: -10px !important;
                  }
                  ha-icon{
                    padding: 9px;
                    border-radius: 100px;
                    --mdc-icon-size: 28px;
                    margin-top: -12px;
                  }
                  bar-card-row bar-card-currentbar,
                  ha-icon, bar-card-backgroundbar {
                    --bar-color:
                    {% if states(config.entity) | int <= 10 %}
                      #ff0026 !important;
                      --card-mod-icon: mdi:battery-10 !important;
                    {% elif states(config.entity) | int <= 20 %}
                      #ff4d00 !important;
                      --card-mod-icon: mdi:battery-20 !important;
                    {% elif states(config.entity) | int <= 30 %}
                      #ff9900 !important;
                      --card-mod-icon: mdi:battery-30 !important;
                    {% elif states(config.entity) | int <= 40 %}
                      #ffcc00 !important;
                      --card-mod-icon: mdi:battery-40 !important;
                    {% elif states(config.entity) | int <= 50 %}
                      #e7fc03 !important;
                      --card-mod-icon: mdi:battery-50 !important;
                    {% elif states(config.entity) | int <= 60 %}
                      #aaff00 !important;
                      --card-mod-icon: mdi:battery-60 !important;
                    {% elif states(config.entity) | int <= 70 %}
                      #aaff00 !important;
                      --card-mod-icon: mdi:battery-70 !important;
                    {% elif states(config.entity) | int <= 80 %}
                      #22c402 !important;
                      --card-mod-icon: mdi:battery-80 !important;
                    {% elif states(config.entity) | int <= 90 %}
                      #22c402 !important;
                      --card-mod-icon: mdi:battery-90 !important;
                    {% elif states(config.entity) | int <= 100 %}
                      #22c402 !important;
                      --card-mod-icon: mdi:battery !important;
                    {% else %}
                      blue
                      mdi:bug
                    {% endif %}
                  }
                  bar-card-row ha-icon {
                    color: color-mix(in srgb, var(--bar-color) 100%, transparent);
                    background: color-mix(in srgb, var(--bar-color) 20%, transparent);
                  }
                  bar-card-row bar-card-indicator {
                    color: color-mix(in srgb, var(--bar-color) 100%, transparent);
                  }
                  ha-card {
                    padding: 0px !important;
                    margin: -4px 0px !important;
                    height: 60px;
                  }'
        }
      }},
    {%- endfor %}
sort:
  method: state
  numeric: true
  count: 8
5 Likes

Hi everyone,
Is it possible to exclude all areas that do not match a certain name?
E.g. I want to exclude all areas that are not named ā€˜Living Roomā€™.

I would like to work with exclude instead of include, because the include would require me to add a lot of additional code for the card that is receiving the entities.