🔹 Auto-entities - Automatically fill cards with entities

so this gets weirder per post… how is your entity created? Is this some custom integration, given the presence of an attribute index, and the absence of all core attributes …?

also, given the example in the docs

are you sure payload shouldnt be inside brackets?

I have a python script. that creates those text_inputs (input_text.xenia_script_*) of data retrieved from an external device using hass.services.call and hass.states.set functions. Index is just a value, we could name it totally different.

I see, that would explain the out of the ordinary attribute indeed. Using the hass.states.set myself in python, and though powerful, it is prone to unexpected outcome.

I’d suggest you take this in to a separate topic, and out of auto-entities, because it would be an issue of getting the correct attribute inside that payload template, and not so much the auto-entities part of it here. It’s getting awfully off-topic because of that.

please check the brackets remark I added earlier, and see if thats relevant?

My understanding is, that the bracket is only used when using the Developer Tools.

Thanks so far for your support.

Regarding auto-entities and what I need to achieve:

  1. My device provides me with a list with an unknown quantity of data pairs: Text + ID
  2. The “Text” part of each of these data pairs should be a button on my front.end.
  3. Pressing the button, a rest_command (an URL) should be called that ends with the provided ID for the button (http://<fixed.URL>/execute_script?ID=ID of data pair)

I started my implementation with generating the input_text entities to achieve this.

What would be your suggestion to approach this?

well, its a bit of a guess on my behalf, but it could be a few things.
if the command expects a number, you should provide it. Currently you’re providing a string. try adding |float at that template?

could also be you are providing the full data pair, while you only need to provide the number?

I cant say, because can not test locally.

and about the brackets: this is a misconception, I use them in all of by payloads. the ones with only 1 data pair, and also the ones with more than that.

I have been using your code for some time now and everything is working fine. Today I miserably tried to apply an enhancement. I want to display an icon based on the entity id. If it is a light, display a lightbulb, if it is a fan, display a fan. What am I missing? This is my code:

type: custom:auto-entities
card:
  type: grid
  columns: 4
  square: false
  title: Lights On
card_param: cards
filter:
  template: |-
    {% for x in expand('group.Lights_House') | selectattr('state','eq','on') %}
    {{- 
    {
      'type': 'custom:mushroom-entity-card', 
      'entity': x.entity_id,
      'primary_info': 'state',
      'secondary_info': 'name',
      'icon': >
        {% if 'fan' in x.entity_id %}
          mdi:fan
        {% else %}
          mdi:lightbulb
        {% endif %}
      'icon_color': 'amber',
      'vertical': true,
      'tap_action': {
        'action': 'call-service',
        'service': 'homeassistant.turn_off',
        'target': { 'entity_id': x.entity_id }
       }
    }
    -}},{%- endfor -%}

Sorry, most probably an easy case. But I spend a lot of time searching and can not figure out why this code won’t style? Neither icons nor border…

type: custom:auto-entities
card:
  title: Batteries
  type: glance
filter:
  exclude:
    - entity_id: '*_battery_state*'
    - entity_id: '*_battery_temperature*'
  include:
    - entity_id: '*battery*'
sort:
  method: state
  numeric: true
unique: true
card_mod:
  style: |
    :host {
      --paper-item-icon-color:
        {% if states(config.entity) | int < 10 %}
          red
        {% elif states(config.entity) | int > 30 %}
          hsl(120, 93%, 39%) !important
        {% else %}
          hsl(60, 100%, 50%)
        {% endif %};
    }

    ha-card {
      border-radius: 150px 15px 15px 15px;

      --ha-card-background: hsla(60,15%,60%,0.4);
    }

I solved this. Per definition templates are not possible for actions. [ Actions - Home Assistant ]

So I now pass the current entity (this.entity_id) as parameter to the rest_command and do the needed templating there.

Thanks @Mariusthvdb for your support.

hmm. I believe you are mixing several concepts and options for those concepts, as auto-entities is a completely different beast than the core card options for actions. Especially since you were using mushroom…

and as I already suspected you needed the entity, not just the attribute, so using this.entity_id would seem a logical solution indeed.

what would help, is if you’d post some results. You’ve been scarce in the ask, but now show even less.

great you’ve got it working now, please post your final solution, so others might benefit from it.

Team,

Is it possible to have and “options:” section in a template filter, in auto-entities ?

I am looking for something like below code - see “options:…”
(The template does generate the correct entities.
The intent is to have the tap_action set to none for these filtered entities).

        - type: conditional
          conditions:
            - entity: input_boolean.on_off_toggle_conditional_unavailable_devices_on
              state: 'on'
            - entity: sensor.unavailable_devices
              state_not: '0'
          card:
            type: custom:auto-entities
            show-empty: false
            filter:
              template: >
                {{ state_attr('sensor.unavailable_devices', 'unavail_list_entity_id') }}
              options:
                icon_color: green
                tap_action:
                  action: none
            card:
              type: glance
              show_state: false
              columns: 6

Thank you for your guidance.

The same problem was also in existence with a default button-card.

So overall this is my solution with providing the complete entity to the rest_command and do the templating there:

Input-Value – generated through a sep. Python script.

Auto-Entities Card to display all entities of this specific input_value entities calling a rest_command and passing over this.entity_id as parameter when tapped (tap_action).

type: custom:auto-entities
card:
  square: false
  columns: 1
  type: grid
show_empty: false
card_param: cards
filter:
  include:
    - entity_id: input_text.xenia_script_*
      options:
        type: custom:mushroom-template-card
        entity: this.entity_id
        primary: |
          {{ state_attr(entity, 'name')}} [{{state_attr(entity, 'index')}}]
        tap_action:
          action: call-service
          service: rest_command.execute_xenia_script_entity
          data:
            entity_id: this.entity_id

rest_command that interprets the handed over entity just for one attribute value within a template using state_attr

rest_command:
  execute_xenia_script_entity:
    url: "http://xenia.local/execute_script?ID={{ state_attr(entity_id, 'index') }}"

1 Like

using that filter requires you to put it all in that same config. have a look at this:

        - type: custom:auto-entities
          filter:
            template: |-
              {% for x in states.climate -%}
                {{
                  {
                    'type': 'custom:mushroom-climate-card',
                    'show_temperature_control': true,
                    'layout': 'horizontal',
                    'entity': x.entity_id,
                    'name': state_attr(x.entity_id, 'friendly_name')|replace('Thermostat ', ''),
                    'tap_action': {'action':'more-info'}
                  }
                }},
              {%- endfor %}

I am showing a list of automation that matches the name with bedroom and livingroom.

action: fire-dom-event
browser_mod:
  service: browser_mod.popup
  data:
    title: Automations
    content:
      type: custom:auto-entities
      card:
        type: entities
        title: Automation
        show_header_toggle: false
      filter:
        include:
          # - entity_id: switch.nr_*
          - domain: automation
            name: "*Bedroom*"
          - domain: automation
            name: "*Livingroom*"
        exclude: []
      sort:
        method: friendly_name

I want to make two columns for separate rooms. but change the friendly name (removing the [Bedroom] and [Livingroom] parts). How can I do that?

action: fire-dom-event
browser_mod:
  service: browser_mod.popup
  data:
    title: Automations
    content:
      type: horizontal-stack
      cards:
        - type: custom:auto-entities
          card:
            type: entities
            title: Bedroom
            show_header_toggle: false
          filter:
            include:
              - domain: automation
                and: 
                  - name: "*Bedroom*"
            exclude: []
          sort:
            method: friendly_name
        - type: custom:auto-entities
          card:
            type: entities
            title: Livingroom
            show_header_toggle: false
          filter:
            include:
              - domain: automation
                and: 
                  - name: "*Livingroom*"
            exclude: []
          sort:
            method: friendly_name

Can anyone help me with this?

Hi,
I have created a minimalist UI popup card using auto-entities and the button card integrations that shows all power and light switches in a specified area (the area name is passed as a variable) and turn them on/off. This works great so thank you for the awesome integration.

I would like to enhance this by grouping the entities by their respective device. A light or power outlet is represented as device in HA which contains an entity for each individual switch (between 1 and 4 per device).

I can create the a custom button card that uses auto-entities to populate a grid with a button card for each switch. I can then enhance it with information from sensors that are also part of the device, such as the amount of power being consumer.

However, to do this I need to populate a list of devices (not entities) in the specified area. I noticed that auto-entities can be nested by passing a list of entities. Is there any way to have auto-entities return a list of devices (instead of entities) and then pass it into another instance of auto-entities?

I am guessing that it can’t (because then it would be called “auto-entities-or-devices” but thought I would ask.

hope, someone can help me with templating.
ive setup a rest sensor to retrieve current connected teamspeak clients:

sensor:
  - platform: rest
    scan_interval: 5
    resource: http://ts3.example.url:10080/1/?clientlist
    verify_ssl: false
    headers:
      x-api-key: "{{ states('input_text.api') }}"
    name: "TS3 Online"
    value_template: "{{ value_json.body | map(attribute='client_nickname') | join(', ') }}"
    json_attributes:
      - body

with these results as attributes:

image

then i have setup some template sensors for up to 5 online clients generated automatically:

template:
  - sensor:
      - name: "{{ state_attr('sensor.ts3_online', 'body')[0]['client_nickname'] }}"
        unique_id: "ts3_0"
        state: "{% if not state_attr('sensor.ts3_online', 'body')[0]['client_nickname'] or state_attr('sensor.ts3_online', 'body')[0]['client_nickname'] == 'serveradmin' %}OFF{% else %}ON{% endif %}"
        attributes:
          image: /local/images/ts3_{{ state_attr('sensor.ts3_online', 'body')[0]['client_nickname'] }}.jpg
      - name: "{{ state_attr('sensor.ts3_online', 'body')[1]['client_nickname'] }}"
        unique_id: "ts3_1"
        state: "{% if not state_attr('sensor.ts3_online', 'body')[1]['client_nickname'] or state_attr('sensor.ts3_online', 'body')[1]['client_nickname'] == 'serveradmin' %}OFF{% else %}ON{% endif %}"
        attributes:
          image: /local/images/ts3_{{ state_attr('sensor.ts3_online', 'body')[1]['client_nickname'] }}.jpg
      - name: "{{ state_attr('sensor.ts3_online', 'body')[2]['client_nickname'] }}"
        unique_id: "ts3_2"
        state: "{% if not state_attr('sensor.ts3_online', 'body')[2]['client_nickname'] or state_attr('sensor.ts3_online', 'body')[2]['client_nickname'] == 'serveradmin' %}OFF{% else %}ON{% endif %}"
        attributes:
          image: /local/images/ts3_{{ state_attr('sensor.ts3_online', 'body')[2]['client_nickname'] }}.jpg
      - name: "{{ state_attr('sensor.ts3_online', 'body')[3]['client_nickname'] }}"
        unique_id: "ts3_3"
        state: "{% if not state_attr('sensor.ts3_online', 'body')[3]['client_nickname'] or state_attr('sensor.ts3_online', 'body')[3]['client_nickname'] == 'serveradmin' %}OFF{% else %}ON{% endif %}"
        attributes:
          image: /local/images/ts3_{{ state_attr('sensor.ts3_online', 'body')[3]['client_nickname'] }}.jpg
      - name: "{{ state_attr('sensor.ts3_online', 'body')[4]['client_nickname'] }}"
        unique_id: "ts3_4"
        state: "{% if not state_attr('sensor.ts3_online', 'body')[4]['client_nickname'] or state_attr('sensor.ts3_online', 'body')[4]['client_nickname'] == 'serveradmin' %}OFF{% else %}ON{% endif %}"
        attributes:
          image: /local/images/ts3_{{ state_attr('sensor.ts3_online', 'body')[0]['client_nickname'] }}.jpg

so they got these attributes:

image: /local/images/ts3_rog.jpg
friendly_name: rog

i have tried to use auto-entities to filter out these clients, but im unable to pass the “image” attributes to use the image as badge image. Currently im trying entity-filter with badge-cards, but the image url does not work…only if i type the url directly:

type: entity-filter
entities:

  - entity: sensor.template_ts3_0
    image: "{{ state_attr('sensor.template_ts3_0', 'image') }}"

state_filter:
  - 'ON'
card:
  type: custom:badge-card
  card_mod:
    style: |
      div#badges {
        display: flex;
        justify-content: space-around;
        font-size: 1.5em;
      }

resulting in an empty badge.

hopefully anyone help me to pass the “image” attribute to a card, eventually with auto-entities?

thank you!

From my own use, and examples on here, it appears that this card ‘forces’ a line break between each row.

Is there any way of removing that whitespace within the card configuration?

Auto-entities Card

Markdown card with whitespace removed
Screenshot 2023-05-24 at 07.38.18

Further to my question in my last post above, about removing whitespace between rows, it appears that altering the font size only alters the spacing between the icons and not the font size or row spacing of the text (examples below).
So, to bump my original question, is it possible to remove whitespace/line breaks between rows and how can I solve this issue of custom font size only resizing space between icons and not text?

Font size = 12px
Screenshot 2023-05-29 at 08.18.45

Font size = 8px
Screenshot 2023-05-29 at 08.18.05

card-mod thread → 1st post → link at the bottom → how to manage space between rows

1 Like

Do you mean this thread? card-mod

I can’t find any link or post with that reference in the whole thread.

EDIT: Found the link credited to you. Thank you.