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?