lovelace-auto-entities
lovelace-auto-entities copied to clipboard
Feature request: Possibility to overwrite state by another attribute
Use case : I use this type of card to show all the entities where the last_seen date is superior to 24 hours ago. I suspect there might be an issue, so I can check and fix it. In this case, with the card "type":"entities", multiple entities will be shown with their name on the left, and state on the left right. Instead of the state, I would like to show the last_seen value, because this is the context I am interested in. In my example above, it would be values such as "30 hours ago" rather than 18.6% or 14.9°C (state).
I tried this one but it still shows off
on the right side instead of the datetime:
type: custom:auto-entities
card:
type: entities
filter:
template: >
{% set events = states.calendar
| rejectattr('state', 'in', ['None','unavailable','unknown','idle'])
| selectattr('attributes.start_time', 'defined')
| sort(reverse=false, attribute="attributes.start_time")
| list
| default(none) %}
{% set ns = namespace(entries=[]) %}
{%- for e in events %}
{%- set ns.entries = ns.entries +
[{
'entity':e.entity_id,
'name':iif(e.attributes.message is defined, e.attributes.message, e.name),
'state':e.attributes.start_time
}] %}
{%- endfor %}
{{ ns.entries }}
By using the template
option you may achieve what you like.
No need to declutter the card by options which are rarely used and may be replaced by this template
option.
For replacing states you may also use custom:template-entity-row
card.
type: custom:auto-entities
card:
type: entities
filter:
template: >-
{% set SENSOR = 'sun.sun' -%}
{%- for attr in states[SENSOR].attributes -%}
{{
{
'type': 'custom:template-entity-row',
'entity': SENSOR,
'name': attr,
'state': state_attr(SENSOR,attr),
'secondary': states(SENSOR)
}
}},
{%- endfor %}