Migrating media files from /config/local to /media

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!

So I was able to solve this in testing in dev tools services:

service: media_player.play_media
target:
  entity_id: media_player.googlehome_library
data:
  media_content_type: music
  media_content_id: media-source://media_source/local/sounds/sound_bites/bike_horn.mp3

and that makes a lot of noise in the library ! :wink:

so given the fact the default media_source is reached at media-source://media_source/local/ the path following that is what is on the root of share media:

where

  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

used to point me to /local/sounds/sound_bites/xxx.mp3 (with /local being /config/www ) I now need to change the path in that script to

    sequence:
      service: media_player.play_media
      data:
        entity_id: >
          {{states('sensor.sound_bite_player')}}
        media_content_id: >
          media-source://media_source{{states('sensor.sound_bite')}}
        media_content_type: music

So glad I could clinch this, because even though this should be the default path, leaving media-source://media_source makes the script look for the sound file in /config/local (www) by default.

for the record, I am experiencing new issues, but only playing those music files to my browser-mod media_players, and I filed an issue at https://github.com/thomasloven/hass-browser_mod/issues/302

Not sure if BM is creating the issue, it worked before. HA has had several Beta/Dev updates since earlier succes, so I figure something went amiss there.

filed https://github.com/home-assistant/core/issues/67473