How to send media source as a notification

The new media source is pretty cool. I’ve modified a few of my automations to write images, stream.records to that folder.

So here is what I am trying to do.
Automation to capture stream record. I got that working and writes to /media
I can view the recorded .mp4 in my HA app on my iOS device - working
I’d like to send a notification that when clicked on, goes to and plays that .mp4.

I’m happy if the notification is for the iOS app, could be an actionable notification. But basically my main thing is I dont want to have to
get notified
open HA
click on media browser
click on mp4

Anyone have any similiar automations/notifictions?

1 Like

OK, so apparently it’s nothing new to send a MP4 as an attachment, but not opening using the media browser

- alias: Notify Mobile app
  trigger:
  - platform: state
    entity_id: binary_sensor.person_in_driveway
    to: 'on'
  action:
    service: notify.mobile_app_pauls_iphone
    data:
      message: "Door Bell Motion"
      data:
        attachment:
          url: /media/my_stream.mp4
          hide-thumbnail: false

I get the notification but end up just viewing the media browser folder, does not play the video.

This does work

- alias: Notify Mobile app
  trigger:
  - platform: state
    entity_id: binary_sensor.person_in_driveway
    to: 'on'
  action:
    service: notify.mobile_app_pauls_iphone
# notify.paul_and_tracy_iphone
    data:
      message: "Door Bell Motion"
      data:
        attachment:
          url: '/local/tmp/snapshot.mp4'
          hide-thumbnail: false

but of course the video is not in the media browser folder for this example, so it’s a pain to go back and look at later

Replying to my own message with the solution

    service: notify.mobile_app_pauls_iphone
    data:
      message: "Door Bell Motion"
      data:
        attachment:
          url: '/media/local/my_stream.mp4'
          hide-thumbnail: false

Not a big deal, but the attachment does play without sound, but if I play the same file via media browser it does have sound. But I’m super happy with this, allows me to go back and watch the video again easily

3 Likes

Thanks for sharing! Had this exact same issue and your solution worked for me.

1 Like

Been trying to replicate what you do without any luck. Do you know if the same code shoud work for png’s?

Do you store the file in /media/local/file.mp4 and then use the exact same path as attachment in the notification?

1 Like

are you getting errors or just not working

Not sure if you have to do this, but I did

  allowlist_external_dirs:
    - '/media'

Thanks for your reply!
I tried it but with no luck and no error message. Really strange since the image is written to the /media folder but can’t be seen in the notification. Do you see anything obvious I’m doing wrong?

Edit:
This solved my issues, it had to use /media/local/ when sending the notification to access the image.

Hi there!

Is your iOS notification with attachment still working? I do have the same setup as yours, but I can’t get the attachment (image) to load on notification. The notification works, but the image won’t load, instead I get an image that says something like “Failed to load attachment, response status code was unacceptable: 404”.

I’m not sure if this is a bug on the companion app. By the way, where do you have this

allowlist_external_dirs:
    - '/media'

is it in your configuration.yaml? Is it necessary?

Solved my own problem.

For some reason, my snapshot is stored in “/media/local/local”. Yes /local/local And I don’t know why.

But I didn’t need to add allowlist_external_dirs in the configuration.yaml.

- alias: Motion Detected
  trigger:
  - platform: state
    entity_id: binary_sensor.living_room_camera_motion_detected
    to: 'on'
  action:
  - service: camera.snapshot
    target:
      entity_id: camera.living_room_camera
    data:
      filename: '/media/local/living-room_motion-detected.png'
  - delay: '00:00:05'
  - service: notify.ios_phones
    data:
      message: Motion detected in the living room.
      data:
        attachment:
          url: '/media/local/local/living-room_motion-detected.png'
          content-type: png
          hide-thumbnail: false
1 Like

The url and file location are different.

For example:
You have created the following on disk: ‘/media/local/image.jpg’ and when you access the url through the web server you need to tell the media plugin which “source” to access, in this case it’s the local source which points to ( url: “/media/local” -> disk: “/media” ) so you end up with url: “/media/local/local/image.jpg”. So if you were to create on disk: “/media/snapshot/image.jpg” -> url: “/media/local/snapshot/image.jpg”

HTH

Hi,

Is there a way to add the latest clip/image to the notification when the file name is dynamic? (it has an ID and not the constant: “latest_clip”?

thanks!

Hello
I am trying to open local recorded files from camera by clicking on notification,
I can see the preview of file, but when trying to click on it, it will bring me on HA home page
here is the code
I am using folder watcher for monitoring
service: notify.mobile_app_sm_g998u1
data:
title: New image captured!
message: /media{{ trigger.event.data.folder }}/{{ trigger.event.data.file }}
data:
color: red
ttl: 0
priority: high
image: /media{{ trigger.event.data.folder }}/{{ trigger.event.data.file }}
clickAction: /media{{ trigger.event.data.folder }}/{{ trigger.event.data.file }}