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

Thx A) for the quick reply and B) for the awesome enhacements!

No wonder I wasnā€™t able to figure it out, thatā€™s a tricky oneā€¦ :grimacing: Unfortunately some devices have different channels (sources) and they change, so would need to check all - so guessing this isnā€™t the ā€˜best/cleanestā€™ option.

There is another option, Iā€™ve noticed a supported_features exists on all these Roku devices, but there are two different ones.

image

I tried get this ā€˜orā€™ functionality to work, but couldnā€™t make that work either. Below was the lates iteration I tried:

include:
  - domain: media_player
    attributes:
      - supported_features: 18876
        supported_features: 19388

That would give you an AND condition, as in ā€œmatch entities where supported_features is 18876 (logical)AND supported_features is 19388 simultaneouslyā€.

To match either, you need to put them in different filters:

include:
  - domain: media_player
    attributes:
      - supported_features: 18876
  - domain: media_player
    attributes:
      - supported_features: 19388
1 Like

having an issue with icon_coloring in my auto-entities card using the entities in a group, based on input_boolean s state with the same object_idā€™s. the template is based on the icon template in the docs for card-mod: https://github.com/thomasloven/lovelace-card-mod#styling-entity-and-glance-cards

      - type: custom:auto-entities
        card:
          type: entities
          style: |
            :host {
              --paper-item-icon-color:
                {% set id = config.entity.entity_id.split('.')[1] %}
                {% set repo = 'input_boolean.' + id %}
                {% if states(repo) == 'on' %} gold
                {% else %} green
                {% endif %}
                ;
            }
            ha-card {
              box-shadow: none;
              background: none;
              padding: 0px;
              margin: -20px;
            }
        filter:
          include:
            - group: group.github_repos_in_use
              options:
                tap_action:
                  action: more-info
                hold_action:
                  action: navigate #url
                  navigation_path: weblinks
#        #              url_path: >
#        #                {{ state_attr(config.entity,'latest_release_url') }}
                type: custom:template-entity-row
                state: >
                  {% if states(config.entity) != None %}
                    {% if state_attr(config.entity,'latest_release_tag') %}
                    {{state_attr(config.entity,'latest_release_tag')}}
                    {% else %} {{states(config.entity)}}
                    {% endif %}
                  {% else %} Unknown
                  {% endif %}
                secondary: >
                  {% if states(config.entity) != None %}
                    {{state_attr(config.entity,'latest_commit_message')}}
                  {% else %} Unknown
                  {% endif %}
              sort:
                method: name

without the icon template this card works fine listing all members of the group, albeit in the default grey-blueish color HA uses. Id like to show the sensors with a color when an input_boolean is ā€˜onā€™ , as reflected in the template.

Am I using an incorrect place for the template? Ive also tried it in the template-entity-row , but that doesnt change the output.

I have a separate post How to style using card_mod: customization in JS not working which explains what was used before, a custom_ui js template:

    sensor.github_home_assistant:
      templates:
        icon_color: >
          var id = entity.entity_id.split('.')[1];
          var repo = 'input_boolean.' + id;
          if (entities[repo].state == 'on') return 'gold';
          return 'green';

in developer_tools/template:


but I couldnā€™t get that to customize_glob, so would hope auto-entities combined with card-mod would be the answerā€¦

Please help me find the correct way of doing soā€¦

@123 pardon the tag but I remembered this CustomUI - discussion threadā€¦ where you struggled and found a way to work it out, using template-entity-row and auto-entities using card-mod?

