Looping through attributes of a sensor with auto-entities

Hi,
I’m trying to loop through the attributes of a sensor (running VMs or VServers on a machine) to display the running VMs in a auto-entities card:

sensor.machine
vmlabc: "2024-02-14T06:56:16+01:00"
vmltest: "2024-02-14T08:00:06+01:00"
vmwdef: "2024-02-14T06:56:16+01:00"
vsabuild: "2024-02-14T06:55:57+01:00"
vsbuild: "2024-02-14T06:55:57+01:00"

I can loop through these with the following:

type: custom:auto-entities
name: VM/VS
card:
  type: entities
filter:
  template: |-
    {% for wert in states.sensor.machine.attributes %}
    {% if wert[0:2]=='vs' or wert[0:2]=='vm' %}
         {{wert}} 
    {% endif %}
    {% endfor %}
  exclude: []

and get this result:

entities:
  - entity: vmlabc
  - entity: vmltest
  - entity: vmwdef
  - entity: vsabuild
  - entity: vsbuild

I also tried with {{ }} around the block and attributes, but that was not successfull either:

{{
        {
          'type': 'attribute',
          'entity': sensor.machine,
          'attribute': '{{wert}}',
        },
      }},

What can I do to get a list of all the attributes that auto-entities can work with?
Thank you.

You could try something like this:

type: custom:auto-entities
name: VM/VS
card:
  type: entities
filter:
  include:
    - entity_id: /vm*/
      options: secondary_info: last-changed
    - entity_id: /vs*/
      options: secondary_info: last-changed

That’s an example of how you can filter for a couple of different terms and then grab additional information on them. You would have to post the entire device information from developer → states and indicate which attributes you are looking for for me to be more specific.

Thank you for your fast reply.

sensor.machine is one single entity_id and has the following attributes:

CPUTemp: +56.0°C
GPUTemp: +41.0°C
booted: "2024-02-14T06:55:00+00:00"
vmlabc: "2024-02-14T06:56:16+01:00"
vmltest: "2024-02-14T08:00:06+01:00"
vmwdef: "2024-02-14T06:56:16+01:00"
vsabuild: "2024-02-14T06:55:57+01:00"
vsbuild: "2024-02-14T06:55:57+01:00"
updated: "2024-02-14T13:40:30+01:00"

That’s why I tried template instead of include, because as I understand include works with entities, not attributes.

You need to add card parameters, make the entity id fixed and use the output for the attribute

cards_param seems to show cards instead of entities - or is this used for other things too?

I can create a single attribute in an entity card like this:

type: entities
entities:
  - type: attribute
    entity: sensor.machine
    name: vmwtest
    attribute: vmwtest

My question is how I get such a list with the template.

I tried this in the for loop but the result is empty:

{{
        {
          'type': 'attribute',
          'entity': sensor.machine,
          'attribute': '{{wert}}',
        },
      }},

Thank you.

I got this working now:

type: custom:auto-entities
card:
  type: entities
  title: VM/VS v4 template
filter:
  template: |-
    {% set SENSOR = 'sensor.machine' -%}
    {%- for attr in states[SENSOR].attributes['virtual_machines'] -%}
      {{
        {
          'type': 'attribute',
          'entity': SENSOR,
          'attribute': attr,
          'name': attr,
        }
      }},
    {%- endfor %}
sort:
  method: state
  reverse: true

The solution was found at Custom Secondary Info for Entites Card