Playing sound on automation

hi I’m trying and trying but find no solution :frowning:

I want play an alarm sound on my automation when triggered…

I use

service: media_player.play_media
data:
enqueue: next
media_content_type: music
media_content_id: http://ip-home-assistant:8123/???/alarm.mp3
target:
entity_id: media_player.office

can someone help me?
thanks so much

this works fine here:

action:
  - service: media_player.play_media
    target:
      entity_id: media_player.vlc_telnet
    data:
      media_content_id: http://192.XXX.XXX.XX:8123/local/ns-ding-dong.mp3
      media_content_type: music
  - delay:
      hours: 0
      minutes: 0
      seconds: 4
      milliseconds: 0
  - service: notify.vlctelnetha
    data:
      message: De jacuzzi is klaar met opstarten. Have fun.
1 Like

What folder do you store your files in on home assistant? I am trying to set this up as well and I don’t see a folder called local. Also I was able to get it to work by using the UNC Path Name of the home assistant network share.

media_content_id: \\192.168.10.25\media\Test.mp3
\\192.xxx.xxx.xx\config\www\ns-ding-dong.mp3

I store it in Media menu on the left menubar and there on “my media” Icon.

I’ve tried:

media_content_id:
http://192.168.1.5:8123/local/alarm.mp3
http://192.168.1.5:8123/media/alarm.mp3
http://192.168.1.5/media/alarm.mp3
http://192.168.1.5/local/alarm.mp3

\\192.168.1.5\media\alarm.mp3
\\192.168.1.5\config\www\alarm.mp3

but nothing happen, can I check in the automation if this action is executed at all?

thanks

Select the automation and take a look ar traces

Also, I have this in my configuration.yaml:

  allowlist_external_dirs:
    - /config/www
  media_dirs:
    cam: /media/cam_snapshots
    music: /media/music

With allowlist_external_dirs: you can call images or sounds like:

        - service: media_player.play_media
          data:
            entity_id:  group.googletts
            media_content_id: https://your.ip.or.name:8123/local/sonidos/sangijuela.01.mp3
            media_content_type: music

local is my www folder

hi,

I get “bad indentation of a mapping entry (32:2)”

when adding:


 allowlist_external_dirs:
 - /config/www
  media_dirs:
    cam: /media/cam_snapshots
    music: /media/music

ok but you upload the mp3 in \media\ → “my media”
with the home assistend GUI?

Oh, sorry, that goes under

homeassistant:
  allowlist_external_dirs:
    - /config/www
  media_dirs:
    cam: /media/cam_snapshots
    music: /media/music

With maybe some other stuff that you already have there at configuration.yaml

For uplading the files, the same as the other, for instance using the Samba share addon.

hi sorry, doesn’t work

configuration.yaml is green and saved
check config:

Configuration errors

Invalid config for ‘homeassistant’ at configuration.yaml, line 34: Not a directory ‘allowlist_external_dirs->0’, got ‘/config/www’ Invalid config for ‘homeassistant’ at configuration.yaml, line 36: Not a directory for dictionary value ‘media_dirs->cam’, got ‘/media/cam_snapshots’ Invalid config for ‘homeassistant’ at configuration.yaml, line 37: Not a directory for dictionary value ‘media_dirs->music’, got ‘/media/music’

no idea, is this so difficult :frowning:

That was an example. Your directory has to exist. For /config/www create one (where your homeassistant is instaled).

For media_dirs you can skip that.

Calling in from 2025. Was starting from this thread to implement some jokes at home. Prepared to debug path strings etc - but found out I could first upload my sound files directly from my windows PC from within HA in browser. Or iOS in app. Super simple. From within the media folder of HA.

And then I started creating an automation in the HA web UI - graphically. For actions I clicked “Media player” → “Play media” → selected my Google Nest speaker and selected a .wav file browsing the “My media” folder of HA.

Result just worked perfect. Fart sounds are funnier than I remember. Was still curious of the generated yaml. Posting that here for future reference.

and in yaml, that translated into:

actions:
  - action: media_player.play_media
    target:
      entity_id: media_player.kitchen_talkbox
    data:
      media_content_id: media-source://media_source/local/fart3.wav
      media_content_type: audio/x-wav
    metadata:
      title: fart3.wav
      thumbnail: null
      media_class: music
      children_media_class: null
      navigateIds:
        - {}
        - media_content_type: app
          media_content_id: media-source://media_source