petro
(Petro)
January 26, 2022, 12:40pm
21
Your first error can be solved by providing a default after first and you can build safety in it by filtering out media players without last_called
{{ states.media_player | selectattr('attributes.last_called', 'defined') | selectattr('attributes.last_called','eq',true) | map(attribute='entity_id') | first | default(none) }}
I believe someone else answered the second error.
2 Likes
using this example breaks the whole thing and the last call function doesnt work anymore
petro
(Petro)
January 27, 2022, 10:49am
23
You’ll have to post everything. I have Alexa media player and the template works as expected.
dbrunt
(Daniel)
July 26, 2022, 7:18am
24
petro:
Your first error can be solved by providing a default after first and you can build safety in it by filtering out media players without last_called
{{ states.media_player | selectattr('attributes.last_called', 'defined') | selectattr(
Thank you Petro! I had the original version:
- name: "Last Alexa":
unique_id: last_alexa
state: "{{ states.media_player | selectattr('attributes.last_called','eq',true) | map(attribute='entity_id') | first }}"
which I have been using successfully for a while which correctly worked as a templated sensor but failed to render in the template editor for some weird reason!
I’ve taken your code one step further now and applied it to the name:
…
- name: "{{ states.media_player | selectattr('attributes.last_called', 'defined') | selectattr('attributes.last_called','eq',true) | map(attribute='name') | first | default(none) }}"
unique_id: last_alexa
state: "{{ states.media_player | selectattr('attributes.last_called', 'defined') | selectattr('attributes.last_called','eq',true) | map(attribute='entity_id') | first | default(none) }}"
- type: entities
entities:
- entity: sensor.last_alexa
type: custom:multiple-entity-row
show_state: false
secondary_info: sensor.last_alexa