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

dont think it can be done, because youā€™d have to auto populate the row with the type: buttons, and those require the entity key.

smthing like this would be the idea:

type: entities
entities:
  - type: buttons
    entities:
      - entity: sun.sun
      - entity: sun.sun
      - type: custom:auto-entities
        card:
          type: entities
        filter:
          include:
            - domain: update

but it obviously does not work, and complains about that entity key

We can only do that using a template filter and create the list like this:

          template: >
            {% for s in states.update %}
                {
                  "entity": {{s.entity_id}},
                  "name": {{s.name}},
                  "secondary_info": 'last-changed'
                }
               %}
            {% endfor %}

or namespace:

            {% set ns = namespace(updates=[]) %}
            {% for s in states.update %}
              {% set name = state_attr(s.entity_id,'friendly_name') %}
              {% set ns.updates = ns.updates + [
                {
                  "entity": s.entity_id,
                  "name": name,
                  "secondary_info": 'last-changed'
                }
              ] %}
            {% endfor %}
            {{ns.updates}}

but even when that succeeds, we can not add in inside the entities card as type: buttons because it sees the auto-entities keys, like card and typeā€¦

1 Like
light_area_template:
  card:
    type: entities
    title: "[[title]]"
    entities:
      - type: custom:auto-entities
        card_param: entities
        card:
          type: custom:hui-buttons-row
        filter:
          include:
            - group: "[[group]]"
              options:
                show_name: true
        sort:
          method: name
          ignore_case: true
        exclude:
          - state: "unavailable"
1 Like

did you test that? because it throws the

1 Like

I did not, check my response on discord :wink:

1 Like

Yup. Here are my screenshots.
In edit mode. The second one is yours.


And, after Done.

YES!

it can be doneā€¦

I normally use the custom:hui-element to add stuff inside an entities card,

type: custom:auto-entities
card:
  type: custom:hui-element
  card_type: buttons
filter:
  include:
    - domain: update

but in this case I couldnā€™t get it to work.

So, we (Petro) checked the Dom once more:

SchermĀ­afbeelding 2024-05-07 om 14.28.04

type: custom:auto-entities
card:
  type: custom:hui-buttons-row
filter:
  include:
    - domain: update

and add that directly.

btw, Itā€™s not a card, but a row, and thatā€™s why the hui-element above didnt work. this does:

type: custom:auto-entities
card:
  type: custom:hui-element
  row_type: buttons
filter:
  include:
    - domain: update

if you want to combine with other entities, you can do:

type: entities
entities:
  - type: custom:auto-entities
    entities:
      - entity: sun.sun
      - entity: sun.sun  
    card:
      type: custom:hui-buttons-row
    filter:
      include:
        - domain: update

Should work for @clau-bucur now too, please try?

3 Likes

Thanks alot guys! It works very nicely!

1 Like

Hello everyone. I am still having issues with the auto entities card leaving a gap in the new sections view, even when show_empty is set to false.

Hopefully this video helps demonstrate this (turn on sound). Any help most welcome!

@thomasloven Any thoughts on the above spacing issue would be most appreciated please. Thank you

I am pretty sure that this is a known deficiency of the new sections layout. The sections layout is experimental. If you go back to the release notes + all of the comments related to that release, you will see many instances of your problem. I do not believe that at this point in time they have been resolved.

Ok, thanks for confirming that. Another user here @jeffcrum said it was working as expected which made me think it was an isolated issue. Iā€™ll just keep an eye on it as future updates are released.

Yeah, definitely a recurring issue

homeassistant sections conditional space - Google Search

Sorry. I completely missed that your question was for the new sections view.

Hello everybody!

I have a particular use case for auto-entities, that I think would need nesting 2 auto-entities.

My need is to recall the entity filtered in the external auto-entity inside of the internal one.

I will use it to call a pop-up with the browser-mod, and then populate the pop-up with additional information from the external auto-entity.

This is card populated with the external auto-entity. Then, at the tap of a single element, I would like to open a pop-up card like the following, with all the associated information:

In the following, the code developed so far:

