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

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.

yea, I feared as muchā€¦ I donā€™t want to list all that, there are way to many to listā€¦ and, it takes away the beauty of the auto-entities card. It would have to be something like this:

{{trigger.event.data.entity_id in state_attr('group.github_repo_updates','entity_id')}}

if any of these entity_idā€™s would change it would have to update the sensor listed in the card made by the auto-entities card.

If thatā€™s not possible, now, or in the future, it might be best off with this automation I already have, and ad an extra service to that, updating the sensor with the object_id of the triggering entity_id:

  - alias: 'GitHub boolean updates sensor'
    id: 'GitHub boolean updates sensor'
    trigger:
      platform: event
      event_type: state_changed
    condition:
      condition: template
      value_template: >
        {{trigger.event.data.entity_id in state_attr('group.github_repo_updates','entity_id')}}
    action:
      service: homeassistant.update_entity
      entity_id: sensor.github_repo_updates

add

  service: homeassistant.update_entity
  data_template:
    entity_id: >
     sensor.{{trigger.event.data.new_state.object_id}}

or

  service: homeassistant.update_entity
  data_template:
    entity_id: >
      {{'sensor.' + trigger.event.data.new_state.object_id}}

?
they both throw errors btw, but they do workā€¦, no they dont, it was because I switched views, from the log back to the view again, and it rerendered the auto-entitiesā€¦ canā€™t an automation trigger the re-rendering of that card? if must the view maybe?

never-mind, i found the solution. vera imported two duplicates.

hi everyone,

can you guys look at my code to help identify why i have duplicate entities?

cards:
  - cards:
      - color: var(--disabled-text-color)
        color_type: label-card
        name: Batteries
        template: button-card-headers
        type: 'custom:button-card'
      - card:
          column_width: 26%
          justify_content: left
          layout: horizontal
          min_columns: 4
          type: 'custom:layout-card'
        filter:
          include:
            - attributes:
                battery_level: < 90
              options:
                color: var(--disabled-text-color)
                color_type: label-card
                icon: |
                  [[[
                    var battery_level = states['this.entity_id'].attributes.battery_level;
                    var battery_round = parseInt(battery_level / 10) * 10;
                    if (battery_round >= 100) return 'mdi:battery';
                    else if (battery_round > 0) return 'mdi:battery-' + battery_round;
                    else return 'mdi:battery-alert';
                  ]]]
                label: |
                  [[[
                    var bri = states['this.entity_id'].attributes.friendly_name;
                    return bri  ;
                  ]]]
                layout: vertical
                name: |
                  [[[
                    var bri = states['this.entity_id'].attributes.battery_level;
                    return bri  + '%';
                  ]]]
                show_icon: true
                show_label: true
                styles:
                  card:
                    - background-color: var(--disabled-text-color)
                  icon:
                    - color: maroon
                  label:
                    - font-size: 10px
                  name:
                    - font-size: 12px
                type: 'custom:button-card'
        type: 'custom:auto-entities'
    type: vertical-stack
layout: horizontal
type: 'custom:layout-card'

Hi!

Iā€™m using this card, it works great!

I have my cameraā€™s motion sensors displaying when thereā€™s movement and I was wondering if there is a chance to set the tap-action for certain entities to, instead of showing the more info box of the motion sensor, show the actual camera.

Thanks!

since I am looking for a way to color the icons, based on a template in (card-mod) style, did you do so here? or are these colored by custom-ui in the backend.

My battery sensors will al be the default grey after updating to HA 110ā€¦ since the way custom-ui uses icon_color is no longer working from hat HA version.

Thomas, is it possible to use a template in the auto-entities that works for all entities in that card? I ask because since the earlier success here doesnt seem to work in this auto-entities card using:

  - type: custom:auto-entities
    card:
      title: Philips light level (lux) sensors
      type: entities
    filter:
      include:
        - entity_id: sensor.*_sensor_light_level_raw
          options:
            style: |
              :host {
                --paper-item-icon-color:
                 {% if states(config.entity)|float < 1 %} maroon
                 {% elif states(config.entity)|float < 300 %} firebrick
                 {% elif states(config.entity)|float < 10000 %} orange
                 {% elif states(config.entity)|float < 17000 %} green
                 {% elif states(config.entity)|float < 22000 %} gold
                 {% elif states(config.entity)|float < 25500 %} teal
                 {% elif states(config.entity)|float < 28500 %} dodgerblue
                 {% elif states(config.entity)|float < 33000 %} lightskyblue
                 {% elif states(config.entity)|float < 40000 %} lightblue
                 {% elif states(config.entity)|float < 40000 %} lightcyan
                 {% else %} azure
                 {% endif %}
                 ;
               }

or using the options for the style. I canā€™t get it to show the entities, let alone colored, using the style: . Without that, the listing is fine.

the bottom example here https://github.com/thomasloven/lovelace-card-mod/blob/1105f6f1c3f3d91a389f810c96826f0d816e1df5/src/example.yaml should be quite alike?
please have a look? thanks.

edit

overnight the cache seems to have healed allā€¦ This is suddenly showing correctly now. Sorry to bother.

gave me the opportunity to cleanup the template a bit:

  - type: custom:auto-entities
    card:
      title: Test auto coloring light level (lux) sensors
      type: entities
    filter:
      include:
        - entity_id: sensor.*_sensor_light_level_raw
          options:
            style: |
              :host {
                --paper-item-icon-color:
                 {% set level = states(config.entity)|float %}
                 {% if level == 0 %} black
                 {% elif level < 1 %} maroon
                 {% elif level < 300 %} firebrick
                 {% elif level < 10000 %} orange
                 {% elif level < 17000 %} green
                 {% elif level < 22000 %} gold
                 {% elif level < 25500 %} teal
                 {% elif level < 28500 %} dodgerblue
                 {% elif level < 33000 %} lightskyblue
                 {% elif level < 40000 %} lightblue
                 {% elif level < 40000 %} lightcyan
                 {% else %} azure
                 {% endif %}
                 ;
               }

too bad more-info isnā€™t set by this, but that would be a card-mod question. Iā€™ll hop over to that thread

This plugin is awesome!
Is it also possible to filter for a specific length?

I have a some list of fuel prices from nearby recognize with ocr only sometimes it miss the last part. So is it possible only show entinties with 2 decimals.