Google home play a song /Playlist/sound automatically using Automation or script

How do I make Google home play a song /Playlist automatically using service: media_player. Select the source. In-Home Assistant
Example: When My door is opened, the door sensor change state should trigger an mp3 file which says, “Your door is open, please close.”

Additional info:
I Am using HA running on Rasberry pi2

Please help

2 options

  • create sound files and save them in your www folder (create one if it does not exist) then play them with url /local/xxx.mp3.
  • simply use one of the TTS components. I use Google’s TTS and it works great
1 Like

Thanks, @lolouk44
Text to speech works but its Robotic like and no expression. Hence I personally don’t like that method

For the method 1 you have mentioned( create sound files and save them in your www folder (create one if it does not exist) then play them with url /local/xxx.mp3)
Can you elobrate exactly how to achive. Am not a great expert hence need a little detailsd explanation

Thanks in advance.

I’ve personally created a subfolder “audio” to host my sound files.
So structure looks like this:

  • HA config folder (containing configuration.yaml etc)
    • www
      • audio

Say in the audio folder you have a file called test.mp3
you can then play it this way:

  - service: media_player.play_media
    data:
      entity_id: media_player.NAME_OF_YOUR_PLAYER_GOES_HERE
      media_content_id: '/local/audio/test.mp3'
      media_content_type: 'audio/mp3'

My setup is slightly different and I’m not home so can’t test but I think that should work.
If your HA exposed to the internet?

1 Like

@lolouk44 Thanks
I will give it a try with an MP3 file stored in www/audio/test.mp3 & let you know if there is a qurey.

If your HA exposed to the internet? Not sure what excatly you are asking, but I am using it locally on my LAN, I have not configured to anything like Duck DNS. I have integrated with google home using discovery feature.

Will my above setting work or should I change something?

if you’ve not forwarded any port on your router it’s not exposed (basically you can’t access it from outside your home)
I believe it should work as it is, if not let me know

1 Like

Seems Like not working, can you please help

Below is how my Audio file is located on my rasberrypi

After storing the test.mp3 file i tried to call the media player service as follows:

mp2
Nothing happens. Please help

1 Like

ok I tried and played about and I think it might not work in the end, at least not for all media_players.
I have ChromeCasts at home and it looks like they’ll only accept online content.
What media_players are you using?
I wonder whether MPD could be an option…

1 Like

Just Google Home.

1 Like

Thanks, they yeah you’ll need a full online URL. this will mean either you expose your HA install on the internet or you store the sound files somewhere so they can be free accessed online.
If you’re not ready to expose your HA instance to the internet, you could save your files in a dropbox folder, then click on share > create link.
Use that link in HA and it should work

Sorry Dosent seem working with Drop box file as well
Below is my services call details
mp3

Test.mp3 dropbox location https://www.dropbox.com/s/sreees7zz67pec3/test.mp3?dl=0

Please help

remove ?dl=0 from your URL and change content type to audio/mp4

1 Like

Sorry again, Noting happens Result is the same. :frowning_face:
Mp4
Please Help

that’s really weird. Just tried now (home), it definitely shows as playing:
image
yet I can’t hear anything :face_with_raised_eyebrow:

Oh got it, Dropbox changed the way you can share files, you need to be signed in :angry:
You may need to seek an alternative platform to host your files
In the mean time try with this URL to test: http://icy-e-bab-04-cr.sharp-stream.com/absoluteclassicrock.mp3

Above url works great, Thanks a lot

Let me know whats the trick to get my own mp3’s

To host your own mp3 you need to find some cloud service that will allow you to host and access via direct links. I’ve not tried them but there are a few (Google drive, Microsoft onedrive, etc).
To make your mp3, well it’s up to you. You can record your own voice, find free online samples that you can download,…

1 Like

Thanks a lot. Will explore ways & implement.
U r awesome thanks

1 Like

@lolouk44 Finally i found that whatever code you gave first works :slight_smile:
The only thing is i dint add the ip address of my HA pi before local

'/local/audio/test.mp3 **Doesn't work** 
'ipaddress of HA Pi/local/audio/test.mp3   **Works**

Thanks a Lot

3 Likes

Next Query

I have stored say 10 mp3 files in my local file
I want them to play each one at random every morning. thru an automation/script.
Randomly played Day1 mp3 should not repeat for next 9 days, After 10th day the process repeats

Is this possible?
Can you guide?