Trying to play a media file to google home, what am i missing?

This works for Yamaha’s MusicCast devices, I just wish the media player and media browser would function like this. I searched for bugs on this topic but did not find anything, perhaps its time to open one.

Edit: I got it working, I had to go into Server Control > General > and set the following to automatic:

I guess now would be a good to time to get my music library in order.

Thanks. That works great for me.
File at:
/config/www/media/bark.mp3

Test Script:

alias: Play Sound File
sequence:
  - service: media_player.play_media
    data:
      media_content_type: audio/mp3
      media_content_id: /local/media/bark.mp3
    target:
      entity_id: media_player.nesthub
1 Like

I was able to get this working, however my approach differs slightly from the previous solutions.

Backstory: Similar to the original poster, I was trying to play media to a Google Home speaker. Initially I was simply using the “Play Media” action. Text-to-speech was working, so I tried playing a .mp3 file that I could find in “Local Media” of the “Cast” dialog. However, this failed to play out of the Google Home, and stopped the Automation from continuing.

More information about my setup: I use Home Assistant running in a Docker container inside my QNAP NAS via Container Station. To make mp3’s available in the “Local Media”, I created a docker bind from a folder in my NAS (/Container/volumes/home-assistant/qnap/), to /media/qnap/ in the docker container. Now anything I add to the NAS folder appears in HA’s “Local Media”. After reading the posts above, I tried messing with different solutions, but none worked for me.

Solution: Ultimately what I did was looked at the YAML for the non-working “Play Media” action. It exposes the required media_content_id and media_content_type based on the file I selected from the dialog browser.

YAML from non-working “Play Media” action

service: media_player.play_media
target:
  entity_id: media_player.office_speaker
data:
  media_content_id: media-source://media_source/local/qnap/alerts/alert1.mp3
  media_content_type: audio/mpeg
metadata:
  title: alert1.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/qnap
    - media_content_type: ""
      media_content_id: media-source://media_source/local/qnap/alerts

One major difference from the posts above is that this use a media-source:// protocol prefix, and uses audio/mpeg instead of audio/mp3 as the protocol, however, I switched this to audio/mp3 for testing purposes and it still worked :+1:

Now I just plopped those values into a “Call Service” action and it worked on the first try!

Working Call Service YAML:

service: media_player.play_media
data:
  media_content_id: media-source://media_source/local/qnap/alerts/alert1.mp3
  media_content_type: audio/mpeg
target:
  entity_id: media_player.office_speaker

Edit:
I have since learned more about how authentication to the file is working. When linking to a media file using media-source url path, it automatically adds the auth signature to the URL as this is a signed path.

More info is is available in the Authentication API documentation:

From what I understand, if you don’t want authentication, use the ‘www’ folder. I believe placing files in /config/www will give you access to them via the URL /local/. So /config/www/myFile.mp3 should be available at YOUR_HOST:8123/local/myFile.mp3 without authentication.

2 Likes