🔹 Auto-entities - Automatically fill cards with entities

Well, to write less code and adhere to DRY

filter:
  include:
	- state: "unavailable"
	  domain: switch
	  attributes:
		device_class: outlet
	- domain: switch
	  state: "unavailable"
	  attributes:
		device_class: outlet

Would become

filter:
  include:
	- state: 
		- "unavailable"
		- "on"
	  domain: switch
	  attributes:
		device_class: outlet

If a list was allowed for the state for example (I know I talked about entity_ids, but the same principle would apply there)

Maybe there is a way to achieve this already with regex or something. I’m still quite new to this addon :slight_smile:

Exactly))))

type: custom:auto-entities
card:
  type: entities
filter:
  include:
    - domain: sensor
      state: /unavailable|unknown/

Ah, thanks, that solved it! :100: I take my original question back :smiley:

is there a way to show the attributes of an entity see below. I want to create auto entities of a device’s attributes?

link

legend! Thank you!

I’m asking you for help. I have sensors called sensor.xxx_rssi and I wanted them to turn on the switch of the same name with the ending _restart (switch.xxx_restart) when pressed (tap_action). Is it feasible?

type: custom:auto-entities
show_empty: false
sort:
  method: state
  numeric: true
  reverse: false
  ignore_case: false
  ip: false
card:
  type: custom:bar-card
  title: WIFI
  positions:
    icon: 'off'
  height: 20px
  min: -100
  max: -30
  severity:
    - color: '#cc0000'
      from: -100
      to: -80
    - color: '#914900'
      from: -79
      to: -70
    - color: '#cc6600'
      from: -69
      to: -63
    - color: '#679900'
      from: -62
      to: -47
    - color: '#009900'
      from: -46
      to: 0
  columns: '1'
filter:
  include:
    - entity_id: sensor.*_rssi*  # sensor.xxx_rssi
      options:
        tap_action:
          action: call-service
          service: switch.turn_on
          service_data:
            # Note the magic value this.entity_id here
            entity_id: switch.???_restart # switch.xxx_restart
1 Like

This card seems to solve very elegantly the use cases of auto “selecting” entities to display.
The one enhancement (and I admit it isn’t completely trivial) is to allow more powerful ways to use the collected entities to generate other cards.
Currently the card will take a single card name and populate its entities attribute.
Ideally, we could also provide something like a “grid” card type and then a grid_cell card which will then be instantiated once for each of the entities found.
e.g.

card: "grid"
  grid_cell_card: "custom:button"
  grid_cell_card_options:
      ... attributes you can set supported by the grid_cell_card 

To keep things simple, these options should be a direct pass-through so that this addon has only minimal coupling with any other addons. The only coupling will be with the native “grid” card.

This will be incredibly powerful and fill in a pretty serious deficiency in the core HA frontend and will further massively reduce duplication of card boilerplate.

The auto-entities card already can fill the Grid card with other cards.

2 Likes

but do those cards need to support entities or it knows if they support entity to just pass one at a time?
sorry i’m sure i’m missing something - can you give me a very simple example of auto-entities card filling a grid with e.g. custom-buttons?

It was posted here, search for “grid”

1 Like

apologies, and thank you!!

I use

    sort:
      method: attribute
      attribute: sort-date
      reverse: false
glas 20231113
papier 20231113
pdm 20231023
restafval 20231030

but it should be

pdm 20231023
restafval 20231030
papier 20231113
glas 20231113

I want the first coming first. What am I doing wrong ?

Hi everyone,

I would like to sort this by last_changed. But since I am pulling my entities from a group, I feel like I need to do a sort at the time of expand or when defining ‘activity’ ( which I could probably figure out). The problem is I am pulling the last_changed data from a separate sensor attribute I use to save that data to prevent losing the last_changed on reboot. I think I may be a little out of my depth here. :sweat_smile:

type: custom:auto-entities
card:
  type: entities
  title: Human Activity
