[SOLVED] Can't get mp3 file to play on Google Nest speaker

I have a condition to play a soft “ding” in an mp3 file when someone coming up the stairs with the rooftop door closed. All the conditions seem satisfied, no error messages, but it doesn’t play. Here’s the code, I suspect I’m referring to the file incorrectly. The file exists in the media/audio/mp3 folder, and I can see it and play it in the media tab on the sidebar.

Also confusing, when doing searches through similar posts, I see the http address with <>no quotes, <'> single quotes and <"> double quotes, all of which they claim to work. How can that be?

description: Rooftop Person Arrival Tone
trigger:
  - platform: state
    entity_id:
      - binary_sensor.rooftop_stairs_motion_sensor_motion
    to: "on"
    from: null
condition:
  - condition: state
    entity_id: binary_sensor.rooftop_door_open_sensor_contact
    state: "off"
action:
  - service: media_player.volume_set
    metadata: {}
    data:
      volume_level: 0.9
    target:
      entity_id: media_player.google_nest_mini_rooftop
  - delay:
      hours: 0
      minutes: 0
      seconds: 2
      milliseconds: 0
  - service: media_player.play_media
    target:
      entity_id: media_player.google_nest_mini_rooftop
    data:
      media_content_type: audio/mp3
      media_content_id: "\"http://127.0.0.1:8123/media/audio/mp3/ding.mp3\"
mode: single

For the media content line, I’ve tried:

media_content_id: http://127.0.0.1:8123/media/audio/mp3/ding.mp3
media_content_id: “http://127.0.0.1:8123/media/audio/mp3/ding.mp3
media_content_id: http://192.168.1.55:8123/media/audio/mp3/ding.mp3
media_content_id: “http://192.168.1.55:8123/media/audio/mp3/ding.mp3

In the automation editor, you can click on “Run” under the three button menu to test your actions. If that works, then you would know that the problem is your trigger or conditions. To investigate that, you could look at the traces or cause the motion detector to go to on state (by walking in front of it) and see if it shows as “triggered” in the automation editor. You can also test the conditions in the automation editor.

In this case though, I’m pretty sure the problem is your URL. 127.0.0.1 is a special address called the loopback address that is a way for devices to refer to themselves. Since the file is on your HA device, and not on your nest device, that is not the right one to use in this case.

You didn’t say, but I assume that 192.168.1.55 is your HA device. What folder did you put the ding.mp3 in?

As to your question about quotes, in some cases quotes are required for particular values, and if so both single and double quotes are acceptable. For normal URLs, quotes are not necessary. However, the value you have in your automation is not a valid quoted string because you open the quoted string, but you never close it. The backslash+quote is a way of saying that the quotation mark is part of the value, so it’s as if you are saying the URL should have a quotation mark at the beginning and the end.

It’s not the automation as I’ve run it with no conditions and tested even outside the automation.

I’ve changed things around as I read that there should be a separate directory for media under /config, and it should be referenced in configuration.yaml

So I created a config/media folder and added the mp3 file there. In my config file I added:

media_dirs:
  media: /config/media

I put the ding.wav file into that folder. I restarted HA.

I then put http://192.168.1.55:8123/config/media/ding.mp3 into my browser. It simply launched my default dashboard.

I looked in the HA media tab to see if I could play the file from there. I could, and I could play it to my proper speaker.

So, if I go into the automation and click RUN on the action tab, no music??

action:
  - service: media_player.volume_set
    metadata: {}
    data:
      volume_level: 0.9
    target:
      entity_id: media_player.google_nest_mini_rooftop
  - delay:
      hours: 0
      minutes: 0
      seconds: 2
      milliseconds: 0
  - service: media_player.play_media
    target:
      entity_id: media_player.google_nest_mini_rooftop
    data:
      media_content_type: audio/mp3
      media_content_id: http://192.168.1.55:8123/audio/mp3/ding.mp3

I also rried it with config/media/audio/mp3/ding.mp3 and media/audio/mp3/ding.mp3

So I can play it through home assistant, but not at that URL.

Solved. It was the reference to the file. Correct way is:

  - service: media_player.play_media
    target:
      entity_id: media_player.google_nest_mini_rooftop
    data:
      media_content_type: audio/mp3
      media_content_id: **http://192.168.1.55:8123/media/local/audio/mp3/ding.mp3**
mode: single

There is no actual media/local folder, but it seems that when you set the local media path in configuration.yaml with this:

media_dirs:
  media: /config/media

it requires this wording and substitutes the actual folder root. Another lesson I learned is that the /media folder doesn’t seem to be the proper place to put media. Go figure.

media_content_id: "http://127.0.0.1:8123/media/audio/mp3/ding.mp3" should work too.

No idea why you had escaped double quotes, but if it would work anyway, then it clouded your view, so you could not see you missed a closing ordinary double quote.

Read my solved post, that was an error but not the issue.