Margit
February 14, 2024, 2:05pm
1
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.
CO_4X4
(Colorado Four Wheeler)
February 14, 2024, 2:19pm
2
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.
Margit
February 14, 2024, 2:22pm
3
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.
TheFes
(The Fes)
February 14, 2024, 7:00pm
4
You need to add card parameters, make the entity id fixed and use the output for the attribute
Margit
February 14, 2024, 7:55pm
5
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.
Margit
February 15, 2024, 11:42am
6
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