Unable to play local mp3 to Google Home

I’ve setup HASS on my ubuntu server. Most things seem to be working correctly, but have not been able to setup a wireless doorbell, using a Xiaomi button to play a local mp3 to several Google Homes.

      entity_id: media_player.home
      media_content_id: https://10.168.48.236:8123/local/mp3/xxx.mp3
      media_content_type: audio/mp3
    service: media_player.play_media

I can play the mp3 link directly in a web browser, but it won’t play through the automation.

Does anyone have any idea?

Pretty sure you have to use a publicly accessible IP/hostname in order for Google Homes to play audio.

I’m double-nat - not by choice, my service provider is using internal IP addresses, and the fibre modem has no interface that I can access, so I haven’t been able to specify my router as DMZ. So even DDNS doesn’t work, and my ubuntu server can’t be accessed from the internet/not publicly accessible.

Hopefully someone has a work-around, otherwise it looks like I’m screwed if that is the only way to play an mp3

Try like this:

    - service: media_player.play_media
      data:
        entity_id: media_player.home
        media_content_id: /local/mp3/xxx.mp3
        media_content_type: 'audio/mp4'

P.S.: I you are using SSL than your port is probably 443 and you don’t have to enter the port number. But try the /local/mp3/xxx.mp3 first.

This does not work on my system. I have to use a publicly accessible URL for the media file.

Try using Dropbox or something similar? The URL can point to your publicly accessible mp3

I tried what Bob_NL suggested, but same as flamingm0e, it doesn’t work. I substituted with http://www.galaxyfaraway.com/Sounds/Welcome.wav, which worked.

I’m just really puzzled as to why a local file won’t play, but an internet file will??

I had the same issue in version 0.4x. As a workaround I was using the dropbox workaround as @flamingm0e mentions.

To do that: place file in a Dropbox folder, share the file and change the first part of the link to https://dl.dropboxusercontent.com

Complete link looks like this then:

https://dl.dropboxusercontent.com/s/l5qz6gvbks40ysn/Duke%20Nukem%20-%20Something%20smells%20rotten.mp3?dl=0

P.S. I just realized that maybe you could also try to just place the file directly in your www directory instead of in a subfolder. Could be a permission issue on the subfolder.
Than use:

        media_content_id: /local/xxx.mp3
1 Like

Oddly still doesn’t work, whether it’s on directly in the www directory or a subfolder.

I’ll also try out the dropbox method as well. Although dropbox is better than a random file on the internet, it’s still not ideal as it’s not locally hosted. I’d still prefer to locally host the file in case the internet craps out, so if anyone has any ideas, I’ll be happy to try them out!

Because we don’t have local control over our Homes

I managed to play local mp3 sounds on my chromecast this is what I have done:
https://mydomain.duckdns.org/local/mp3/HappyBirthday.mp3 for automation I used this:

  • alias: Play Happy Birthday
    trigger:
    platform: state
    entity_id: group.family
    to: home
    action:
    service: media_player.play_media
    data:
    entity_id: media_player.living_room_speaker
    media_content_id: https://mydomain.duckdns.org/local/mp3/HappyBirthday.mp3
    media_content_type: audio/mp4

I am using Hassbian, but I believe it will work on Hassio too. Just put the files under the www directory in Home Assistant.

This isn’t ‘local’. This is using your PUBLIC URL to play the file. It has to be a ‘public’ URL for it to work.

Sorry, my bad!

To play a local MP3 file on my local Google Home Assistant Mini, the procedure that finally worked for me was:

Install HassIO onto Raspberry Pi. Install Add-On, Samba Share.
From laptop or PC, map to Samba share, config.
From laptop or PC, create subdirectory under config named: www
Then create subdirectory under config/www named: audio
Copy the mp3 file to /config/www/audio
Restart HassIO. This is required to make HassIO start sharing the new folders locally via http.
After HassIO has restarted, from laptop or PC, browse to http://Local_IP_Address_of_HA:8123/local/audio/YourSong.mp3
The browser should launch the audio file using whatever your browser has configured to play MP3s. That proves the changes above were effective.

Now configure HassIO to play the file.
I’m using an automation to play mine at 7PM every day, like this (in automations.yaml):

- id: 'PlayMySong'
  alias: PlayMySong
  trigger:
  - at: '19:00:00'
    platform: time
  action:
  - service: media_player.play_media
    data:
      entity_id: media_player.google_mini
      media_content_id: http://192.168.1.2:8123/local/audio/mysong.mp3
      media_content_type: 'audio/mp3'
6 Likes

Hey great. Here is what I use google home mini playing alarm sound when motion detected:

  - alias: "Dafang Living Room motion detection warn via Line"
    trigger:
    - entity_id: binary_sensor.dafang_motion_sensor
      from: 'off'
      platform: state
      to: 'on'
    condition:
     - condition: time
       after: '00:00:01'
       before: '23:59:00'
    #   after: '00:02:01'
    #   before: '00:05:30'
    action:
      - service: shell_command.dafang_living_room
      - service: light.turn_on
        data:
          entity_id: light.mezzanine_lamp
          effect: red_strobe
      - service: media_player.turn_on
        data:
          entity_id: media_player.google_home
      - service: media_player.volume_set
        data:
          entity_id: media_player.google_home
          volume_level: .8
      - delay: '00:00:05'
      - service: media_player.play_media
        data:
          entity_id: media_player.google_home
          media_content_id: http://192.168.2.14/hassio/PoliceSirenLoopSound.mp3
          media_content_type: 'audio/mp3'

What I don’t know is to make it repeats playing the siren sound.

I haven’t tried to repeat playing a sound from Home Assistant through my Google Home Mini, but maybe one of these articles would help you do that?

1 Like

Thanks for your suggestion. I will try those solutions. In the meantime, I use Audacity software to repeat the siren sound from 30 sec to 5 min and save as a long version siren mp3 file. That would be enough to scare the thief :grinning:

I’m trying to test this also but having no luck on the services panel.

{
"entity_id": "media_player.kitchen_home", 
"media_content_id": "http://ipofhassio:8123/local/audio/doorbell1.mp3", 
"media_content_type": "audio/mp3"
}

That produces the error extra keys not allowed @ data['media_content_id'] even though popping that URL into my browser plays the file. Anyone see what I’m doing wrong?

This is one of the action when motion was detected. It will turn light on as strobe light, google home on, increase volume, play my recorded siren sound (last 5 minutes), then decrease volume.

    action:
      - service: shell_command.dafang_living_room
      - service: light.turn_on
        data:
          entity_id: light.mezzanine_lamp
          effect: custom
      - service: media_player.turn_on
        data:
          entity_id: media_player.google_home
      - service: media_player.volume_set
        data:
          entity_id: media_player.google_home
          volume_level: .9
      - delay: '00:00:05'
      - service: media_player.play_media
        data:
          entity_id: media_player.google_home
          media_content_id: http://192.168.2.14/hassio/PoliceSirenLoopSound5min.mp3
          media_content_type: 'audio/mp3'
      - delay: '00:06:00'
      - service: media_player.volume_set
        data:
          entity_id: media_player.google_home
          volume_level: .5

Are you invoking the service, media_player.play_media ?

I can’t get the following to work and don’t know why. I get the link sound when the Google Home device is about to play something, but nothing else

      - service: media_player.play_media
        data:
          entity_id: media_player.lounge_mini
          media_content_id: http://192.168.0.14:8123/local/sounds/airport.mp3
          media_content_type: 'audio/mp3'