🔹 Auto-entities - Automatically fill cards with entities

new day, new challenge…

have this auto-entities card:

  - type: custom:auto-entities
    card:
      type: map
      title: Maps Family abroad
    show_empty: false
    filter:
      include:
        - entity_id: person.*_address
          attributes:
            country_code: not nl
          options:
            aspect_ratio: 969
            dark_mode: false
            default_zoom: 14

which looks for the attribute country_code, on my adapted person entities. If that isnt ‘nl’ they should show up on a map.

thing is that when we all are in nl, and the card should be empty, and not show, it returns these errors in inspector (Safari):

dark_mode is listed in my config, so that could be passing the show_empty, but when on earth would the hours_to_show be listed there…

so, several issues in 1
please have a look if you can find something wrong here.

for the sake of testing, I changed it to:

  - type: custom:auto-entities
    card:
      type: map
      title: Maps Family abroad
    show_empty: false
    filter:
      include:
        - entity_id: person.*_address
          not:
            attributes:
              country_code: be
          options:
            aspect_ratio: 969
            dark_mode: false
            default_zoom: 14

and, since all are in nl, this shows a map with all family members. Changing the be to nl here, brings back the error, now in Chrome, and consistently shows an error on the entities for Map:

and even this returns the error:

  - type: custom:auto-entities
    card:
      type: map
      title: Maps Family abroad
    show_empty: false
    filter:
      include:
        - entity_id: person.*_address
          attributes:
            country_code: be

while using nl in the last config, shows nicely.

- type: custom:auto-entities
  card:
           type: custom:fold-entity-row
           head: 
                        type: section
                        label: test
  card_param: entities
  filter:         
         include:
                    - entity_id: "input_boolean.light_*_on_alarm"
                      options:
                          name: this.entity_id

instead of ‘this.entity_id’ can i get back the value of an attribute of this ?

I am trying to monitor my devices and I need the card where will be only offline devices. I crated ping binary_sensor for each of my devices.


But the issue is that I still see all my devices. Even if I add domain: binary_sensor, I still see all my binary_sensors, not just the devices I want to monitor.

type: 'custom:auto-entities'
show_empty: false
card:
  type: glance
  title: Offline devices
entities:
  - entity: binary_sensor.eap_dg
  - entity: binary_sensor.eap_sg
  - entity: binary_sensor.vticnica_diy
  - entity: binary_sensor.water_valve
  - entity: binary_sensor.hob
  - entity: binary_sensor.hood
  - entity: binary_sensor.oven
  - entity: binary_sensor.klima
  - entity: binary_sensor.pred_kletjo
  - entity: binary_sensor.rgb_dnevna
  - entity: binary_sensor.ring
  - entity: binary_sensor.roomba
  - entity: binary_sensor.toplotna
  - entity: binary_sensor.broadlink
  - entity: binary_sensor.magichome
  - entity: binary_sensor.chromecast
  - entity: binary_sensor.ifan02
  - entity: binary_sensor.podstresje
  - entity: binary_sensor.senzorji_strop
  - entity: binary_sensor.wled
filter:
  include:
    - domain: binary_sensor
      state: "off"

According to this:

you may specify a “name” for each sensor.
Let it be something like "presence_%device_name%"
Then in the “auto-entities” in the "include"section specify this:

filter:
  include:
    - entity_id: binary_sensor.presence_*
      state: off
1 Like

This works, thanks. But now I have also on the card next to the name also “presence_”, so all my items have names like “presence_Hob”.
I tried to add friendly_name: Hob into the configuration, but it does not work. I also tried with id: presence_hob with the hope that this will be taken as entity_id, but again no success

In my setup:

  1. Specify 'name' with some “standard” word like “presence_”, “available” etc.
  2. Specify 'friendly_name' using “Customization”.
  3. In ‘auto-entities’ use something like “include: entity_id: presence_*” (as I mentioned above). As a result, all entities are listed properly (only devices & with OFF state) with their friendly names.

