And solved - need to reference back to the array to extract the value:
{% for fav in state_attr('sensor.sonos_favorites','items') %}
{{state_attr('sensor.sonos_favorites','items')[fav]+"\n"|e}}
{%-if not loop.last%}{%-endif%}
{%-endfor%}
On the integrations screen, find the Sonos integration. Click on the entities link to open up just the Sonos entities. In the top right of that screen click on the menu button (upside down triangle) and ensure ‘Show disabled devices’ is checked.
sensor.sonos_favorites should now appear in the list. Click on the sensor name to open the dialogue for that sensor. Advanced is at the bottom. If you don’t see Advanced on this dialog box, it’s a UI bug, click on the title of the box and it should appear.
I’ve been hacking away not really knowing what I’m doing and got this to work:
- obj: "p2b5" # sources list
properties:
"options": >
{% if not (is_state('media_player.living_room','unavailable')) %}{{"(no source)\n"|e}}{%for name in state_attr("sensor.sonos_favorites", "items").values()%}{{name+"\n"|e}}{%-if not loop.last%}{%-endif%}{%-endfor%}{% endif %}
"val": >
{% if not (is_state('media_player.living_room','unavailable')) %}{%for media_id, name in state_attr("sensor.sonos_favorites", "items").values%}
{{loop.index if source == state_attr("sensor.sonos_favorites",'name') }}
{%-endfor%}{% endif %}
"click": "{{ 'false' if (is_state('media_player.living_room','unavailable') or is_state('media_player.living_room','unknown')) else 'true' }}"
Raw payloads are directly passed to the LVGL text rendering engine without any conversion on the MCU. You need to make sure the string is properly encoded into UTF-8 by the application sending the payload! How this is accomplished depends on the Home Automation tool:
At the end of the template you must indicate that Home Assistant needs encoded the string before sending it by appending |e(pipe symbol + e) at the end.
If anyone is interested - this is the final cleaned up solution for OpenHASP changes for Sonos. It addresses the problems with current media display (included extra text) and uses media_player.play_media instead of media_player.select_source as select_source is being depreciated for the Sonos integration.
The rest of the OpenHASP plate definition was unchanged.
plate1:
objects:
- obj: "p1b2" # source
properties:
"text": "{{ state_attr('media_player.sunroom','media_channel') if state_attr('media_player.sunroom','media_channel') else '-' }}"
- obj: "p1b3" # artist and title
properties:
"text": "{{ ( state_attr('media_player.sunroom','media_artist') | replace('TYPE=SNG|TITLE ', '') + ' - ' + state_attr('media_player.sunroom','media_title') | replace('|ARTIST |ALBUM', '') ) if state_attr('media_player.sunroom','media_title') else '-' }}"
- obj: "p1b5" # sources list
properties:
"options": >
{% if not (is_state('media_player.sunroom','unavailable')) %}{{"(no source)\n"|e}}{%for fav in state_attr('sensor.sonos_favorites','items')%}{{state_attr('sensor.sonos_favorites','items')[fav]+"\n"|e}}{%-if not loop.last%}{%-endif%}{%-endfor%}{% endif %}
"click": "{{ 'false' if (is_state('media_player.sunroom','unavailable') or is_state('media_player.sunroom','unknown')) else 'true' }}"
event:
"changed":
- service: media_player.play_media
data:
media_content_type: favorite_item_id
entity_id: media_player.sunroom
media_content_id: "{{ (state_attr('sensor.sonos_favorites', 'items') | list)[val-1] }}"