filter:
  template: >-
    {% set activities = expand(states.binary_sensor.kitchen_occupancy_group.attributes.entity_id) -%}

    {%- for activity in activities -%}
    {%- set last_changed = state_attr('sensor.last_changed_history', 'changes')[activity.entity_id] | as_datetime -%}
      {{
        {
          'type': 'custom:template-entity-row',
          'entity': activity.entity_id,
          'name': activity.attributes.friendly_name.split('Kitchen Human Activity')[1],
          'state': 'Clear' if activity.state == 'off' else 'Detected',
          'color': 'red' if activity.state == 'on' else '',
          'secondary': (relative_time(last_changed), ' ago'),
        }
      }},
    {%- endfor -%}

I’m getting trouble making this code work. Can somebody check for me?
While I tap icon, I get expected int for dictionary value @data['product_id']

    - type: custom:auto-entities
      card:
        type: entities
        # layout_type: grid
      filter:
        include:
          - entity_id: sensor.shopping_list_with_grocy_.*
            sort:
              method: friendly_name
            attributes:
              location: Fridge
              # qty_in_stock: /\b(?!0\b)\b\d+\b/
              parent_product_id: null
            options:
              type: custom:multiple-entity-row
              entity: this.entity_id
              show_entity_picture: false
              show_icon: false
              show_state: false
              secondary_info:
                attribute: qty_in_stock 
              entities:
                - icon: mdi:silverware-fork-knife
                  name: 1
                  tap_action:
                    action: call-service
                    confirmation:
                      text: Consume Quick Consume Amount?
                    service: grocy.consume_product_from_stock
                    service_data:
                      product_id: this.attributes.product_id
                      amount: this.attributes.quick_consume_amount
                      allow_subproduct_substitution: true
                      transaction_type: CONSUME
                - icon: mdi:silverware-fork-knife
                  name: ALL
                  tap_action:
                    action: call-service
                    confirmation:
                      text: Consume ALL?
                    service: grocy.consume_product_from_stock
                    service_data:
                      product_id: this.attributes.product_id
                      amount: this.attributes.qty_in_stock
                      allow_subproduct_substitution: true
                      transaction_type: CONSUME
                - icon: mdi:package-variant
                  name: 1
                  tap_action:
                    action: call-service
                    confirmation:
                      text: Open Quick Consume Amount?
                    service: grocy.open_product
                    service_data:
                      product_id: this.attributes.product_id
                      amount: this.attributes.quick_consume_amount
                      allow_subproduct_substitution: true
      sort:
        method: attribute
        attribute: location

Is it possible to create a weblink?

Hi all,
I’m restarting with HA after a while and struggling with browser mod popupcard using auto entities.
I tried a lot and searched the who forum, but I’m not able to combine the following in the correct way.

Aim: I want a button card showing the current number of lights on.
When clicking on the button, a popup should appear and show the lights which are on.

Can someone help me to get this code working?
Many thanks in advance!

type: custom:button-card
entity: sensor.lights_on_count
show_name: false
show_state: true
layout: icon_state
aspect_ratio: 2/1
styles:
  grid:
    - grid-template-areas: '"x1 s i x2"'
    - grid-template-columns: 1fr min-content 22px 1fr
    - grid-template-rows: 1fr
  state:
    - font-size: 1.0em
    - padding-right: 10px
  icon:
    - width: 100%
tap_action:
  action: fire-dom-event
  browser_mod:
    service: browser_mod.popup
    deviceID: this
    data:
      title: Lights on
    card:
      type: custom:auto-entities
      card: null
      entities:
         show_header_toggle: false
        state_color: false
      filter:
        template: |
          {% for thing in states %}
            {% if thing.state == "on" and thing.domain == "light" %}
              {{ thing.entity_id}}
            {% endif %}
          {% endfor %}
      sort:
        method: friendly_name
      show_empty: false

Only the popup with title appears but nothing else.

also, your spacing seems off on show_header_toggle

this was only a mistake when copy the code in here. I don’t get error messages in the card configuration.

Well, perhaps you could paste your code as it actually appears in your configuration. Otherwise it’s just a guessing game, if that makes sense.

Here is what your auto-entities card configuration should look like. Let’s rule that out first:

      type: custom:auto-entities
      card:
        type: entities
        show_header_toggle: false
        state_color: false
      filter:
        template: |
          {% for thing in states %}
            {% if thing.state == "on" and thing.domain == "light" %}
              {{ thing.entity_id}}
            {% endif %}
          {% endfor %}
      sort:
        method: friendly_name
      show_empty: false