Can you share your ‘auto-entity’ card code? May be I will be able to help.

There is also one possibility to differ “right entity” from “wrong entities”.
For tracking devices I am using ASUSWRT - now I have 20…30 ‘device_tracker’ entities, and in ‘auto-entities’ can specify this:

include:
  - domain: device_tracker
    attributes:
      source_type: router

since all these entities have this attribute.
изображение
For me, ASUSWRT integration is not as fast & reliable as Ping, but it works…
And this integration allows to show NEW added devices (note that with “Ping” you need to declare every device in “configuration.yaml”), but it works only with ASUS routers…

Hi, i am a beginner on this.

What I want is this.
I have some sensors (for the garbage) with data as state.
I want to show them is de actual date is equal or 1 day before.
I try this with:
(example is for date is equal, for day before I want to use “now() + 1”)

filter:
  include:
    - state: = now()

Is this possible? or is it totally wrong?

I also attempt this:

filter:
  template: null
  include:
    - state: '= {{now().date()}}'

and

filter:
  template: null
  include:
    - state: '= {{ as_timestamp (now().date()) | timestamp_custom('%d-%m-%Y') }}'

But now results

Could you try this?

      template: |
        {% for state in states.sensor -%}
          {%- if state.entity_id | regex_match('sensor.afvalinfo_',ignorecase=False) -%}
            {%- set DAY = strptime(states(state.entity_id) | timestamp_local,'%Y-%m-%d').day -%}
            {%- if DAY == now().day or
                   DAY == now().day -1 -%}
              {{ state.entity_id}},
            {%- endif -%}
          {%- endif -%} 
        {%- endfor %}

or even this with 'friendly_name' & 'secondary_info':

      template: |
        {% for state in states.sensor -%}
          {%- if state.entity_id | regex_match('sensor.afvalinfo_',ignorecase=False) -%}
            {%- set DAY = strptime(states(state.entity_id) | timestamp_local,'%Y-%m-%d').day -%}
            {%- if DAY == now().day or
                   DAY == now().day - 1 -%}
              {{  {'entity': state.entity_id, 'name': state_attr(state.entity_id,'friendly_name'), 'secondary_info': 'last-changed' } }},
            {%- endif -%}
          {%- endif -%} 
        {%- endfor %}

I will try that. Thx.
Maybe a stupid question, but this is written in jinja2 language?
And do you now some good sites to learn this? or examples?

yes

I am a beginner too, check this please - https://jinja.palletsprojects.com/en/master/templates/

Thx. a lot

Example with "template" filter - a list of devices with battery level <= WARNING_LEVEL.

  1. Icon’s color is managed by card-mod, the "style" property is passed to "template".
  2. Value of WARNING_LEVEL is managed by slider & "input_select".
  3. A hyperlink to a view with a whole devices’ list is provided.
  4. Card-mod is also used for removing padding, word wrapping for the slider.

изображение
Note: translation from Russian to English is inside comments.

type: 'custom:stack-in-card'
mode: vertical
keep:
  background: false
  box_shadow: false
  margin: false
  outer_padding: false
  border_radius: false