type: custom:stack-in-card
mode: vertical
cards:
  - type: markdown
    content: '# Containers'
    title: ''
    card_mod:
      style: |
        ha-card {
          border: transparent;
        }
  - type: custom:auto-entities
    card_param: cards
    show_empty: true
    sort:
      method: friendly_name
      reverse: false
      ignore_case: false
      ip: false
      numeric: false
    card:
      square: false
      type: grid
      columns: 2
    filter:
      exclude:
        - entity_id: '*memory*'
        - entity_id: '*cpu*'
        - entity_id: '*containers*'
        - entity_id: '*version*'
      include:
        - domain: sensor
          entity_id: '*mexlab_docker_*'
          options:
            type: custom:mushroom-template-card
            entity: this.entity_id
            primary: |
              {{ state_attr(entity, "friendly_name") }}
            secondary: |
              {{ entity }}
            icon: >
              {% set icon_found = true %}

              {% if state_attr(entity, "friendly_name") == "Authentik-PostgresDB
              " %}
                mdi:database
              {% elif state_attr(entity, "friendly_name") == "Authentik-RedisDB
              " %}
                mdi:database
              {% elif state_attr(entity, "friendly_name") == "Authentik-Server "
              %}
                mdi:shield-key-outline
              {% elif state_attr(entity, "friendly_name") == "Authentik-Worker "
              %}
                mdi:key
              {% elif state_attr(entity, "friendly_name") == "Dashy-Dashboard "
              %}
                mdi:view-dashboard
              {% elif state_attr(entity, "friendly_name") == "DockerProxy " %}
                mdi:server-network-outline
              {% elif state_attr(entity, "friendly_name") == "Duplicati " %}
                mdi:backup-restore
              {% elif state_attr(entity, "friendly_name") == "EspHome " %}
                phu:esphome
              {% elif state_attr(entity, "friendly_name") == "Homarr-Dashboard "
              %}
                mdi:view-dashboard
              {% elif state_attr(entity, "friendly_name") == "HomeAssistant " %}
                mdi:home-assistant
              {% elif state_attr(entity, "friendly_name") ==
              "Mosquitto-Portainer " %}
                phu:mosquitto
              {% elif state_attr(entity, "friendly_name") == "Nextcloud-DB " %}
                mdi:database
              {% elif state_attr(entity, "friendly_name") == "Nextcloud " %}
                phu:nextcloud
              {% elif state_attr(entity, "friendly_name") ==
              "Nginx-Proxy-Manager " %}
                phu:nginx
              {% elif state_attr(entity, "friendly_name") == "Portainer " %}
                phu:portainer
              {% elif state_attr(entity, "friendly_name") == "Speedtest-DB " %}
                mdi:database
              {% elif state_attr(entity, "friendly_name") == "Speedtest-tracker
              " %}
                phu:speedtest
              {% elif state_attr(entity, "friendly_name") == "TasmoAdmin " %}
                mdi:power-plug
              {% elif state_attr(entity, "friendly_name") == "Uptime-Kuma " %}
                phu:kuma
              {% elif state_attr(entity, "friendly_name") == "Wireguard-VPN " %}
                si:wireguard
              {% elif state_attr(entity, "friendly_name") == "Zigbee2Mqtt " %}
                mdi:zigbee
              {% else %}
                mdi:cloud-question
                {% set icon_found = false %}
              {% endif %}
            icon_color: |
              {% if states(entity) == "running" %}
                blue
              {% elif states(entity) == "exited"%}
                red
              {% else %}
                orange
              {% endif %}
            tap_action:
              action: more-info
            double_tap_action:
              action: fire-dom-event
              browser_mod:
                service: browser_mod.popup
                data:
                  title: My title
                  content:
                    type: custom:auto-entities
                    card_param: cards
                    show_empty: true
                    sort:
                      method: friendly_name
                      reverse: false
                      ignore_case: false
                      ip: false
                      numeric: false
                    card:
                      square: false
                      type: entities
                      columns: 2
                    filter:
                      exclude:
                        - entity_id: '*memory*'
                        - entity_id: '*cpu*'
                        - entity_id: '*containers*'
                        - entity_id: '*version*'
                      include:
                        - entity_id: ?
            hold_action:
              action: none
            card_mod:
              style: |
                ha-card {
                  border: transparent;
                }

What should I write inside of the internal entity_id ?

So I have a question which I just cant seem to fathom a solution for or why its happening. So I have this card here:

type: custom:auto-entities
card:
  title: Temperatures and Humidity Readings
  type: entities
filter:
  template: >-
    {% set area_filter = ['area1', 'area2'] %}
    {% set temp_filter = ['sensor.temperature_sensor_1', 'sensor.temperature_sensor_2'] %}
    {% set humid_filter = ['sensor.humidity_sensor_1', 'sensor.humidity_sensor_2'] %}

    {%- set areas = states.sensor
      | selectattr('attributes.device_class', 'in', ['temperature', 'humidity'])
      | rejectattr('entity_id', 'in', temp_filter + humid_filter)
      | map(attribute='entity_id')
      | map('area_name') | unique | reject('none') 
      | reject('in', area_filter)
      | list -%}

    {% if areas | length == 0 %}
      {{
        {
          'type': 'custom:button-text-card',
          'title': 'No temperature or humidity sensors found',
          'icon': 'mdi:chat-question',
          'background_color': 'var(--primary-color)'
        }
      }},
    {% else %}  
      
    {%- for area in areas -%}
      {% set temperatures = states.sensor
        | selectattr('attributes.device_class', 'eq', 'temperature')
        | rejectattr('entity_id', 'in', temp_filter)
        | selectattr('entity_id', 'in', area_entities(area))
        | list -%}
      {% set humidities = states.sensor
        | selectattr('attributes.device_class', 'eq', 'humidity')
        | rejectattr('entity_id', 'in', humid_filter)
        | selectattr('entity_id', 'in', area_entities(area))
        | list -%}   

      {% set all_sensors = temperatures + humidities -%}

      {{
        {
          'type': 'custom:button-text-card',
          'title': area,
          'icon': 'mdi:thermometer-water',
          'background_color': 'var(--primary-color)'
        }
      }},

      {%- if temperatures | length > 0 or humidities | length > 0 -%}
        {%- for sensor in all_sensors -%}
          {{
            {
              'type': 'horizontal-stack',
              'cards': [
                {
                  'type': 'custom:mini-graph-card',
                  'animate': 'true',
                  'height': '40',
                  'entities': [sensor.entity_id],                          
                  'line_width': '2',
                  'font_size': '100',
                  'show': {                            
                    'labels': 'true',
                    'fill': 'true',
                    'average': 'true',
                    'extrema': 'true',                            
                  },
                  'points_per_hour': '2',
                  'color_thresholds': [
                    { 'value': '0', 'color': 'blue' },
                    { 'value': '15', 'color': '#42f57b' },
                    { 'value': '20', 'color': '#51f542' },
                    { 'value': '25', 'color': '#ffbb00' },
                    { 'value': '30', 'color': 'red' }
                  ]                 
                },
                                      
              ],
            }
          }},
        {%- endfor %}     
      {%- endif %}
    {%- endfor %}  
    {%- endif %}

This card loops over all my areas and should list all my temperature and humidity sensors in my home with its own graph. Now, the code presented here will unfortunatley produce two horizontal-stacks per area - one for the temperature sensor and one for the humidity sensor, but that is not what is bothering me here.

The output looks like this!

If I try to copy the code in the error and paste it into a card, it works flawlessly and I cannot fathom why this should happen.

Is there anyone that has any idea as to why this isnā€™t rendering properly?

You are effectively trying to use a horizontal-stack card as an entity, which is not possible by default, hence the error.

You can get round this by using another of Thomas LovĆ©nā€™s custom cards hui-element.

Trying to use exclude - state away , but i donā€™t see a change when using that option, is this a bug?

2024-05-26 12_13_46-Andrew Overview Dashboard ā€“ Home Assistant - Vivaldi

Here is my card code in itā€™s current state.

type: custom:auto-entities
sort:
  method: attribute
  attribute: signal_level
  ignore_case: false
  reverse: true
filter:
  include:
    - domain: device_tracker
      attributes:
        wireless: true
      options: {}
  exclude:
    - state: Away
card:
  type: custom:bar-card
  attribute: signal_level
  height: 20px
  positions:
    icon: 'off'
    indicator: 'off'
    name: inside
  severity:
    - color: red
      from: 0
      to: 40
    - color: orange
      from: 41
      to: 70
    - color: green
      from: 71
      to: 100
  show_header_toggle: false
  title: Signal Level
show_empty: true

I would expect several of the top entries to be excluded from this card, but that doesnā€™t happenā€¦
2024-05-26 12_15_52-Andrew Overview Dashboard ā€“ Home Assistant - Vivaldi

Hey crew,
Iā€™m using auto-entities to populate a list of Temperature Sensors, but Iā€™m having trouble generating the Name and State within the Mushroom Template Cards.

My goals are:

  1. for the Primary field: display the Friendly Name (and if possible, I would love to remove the words 'Climate Sensor Temperature" from each field, so that ā€œKitchen Climate Sensor Temperatureā€ would simply read as ā€œKitchenā€)
  2. for the Secondary field: display the State, IE: 69.1 Ā°F

Iā€™m wondering if I need to abandon the mushroom-template-card and opt for config-template-card but Iā€™m not quite sure.

Here is my code so far, along with a screenshot. Any help is appreciated! Thanks crew,

image

type: custom:auto-entities
card:
  square: false
  type: grid
  columns: 1
filter:
  include:
    - name: /Climate Sensor Temperature/
      options:
        type: custom:mushroom-template-card
        icon: mdi:thermometer
        primary: this.entity_id
        secondary: state
        icon_color: |-
          {% set state=states('this.entity_id') %}
          {% if state > '70' %}
            red
          {% elif state > '69' %}
            orange
          {% else %}
            yellow
          {% endif %}
  exclude:
    - state: unavailable
sort:
  method: state
  reverse: true
  numeric: true
show_empty: false
card_param: cards


Same-day edit:

FWIW, I also tried switching to mushroom-entity-card instead of the mushroom-template-card version above. The mushroom-entity-card version generates the device name & state/temperature correctly, but the color-coding breaks and makes the icons black.

image

I think you should use state away, so lowercase, not the translated one that is shown on the frontend.

1 Like

tried thatā€¦didnā€™t work, unfortunately
tried with quotes
tried with no quotes and stars
tried with stars and no quotes
tried upper case Away with quotes and stars
tried with upper case Away and stars with no quotes

nothing seems to workā€¦

perhaps itā€™s because the include and exclude are contradictive? I am including All wireless attributes that are trueā€¦but excluding anything that is awayā€¦so because the wireless value is true, the entity remains? I really dont knowā€¦ Iā€™m outta guesses at this point.