Ive now minimized the template to this, but still no such luck:

      - type: custom:auto-entities
        card:
          type: entities
          style: |
            ha-card {
              box-shadow: none;
              background: none;
              padding: 0px;
              margin: -20px;
            }
        filter:
          include:
            - group: group.github_repos_in_use
              options:
                tap_action:
                  action: more-info
                hold_action:
                  action: navigate
                  navigation_path: weblinks
                type: custom:template-entity-row
                style: |
                  :host {
                    --paper-item-icon-color:
                      {% set id = config.entity.object_id %}
                      {% set repo = 'input_boolean.' + id %}
                      {{'gold' if is_state(repo,'on') else 'green'}}
                      ;
                  }
                state: >
                  {% if states(config.entity) != None %}
                    {% if state_attr(config.entity,'latest_release_tag') %}
                    {{state_attr(config.entity,'latest_release_tag')}}
                    {% else %} {{states(config.entity)}}
                    {% endif %}
                  {% else %} Unknown
                  {% endif %}
                secondary: >
                  {% if states(config.entity) != None %}
                    {{state_attr(config.entity,'latest_commit_message')}}
                  {% else %} Unknown
                  {% endif %}
              sort:
                method: name

the template itself should work:

would appreciate your inputā€¦
thanks!

I really wish I could help you but Iā€™m a novice with Lovelace.

Iā€™ve never uses the auto-entities card and that linked post represents the peak of my involvement with the template-entity-row card. Ultimately, I didnā€™t use it (and continued to use Custom UI) because I donā€™t want to see templates flashed on screen whenever the page is refreshed.

ok thanks. I remember that, and it indeed still flashes the templates :wink:

Hi

Iā€™m trying to create a Delivery card based off the 17Track sensor and using auto-entities to populate it, and am having some difficulties with the way the sensor stores names (it prefixes each name with 'Seventeentrack Package: '). I was hoping I could get round this by using a name template, something like this (early days of home assistant coding, so apologies if Iā€™ve made glaring mistakes):

              - type: custom:auto-entities
                show_empty: false
                card:
                  type: glance #entities
                  columns: 10
                  title: Parcels
                filter:
                  include:
                    - entity_id: "sensor.seventeentrack_package_*"
                      options:
                        name: >
                            {{ name|regex_replace(find='Seventeentrack Package: ', replace='', ignorecase=True) }}

but I can not get it to work. I also tried this in my configuration.yaml, but it says it doesnā€™t recognise the customize_glob integration:

customize_glob:
  "sensor.seventeentrack_package_*":
    friendly_name: test

Does anyone know a way of changing the name of an entity grabbed by auto_entites to be a substring of itself? Thank you for any help you can give.

Try entity_id instead of object_id.

hi, thanks for chiming in!