cards:
  - type: 'custom:auto-entities'
    card:
      type: entities
      title: Контроль заряда батарей    ### Battery level check
    entities:
      - type: section
        label: Список устройств     ### Devices
    unique: false
    show_empty: true
    filter:
      template: >
        {% set WARNING_LEVEL = states('input_number.battery_level_check') |
        float -%}

        {%- for state in states.sensor -%}
          {%- if state.entity_id | regex_match('sensor.battery_',ignorecase=False) -%}
            {%- set LEVEL = states(state.entity_id) | float -%}
            {%- if LEVEL <= WARNING_LEVEL -%}
              {{
                { 'entity': state.entity_id,
                  'secondary_info': 'last-changed',
                  'style': ':host { {%- if states(config.entity) == "unknown" -%}
                                    --paper-item-icon-color: brown;
                                    {%- elif states(config.entity) | float <= states("input_number.battery_level_critical") | float -%}
                                    --paper-item-icon-color: red;
                                    {%- elif states(config.entity) | float <= states("input_number.battery_level_warning") | float -%}
                                    --paper-item-icon-color: rgb(250,218,67);
                                    {%- else -%}
                                    --paper-item-icon-color: green;
                                    {%- endif %} }'
                } }},
            {%- endif -%}
          {%- endif -%} 
        {%- endfor %}
    sort:
      method: state
      reverse: false
      ignore_case: false
      attribute: null
      first: 0
      count: 1000
      numeric: true
  - type: entities
    entities:
      - type: button
        icon: 'mdi:blank'
        name: ' '
        action_name: Полный список устройств    ### All devices
        tap_action:
          action: navigate
          navigation_path: /lovelace/battery
    style: |
      ha-card .card-content {
        padding-top: 0px;
        padding-bottom: 0px;
      }
  - type: entities
    entities:
      - type: section
      - type: 'custom:fold-entity-row'
        head:
          type: 'custom:dummy-entity-row'
          entity: sensor.test_zero_value
          icon: 'mdi:cogs'
          name: Настройки   ## Settings
        padding: 0
        open: false
        entities:
          - type: divider
            style:
              height: 10px
              width: 100%
              background: none
          - entity: input_number.battery_level_check
            name: 'Уровень заряда менее, чем'   ### Level less than
            style:
              hui-generic-entity-row:
                $: |
                  .info.text-content {
                    text-overflow: unset !important;
                    white-space: unset !important;
                  }
3 Likes

Thx. It seems to work.

maybe have a look in the dedicated thread for afvalwijzer: Garbage pickup date (mijnafvalwijzer.nl) custom_component

the template I posted there isnt doing what you ask, but you might see useful info for having auto generated cards with this integration.

Also, glad to assist getting you up and running, but hop over there and will see what you need.

I will look in that thread for afvalwijzer.

Does anyone know if it is possible to use auto entities to break out and create a card for each item in a list attribute of a single entity?

I’ve looked around and not had any luck so far, any help appreciated.

I figured out how to get it to create entities for the attributes using the template filter but I’m still stuck on how I can get this to work with the card_param so the buttons can be added to a grid card.

This is what I have so far…

> type: 'custom:auto-entities'
> show_empty: true
> card:
>   type: grid
>   columns: 3
> card_param: cards
> filter:
>   template: |
>     {%- for chore in state_attr('sensor.grocy_chores', 'chores') -%}
>       {{ { 'entity' : 'sensor.grocy_chores',     
>            'name' : chore.name,
>            'icon' : 'mdi:fish',   
>            'type' : 'custom:button-card',
>             }
>              }},
>     {%- endfor -%}

I’m not getting anything to populate with your example. I verified that my grocy chores sensor is the same. Could you verify the formatting? I also tried different types of cards in type and I get no output at all.

type: 'custom:auto-entities'
show_empty: true
card:
  type: grid
  columns: 3
card_param: cards
filter:
  template: |
    {%- for chore in state_attr('sensor.grocy_chores', 'chores') -%}
      {{ { 'entity' : 'sensor.grocy_chores',     
           'name' : chore.name,
           'icon' : 'mdi:fish',   
           'type' : 'custom:button-card',
            }
             }},
    {%- endfor -%}

Thanks for the help, that is the problem I can get it to work adding it simply to the entities card but I can’t get the template filter working with a card that expects “cards” as input.

The below does work but I want more control over the layout of the buttons

type: 'custom:auto-entities'
show_empty: true
card:
  type: entities
filter:
  template: |
    {%- for chore in state_attr('sensor.grocy_chores', 'chores') -%}
      {{ { 'entity' : 'sensor.grocy_chores',     
           'name' : chore.name,
           'icon' : 'mdi:fish',   
           'type' : 'custom:button-card',
            }
             }},
    {%- endfor -%}