Hi all,
I was wondering if you can display sensor items, in this case specifically sensor.sonos_favorites, as buttons.
I have already managed to put the favorites in an input_select with an automation to set the options like this when the sensor.sonos_favorites changes:
"{{ state_attr('sensor.sonos_favorites', 'items').values() | list }}"
Then I can play the favorite with an automation that checks if the value of the input_select has changed. The automation calls the media_player.play_media service:
service: media_player.play_media
data:
media_content_id: >-
{{ (state_attr('sensor.sonos_favorites',
'items')|list)[(state_attr('sensor.sonos_favorites', 'items').values() |
list).index(states('input_select.sonos_favorieten'))] }}
media_content_type: favorite_item_id
target:
entity_id: "{{ sonos_speaker }}"
continue_on_error: true
Now I would like to display the favorites as buttons and add the action to play the favorite.
I have tried that with auto-entities (which is probably not even the right card type to achieve this), and that has not been successful yet.
type: custom:auto-entities
card:
type: grid
columns: 3
square: true
card_param: cards
filter:
template: |
{% set items = state_attr('sensor.sonos_favorites', 'items') %}
{% for value in items.items() %}
- type: button
name: "{{ value }}"
tap_action:
action: call-service
service: media_player.play_media
service_data:
media_content_id: "{{ value }}"
media_content_type: favorite_item_id
target:
entity_id: "{{ sonos_speaker }}"
show_name: true
show_icon: false
{% endfor %}
Does anyone have an idea what I could try next?