I did try this before:

            :host {
              --paper-item-icon-color:
                {% set id = config.entity.entity_id.split('.')[1] %}
                {% set repo = 'input_boolean.' + id %}
                {% if states(repo) == 'on' %} gold
                {% else %} green
                {% endif %}
                ;

on the template-entity-row. it does nothing unfortunately. should I syntax it differently?

Actually, config.entity is the entity id, not the state object.

{% set repo = config.entity %}

Yey, I figured it out. The customize_glob problem was that I didnā€™t realise it needed to be member of homeassistant:, so a few indents later and that was sorted. It didnā€™t help with the templating through. What did was using another one of @thomasloven customisations, template-entity-row. Here what is working, with dynamic icons and nicer looking names, in case it helps someone else:

              - type: custom:auto-entities
                show_empty: false
                card:
                  type: entities
                  column_width: 50%
                  columns: 2
                  title: Parcels
                filter:
                  include:
                    - entity_id: "sensor.seventeentrack_package_*"
                      options:
                        type: "custom:template-entity-row"
                        name: >-
                            {{state_attr(config.entity, 'friendly_name')|regex_replace(find='Seventeentrack Package: ', replace='', ignorecase=True)}}
                        secondary: >-
                            {% if state_attr(config.entity, 'location') %}
                              {% if state_attr(config.entity, 'location') == "CN" %}
                                China:
                              {% else %}
                                 {{state_attr(config.entity, 'location')}}:
                              {% endif %}
                            {% endif %}
                            {% if state_attr(config.entity, 'info_text') %}
                              {{state_attr(config.entity, 'info_text')}}
                            {% endif %}
                        icon: >
                              {% if states(config.entity) == "In Transit" %} 
                                mdi:truck-delivery
                              {% elif states(config.entity) == "Delivered" %}
                                mdi:package-variant
                              {% elif states(config.entity) == "Not Found" %}
                                mdi:briefcase-search
                              {% elif states(config.entity) == "Returned" %}
                                mdi:directions-fork
                              {% elif states(config.entity) == "Undelivered" %}
                                mdi:help-box
                              {% elif states(config.entity) == "Expired" %}
                                mdi:timer-off
                              {% elif states(config.entity) == "Collection" %}
                                mdi:package-variant-closed
                              {% else %}
                                mdi:alert-circle
                              {% endif %}
#                        tap_action:
#                          action: url
#                          url_path: 'https://17track.net/en/track#nums={{ state_attr(config.entity, 'tracking_number') }}'
                        style: |
                          :host {
                            --paper-item-icon-color: 
                              {% if states(config.entity) == "In Transit" %} 
                                blue
                              {% elif states(config.entity) == "Delivered" %}
                                green
                              {% elif states(config.entity) == "Not Found" %}
                                red
                              {% elif states(config.entity) == "Returned" %}
                                orange
                              {% elif states(config.entity) == "Undelivered" %}
                                red
                              {% elif states(config.entity) == "Expired" %}
                                grey
                              {% elif states(config.entity) == "Collection" %}
                                purple
                              {% else %}
                                red
                              {% endif %}
                                ;
                            animation: 
                              {% if states(config.entity) != "In Transit" and states(config.entity) != "Delivered" %}
                                blink 2s ease infinite
                              {% endif %}
                                ;
                            }

Things that still need looking into, so donā€™t copy them, although any help would be appreciated:

  • The animation bit doesnā€™t work
  • The tap_action canā€™t be templated
  • Iā€™ve guessed the names of the ā€˜Collectionā€™, ā€˜Expiredā€™, ā€˜Returnedā€™ and ā€˜Not Deliverableā€™ states, for the moment
  • I was desperate to use anchors, until I used them and realised they didn;t work inside Template code
  • Iā€™ve no idea what the difference between > and >- at the start of a multi-line template, Iā€™ve used them interchangeably and not noticed any difference myself.

Anyway, hope that all helps someone.
Alex

5 Likes

i am confused, sorryā€¦

the entity is sensor.github_home_assistant. I want those to be colored based on the input_boolean with the same object_id, input_boolean.github_home_assistant

if config.entity is the entity_id, should I then use:

            :host {
              --paper-item-icon-color:
                {% set id = config.entity.split('.')[1] %}
                {% set repo = 'input_boolean.' + id %}
                {% if states(repo) == 'on' %} gold
                {% else %} green
                {% endif %}
                ;

?
let me tryā€¦

YESS!


thank you very much Thomas!

being the magic rule, have to memorize thatā€¦

edited my dedicated post How to style using card_mod: customization in JS not working - #7 by Mariusthvdb and indicated you solved it.

I managed to get the following combination from custom:auto-entities with custom:fold-entity-row done for which the following code applies.

title: GAD
show_header_toggle: false
entities:
  - input_boolean.notify_utility
  - input_datetime.gad_notification_time
  - type: 'custom:auto-entities'
    filter:
      include:
        - entity_id: sensor.gad_vandaag
        - entity_id: sensor.gad_morgen
        - entity_id: sensor.gad_restafval
        - entity_id: sensor.gad_gft
        - entity_id: sensor.gad_papier
        type: 'custom:fold-entity-row'
        head:
        type: section
        label: Details
          - entity_id: sensor.gad_pmd
          - entity_id: sensor.gad_textiel
          - entity_id: sensor.gad_kerstbomen
    sort:
      attribute: Sort-date
      method: attribute
      numeric: true
      entities: null
    card:
      type: 'custom:fold-entity-row'
      head:
        type: section
        label: Details

However, the reverse should be applicable, i.e. the current details should stay always and the top two entities should be allowed to roll-up. I do not seem to be able to get the ā€˜custom: fold-entity-rowā€™ visible this time. Any suggestions where Iā€™m wrong in the revised code below?

type: custom:auto-entities
show_empty: false
card:
  type: entities
  title: GAD
filter:
  include:
    - entity_id: sensor.gad_vandaag
    - entity_id: sensor.gad_morgen
    - entity_id: sensor.gad_restafval
    - entity_id: sensor.gad_gft
    - entity_id: sensor.gad_papier
    - entity_id: sensor.gad_pmd
    - entity_id: sensor.gad_textiel
    - entity_id: sensor.gad_kerstbomen
sort:
  attribute: Sort-date
  method: attribute
entities:
  - entity: input_boolean.notify_utility
  - entity: input_datetime.gad_notification_time
  head:
  label: Days
  type: section
    padding: 0
    type: 'custom:fold-entity-row'
1 Like

Indentation of rows 3-5 from the bottom, perhaps?

Thanks for thinking along with me but unfortunately no luck. I started from scratch again and deleted the code associated with the custom: auto-entities.

entities:
  - entity: sensor.gad_vandaag
  - entity: sensor.gad_morgen
  - entity: sensor.gad_restafval
  - entity: sensor.gad_gft
  - entity: sensor.gad_papier
  - entities:
      - entity: input_boolean.notify_utility
      - entity: input_datetime.gad_notification_time
    head:
      label: Notification Settings
      type: section
    padding: 0
    type: 'custom:fold-entity-row'
show_header_toggle: false
style: |
  ha-card {
    border: solid 2px var(--primary-color);
  }
title: GAD
type: entities

Now i need to find out how to insert the necessary lines to apply the custom:auto-entities to the top five entities such that they will be sorted based on

sort:
attribute: Sort-date
method: attribute
numeric: true

Any lead would be appreciated.

You could try something like:

type: custom:auto-entities
filter:
  include:
    - entity: sensor.gad_*
      sort:
        method: attribute
        ...

    - type: custom:fold-entity-row
      head:
        ...
      entities:
        - input_boolean...
        - input_datetime...

I.e. sort the waste types separately.
A filter that has a type: property will not be processed as a filter, but just passed through as it is.

Bingo!

type: 'custom:auto-entities'
show_empty: false
card:
  type: entities
  title: GAD
filter:
  include:
    - entity_id: sensor.gad_*
      sort:
        attribute: Sort-date
        method: attribute
        numeric: true
    - type: 'custom:fold-entity-row'
      head:
        label: Notification Settings
        type: section
      padding: 0
      entities:
       - entity: input_boolean.notify_utility
       - entity: input_datetime.gad_notification_time
show_header_toggle: false
style: |
  ha-card {
    border: solid 2px var(--primary-color);
  }
title: GAD

Thanks a lot!

Thomas, this is working fine now. only issue left might be that the template isnā€™t auto-updating, and needs a manual refresh. Can I set an entity for the template so it updates on that entity_id?

            :host {
              --paper-item-icon-color:
                {% set id = config.entity.split('.')[1] %}
                {% set repo = 'input_boolean.' + id %}
                {% if states(repo) == 'on' %} gold
                {% else %} green
                {% endif %}
                ;

Great pluing!! I want to use it with my plant cards, what am i doing wrong:

                    - type: entities
                      entities: 
                        - type: custom:auto-entities
                          card:
                            type: entities
                            title: Plants
                            show_header_toggle: false
                          filter:
                            include:
                              - domain: plant
                                options:
                                  type: plant-status
                                  entity: this.entity_id

Iā€™m getting the following errors:

Unknown type encountered: plant-status.

entity: plant.achterkamer type: plant-status toggle: true

Unknown type encountered: plant-status.

entity: plant.rode_ovaal_pot type: plant-status toggle: true

Just found a solution, see below:

type: entities
entities: 
  - type: custom:auto-entities
    card:
      type: entities
      title: Plants
      show_header_toggle: false
    filter:
      include:
        - domain: plant
          options:
            type: custom:layout-card
            cards:
              - type: plant-status
                entity: this.entity_id

You can specify entity_ids: that cause an update with

style: |
  :host {
      ..etc..
  }
entity_ids:
  - input_boolean.my_thing

But thatā€™s a static list.
If not specified, itā€™s set to entity:.

Your problem is that plant-status is a Card, but the entities card expects Rows.
This can help.