Template Variable question for new Media Selector 2022.4.0

The new media selector has me scratching my head…

What the heck? It pulls in a ton of metadata, and when you try to plug that into, say media player, in a Blueprint it says it doesn’t like the metadata…
Anyone get that one working?

(In the blueprint…)

blueprint:
  name: Media Player Script Blueprint test
  description: 'stuff here'
  domain: script
  homeassistant:
    min_version: 2022.4.0
  input:
    file_2_play:
      name: Media File to play
      description: 'stuff here'
      default: []
      selector:
        media: {}
mode: queued
sequence:
- alias: Media Player Blueprint Script
  service: media_player.play_media
  data:
    !input 'file_2_play

That’s what looked the most promising… but fails

Media Player test2: Error executing script. Invalid data for call_service at pos 1: extra keys not allowed @ data['metadata']]

script that is generated from the trace:

alias: Media Player Blueprint Script
service: media_player.play_media
data:
  entity_id: media_player.common_group_2
  media_content_id: media-source://media_source/local/mp3/FireTruck.mp3
  media_content_type: audio/mpeg
  metadata:
    title: FireTruck.mp3
    thumbnail: null
    media_class: music
    children_media_class: null
    navigateIds:
      - {}
      - media_content_type: app
        media_content_id: media-source://media_source
      - media_content_type: ''
        media_content_id: media-source://media_source/local/mp3

The more I looked at it, the more made me think bug so I posted an issue:

If anyone has a solution other than manually deleting the stuff below metadata:, let me know.

The suggestion there was to put the selector result in a variable and pull out what you want.
This sounds good but is a bit beyond me how.
This looks like a dictionary, so I tried to pull the stuff out that way, but it fails to find the key.
Any smart people want to give me a hand here?

blueprint:
  name: Media Player Script Blueprint test
  description: 'stuff here'
  domain: script
  homeassistant:
    min_version: 2022.4.0
  input:
    file_2_play:
      name: Media File to play
      description: 'stuff here'
      default: []
      selector:
        media: {}
mode: queued
variables:
  output: !input "file_2_play"
  e_id: '{{ (output)[entity_id] }}'
  c_id: '{{ (output)[media_content_id] }}'
  c_type: '{{ (output)[media_content_type] }}'
sequence:
- alias: Media Player Blueprint Script
  service: media_player.play_media
  data:
    entity_id: '{{ e_id }}'
    media_content_id: '{{ c_id }}'
    media_content_type: '{{ c_type }}'

Media Player Script Blueprint test 5: Error executing script. Invalid data for call_service at pos 1: not a valid value for dictionary value @ data['entity_id']

trace rendered script:

mode: single
variables:
  output:
    entity_id: media_player.kitchen_speaker
    media_content_id: media-source://media_source/local/mp3/steps.mp3
    media_content_type: audio/mpeg
    metadata:
      title: steps.mp3
      thumbnail: null
      media_class: music
      children_media_class: null
      navigateIds:
        - {}
        - media_content_type: app
          media_content_id: media-source://media_source
        - media_content_type: ''
          media_content_id: media-source://media_source/local/mp3
  e_id: '{{ (output)[entity_id] }}'
  c_id: '{{ (output)[media_content_id] }}'
  c_type: '{{ (output)[media_content_type] }}'
sequence:
  - alias: Media Player Blueprint Script
    service: media_player.play_media
    data:
      entity_id: '{{ e_id }}'
      media_content_id: '{{ c_id }}'
      media_content_type: '{{ c_type }}'
alias: Media Player Script Blueprint test 4
icon: mdi:battery-20

I did try some expand stuff but truly I don’t know what I’m doing with that. Obviously not a programmer here. Just want to see the media selector work.
The HA documentation is not helpful, yet. I would be happy fixing that should I figure this out.

Still thinking this shouldn’t be this hard no matter what Paulus says. He closed the issue and doesn’t see a problem, so it must be me that thinks this is too complicated, right?

Call me crazy, but expanding the media player to accept the metadata or stripping the metadata from the selector would make more sense, right?

If you use the media selector in the automation UI editor, it generates this as code, so this is how I have to change the return to by splitting it in variables.

- id: '1649691367745'
  alias: New Automation
  description: ''
  trigger:
  - platform: state
    entity_id: switch.c1
    to: 'on'
  condition: []
  action:
  - service: media_player.play_media
    target:
      entity_id: media_player.kitchen_speaker
    data:
      media_content_id: media-source://media_source/local/mp3/jaws_x.mp3
      media_content_type: audio/mpeg
    metadata:
      title: jaws_x.mp3
      thumbnail:
      media_class: music
      children_media_class:
      navigateIds:
      - {}
      - media_content_type: app
        media_content_id: media-source://media_source
      - media_content_type: ''
        media_content_id: media-source://media_source/local/mp3
  mode: single

I think it’s a dict, but I have something wrong in the conversion.
It shouldn’t be this difficult…

This is working…

blueprint:
  name: Media Player Script Blueprint test
  description: 'stuff here'
  domain: script
  homeassistant:
    min_version: 2022.4.0
  input:
    media:
      name: Media File to play
      description: 'stuff here'
      default: []
      selector:
        media: {}
variables:
  _media: !input media
  eid: '{{ _media.entity_id }}'
  mid: '{{ _media.media_content_id }}'
  mct: '{{ _media.media_content_type }}'
mode: queued
sequence:
- alias: Media Player Blueprint Script
  service: media_player.play_media
  target:
    entity_id: "{{ eid }}"
  data:
    media_content_id:  "{{ mid }}"
    media_content_type:  "{{ mct }}"

Documentation update has been pushed to update the media selector documentation…

Also this is happening, so this will probably just work in the next release,
without the dancing variables…