up to now, I have a perfectly fine working setup where my media (sound) files are stored in /config/local/sounds
I can play these with
- unique_id: tune
name: Tune
state: >
{% set state = states('input_select.tune') %}
{% set url = states('input_text.base_url') %}
{% set path = '/local/sounds/tunes/'%}
{% set sound_bite = state|slugify %}
{% set ext = '.mp3' %}
{{[url,path,sound_bite,ext]|join}}
or
- unique_id: sound_bite
name: Sound bite
state: >
{% set state = states('input_select.sound_bite') %}
{% set url = states('input_text.base_url') %}
{% set path = '/local/sounds/sound_bites/'%}
{% set sound_bite = state|slugify %}
{% set ext = '.mp3' %}
{{[url,path,sound_bite,ext]|join}}
and scripts
sound_bite:
alias: Sound bite
mode: restart
sequence:
service: media_player.play_media
data:
entity_id: >
{{states('sensor.sound_bite_player')}}
media_content_id: >
{{states('sensor.sound_bite')}}
media_content_type: music
tune:
alias: Tune
mode: restart
sequence:
service: media_player.play_media
data:
entity_id: >
{{states('sensor.tune_player')}}
media_content_id: >
{{states('sensor.tune')}}
media_content_type: music
base_url points to the url we are served by Nabucasa so is my /config
share.
Frenck pointed me to the fact I shouldn’t need the base_url in that template, and I can confirm that:
- unique_id: sound_bite
name: Sound bite
state: >
{% set state = states('input_select.sound_bite') %}
{% set path = '/local/sounds/sound_bites/'%}
{% set sound_bite = state|slugify %}
{% set ext = '.mp3' %}
{{[path,sound_bite,ext]|join}}
works fine too!
Since Homeassistant also has the /media
share, and that’s used when uploading file from the UI, I figured to used that.
/media
should be the default as described in Media Source - Home Assistant
but I keep getting error when trying to used that share using:
{% set state = states('input_select.sound_bite') %}
{% set path = '/audio/sound_bites/'%}
{% set sound_bite = state|slugify %}
{% set ext = '.mp3' %}
{{[path,sound_bite,ext]|join}}
error:
Failed to cast media http://192.168.1.71/:port/audio/sound_bites/confusing_voice_mail.mp3?authSig=redacteddDA from internal_url (http://192.168.1.71/:port). Please make sure the URL is: Reachable from the cast device and either a publicly resolvable hostname or an IP address
same error is shown with the full nabucasa link. apparently it doesnt see my /media
share, but keeps pointing to the /config
share.
I dont have any _url set, and use local for internal, NabuCasa for external
/config share:
/media share:
which are recognized alright in the system:
and which I can play via the UI:
and even the automation editor sees this correctly:
I just can NOT play them via any backend command
from dev tools services, this works:
service: media_player.play_media
target:
entity_id: media_player.googlehome_library
data:
media_content_type: "music"
media_content_id: "/local/sounds/sound_bites/bike_horn.mp3"
which is on my /config
share
trying to point that to media-source://media_source/<media_dir>/<path>
where Default media_dir
is local
, would translate to
service: media_player.play_media
target:
entity_id: media_player.googlehome_library
data:
media_content_type: "music"
media_content_id: "media-source://audio/sound_bites/bike_horn.mp3"
throws an error KeyError: ‘media’
websocket_api script: Error executing script. Unexpected error for call_service at pos 1: 'media'
or if I add the /media share in that path, same error
please have a look how I could fix this issue?
thanks!