Directly link to file in media library?

Is there any way to directly link to a file in a local media library? I’ve tried some formats but I haven’t found any that work yet. My use case is that I’m trying to have the video from my doorbell camera play on my phone via an action in a notification (Android).

My intention was to have a notificatoin with “Watch” and “Browse” actions. The former would play the current video, and the latter would take you to the media folder.

So far, I have tried URLs like the following:

  • /media/cameras/front_door/20250115_233313_FrontDoor.mp4 (I get 401 Unauthorized, even though I am logged in). The camera_proxy URL in the camera entity works, but sometimes the camera captures another video (and the entity’s state updates) before I get the chance to click on the notification. For this reason, I want to link to a particular file, not reference the camera entity.
  • /media-browser/browser/app%2Cmedia-source%3A%2F%2Fmedia_source/%2Cmedia-source%3A%2F%2Fmedia_source%2Fcameras%2Ffront_door This crazy URL is what’s in the address bar when I browse to the media folder that the file is in. If I include the “https://domain.com” part of that URL, it works, but it loads in the default web browser instead of the app.

Is there any way I can accomplish what I’m trying to do?

Hello SteveDinn,

For me in configuration.yaml

homeassistant:
  media_dirs:
    local: /media

Then the /media path becomes part of /local .
And put the mp3 in a folder in HA under

/media/mp3

(The media folder already exists, you would want to add a sub folder to that, or at least I did, to keep your OCD happy.)
When I want to use an MP3, the path is

media-source://media_source/local/mp3/Ships_Bell_4.mp3

Adjust as you desire, but that is a basic version of mine.
Longer version in here: HA Config

Therre is a frigate notification blueprint which attaches pictures or videos of an event to a notification, so looking at how they do that may assist you.

EDIT:It is here GitHub - SgtBatten/HA_blueprints: Somewhere to store automation blueprints

action navigate to media browser…

action:  notify.mobile_app_<your_device_id_here>
data:
  message: browse
  data:
    actions:
      - action: "URI"
        title: Browse media
        uri: "/media-browser/browser"

video attachment…

1 Like

This URL format will let me play the doorbell camera videos on my TV with a media_play action, but I can’t attach them to a notification this way, nor use them as a URL to play them from a notification action :frowning:

Can you link to a subfolder this way? I can’t figure out how to get that working. My media folder is called cameras and it has a subfolder for each camera’s images, i.e., front_door.

I looked into my webserver’s logs when I clicked on a video from the media browser (which is probably what I should have done in the first place) and I found the URI that is is using:

GET /media/cameras/front_door/20250111_154051_FrontDoor.mp4?authSig=[a really long encoded parameter]

That authSid is NOT an access token – I tried that. Does anyone know how we can obtain those values in order to actually link to some media?

Is this MP4 represented somewhere in an entity state or attribute?

For example, in a media player the artwork is an attribute of the media player entity and you can get the url with a template.

More particularly a camera entity should have a entity_picture attribute which has the url in it.

action: notify.mobile_app_viet_ngoc
data:
  message: Test video
  data:
    video: /media/local/test_video.mp4

For notification you can use media source or www public folder. For www you don’t need token access, but it’s public.

Hrm…So, that style of URL does work to attach the video to the notification, but doesn’t work when using it to view the video from an action. The video attached to the notification doesn’t really play smoothly – it kind of stutters and you can’t see it at full resolution.

My main problem is that since I have to poll Blink to download the videos and several can come down at once if there were multiple instances of detected motion during the polling interval. Because of multiple files getting written to the folder in very quick succession, the folder watcher event fires multiple times very quickly. I can’t rely on the entity state to have the same video at the same URL when I click on the notification’s action even a couple of seconds later. I want to be able to grab the absolute URL of the file as soon as the folder watcher event fires and use it exclusively – not continue to reference the state of the entity, which may have changed out from under me.

It’s unfortunate that there seems to be no easy way to link directly to a media file. I think you should be able to do this if you are logged in.

While I’m bitching :smiley: I think that the media folder view should be sortable. After only a week’s worth of motion detection videos, it’s a pain to have to scroll all the way to the bottom to see the latest ones. I want to be able to sort them in reverse-chronological order (or even reverse alphabetical, since they’re named with the date & time).

Hello!
Can you tell me how I can play all the audio files from the catalog? Without creating a playlist.
I’m trying to do this through a script, but I can’t.

action: media_player.play_media
metadata: {}
data:
  media_content_type: music
  media_content_id: media-source://media_source/local/music/
  enqueue: replace
target:
  entity_id: media_player.nabu

I struggle with this aspect of configuring media folders and how to access them. I have this in my configuration.yaml

homeassistant:
  media_dirs: 
    media: /media

However, I also have a www/Sounds folder that has my mp3 files in it. If I want to play a particular file on a media player, I use, for example:

- action: media_player.play_media
    data:
      entity_id: <my_media_player>
      media_content_id: http://<HA IP:8123>/local/Sounds/sound.mp3
      media_content_type: music

If I add

homeassistant:
  media_dirs:
    media: /media
    local: /media

what effect will that have on my file structure and would that allow me to also use

media-source://media_source/local/Sounds/sound.mp3

to play that sound?