Attach photo to notification

I’m sorry to be that newbie. Have been struggling with this for two days straight. Have read the forums and tried every syntax combination I’ve come across to no avail. Just looking for the configuration syntax to attach a photo to a notification. I can confirm the photo is where I think it is, and I can access it.

What kind of notification?
What kind of photo?
Where is the photo?

Here is the structure I use for a photo link (from BlurIris send as a path via MQTT) on share using Telegram and Signal.

/media/camalerts/Alerts/{{states("sensor.mqtt_12345_blueiris_front_lower_cam_image_path")

and here a webcam snapshot to IOS when motion is detected at the front door:

alias: Front Doorcam Send a doorcam snapshot on movement AceIndy
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.frontdoormotion_sensor
    from: "off"
    to: "on"
    for:
      hours: 0
      minutes: 0
      seconds: 0
condition: []
action:
  - service: camera.snapshot
    entity_id: camera.doorcam
    data:
      filename: "{{ snapshot_create_file_path }}"
  - service: notify.mobile_app_aceindy_iphone
    data:
      title: "{{ notification_title }}"
      message: "{{ notification_message }}"
      data:
        attachment:
          content-type: jpeg
          url: /local/tmp/snapshot_doorcam.jpg
        push:
          sound:
            name: default
            critical: 1
            volume: 1
variables:
  binary_sensor: binary_sensor.frontdoormotion_sensor
  binary_sensor_name: "{{ states[binary_sensor].name }}"
  notification_title: Movement detected
  notification_message: "{{ binary_sensor_name }} was activated!"
  snapshot_create_file_path: /config/www/tmp/snapshot_{{ states[camera].object_id }}.jpg
  snapshot_access_file_path: "{{ snapshot_create_file_path | replace('/config/www','/local') }}"
6 Likes

Honestly after 4000 variations of attachment, image, push, internal dirs, external dirs this worked. Thank you!

1 Like

Hi @davidwas, since the problem you had is solved, please take the time to mark the answer as solution, you do that by selecting the three dots under the post:

image

Then select the check box:

image

Don’t forget too while you’re down there to click the heart to like the post, as a way of saying thank you.

Note: if you reveal what the problem was and how it got solved, it might help others with this problem
too.
Tip: if you had added “Mobile Apps” & the platform as category, your topic would live in a more suited section.

you’re welcome :wink:

My experience with snapshots is not ideal. I had some notifications that worked and then stopped, or images were cached.
I got advice here in forum to just use api as follows:

service: notify.phone_notification
    data:
      title: <b>You've got mail!</b>
      message: Check your mailbox
      data:
        image: /api/camera_proxy/camera.mail_high
        notification_icon: mdi:mailbox-up-outline
3 Likes

How do you retrieve the api of camera and does it also work for video?

Just in case someone else stumbles across this thread: I tried everything, and nothing seemed to work. I would receive a preview of the photo, but when I clicked on the notification, it opened the app (iOS, in this case) without showing the photo or other (i.e. map) attachment. Then I realized you had to press and hold the notification (D’oh) to see the attachment.

2 Likes

if someone finds this and has problems geting it to work, here is my working automations yaml script:

So I fought my way through the different notations of paths, and here are my findings:

  • option 1: pass the path as "/local/<whatever>" where "/local" is actually "/config/www" on your disk
  • option 2: pass the path as "/media/local/<whatever>" where "/media/local/" is actually "/media/" on your disk. This is the tricky part, because "/media/local" translates to “use media source named local”, which by default points to "/media" on the hard disk.

Option 2 is especially important if you added a new media folder in GUI (e.g. a folder from a NAS). It is then mounted inside "/media" on the disk. So you access it as "/media/local/your_new_folder". All this applies only to notifications!

4 Likes

This is all well and good, but I want the image in the notification to be static. In other words, I don’t want to include a link to the photo, but the photo itself. If I include a link, the photo in that link will likely change before I get around to viewing it. Having a static image included in the notification is the only way to keep the message text and image in sync.

This is very static:

Hi all, thanks for the descriptions. I’m no dev, but would like to follow your solution.

This notification works, but with no image… I’m guessing problem might be with image location on action: camera.snapshot:

filename: /media/motion.jpg

and on notify.notify action:

image: /media/motion.jpg

My current Notification yaml:

alias: 111 Notification - Doorbell Motion
description: ""
triggers:
  - type: motion
    device_id: 0590e894177956550b149beef8d39c6c
    entity_id: 2f0b59aa727ff884d6eedd088bf6e094
    domain: binary_sensor
    trigger: device
conditions: []
actions:
  - action: camera.snapshot
    metadata: {}
    data:
      filename: /media/motion.jpg
    target:
      device_id: 6066ecd85d9b787e61659957856b4162
  - action: notify.notify
    metadata: {}
    data:
      message: At {{ now().strftime('%H:%M %a %d %b %Y') }}
      data:
        image: /media/motion.jpg
        ttl: 0
        priority: high
        importance: high
        channel: critical
        visibility: public
        car_ui: true
        notification_icon: mdi:motion-sensor
        actions:
          - action: scene.downstairs_light_on
            title: Turn Downstairs Light On
      title: Doorbell Motion
mode: single

You are right…

snapshot_create_file_path: "/config/www/tmp/snapshot_{{ states[camera].object_id }}.jpg"
snapshot_access_file_path: "{{ snapshot_create_file_path | replace('/config/www','/local') }}"

As you can see from a snippet from my blueprint:

  1. The snapshot must be in www folder
  2. When taking the snapshot, store it in /config/www/some folder/some name
  3. In the notification, use /local/some folder/some name

PS, I assumed you use android, as for IPhone you should use ‘url’ instead of ‘image’ :wink:

Yeah, so I got it working with help from AI. Apparently camera.snapshot action requires an internal URL. However, if you want it to work inside and outside your home network, notify.notify action require an external URL (NabuCasa) works well.
My working example:

alias: 111 Notification - Doorbell Motion
description: ""
triggers:
  - type: motion
    device_id: 0590e894177956550b149beef8d39c6c
    entity_id: 2f0b59aa727ff884d6eedd088bf6e094
    domain: binary_sensor
    trigger: device
conditions: []
actions:
  - action: camera.snapshot
    metadata: {}
    data:
      filename: /config/www/tmp/motion.jpg
    target:
      entity_id:
        - camera.doorbell_wifi_250_mediaprofile_channel1_substream1
  - action: notify.notify
    metadata: {}
    data:
      message: At {{ now().strftime('%H:%M %a %d %b %Y') }}
      data:
        image: >-
          https://xxxxxxxxccchhh.ui.nabu.casa/local/tmp/motion.jpg
        ttl: 0
        priority: high
        importance: high
        channel: critical
        visibility: public
        car_ui: true
        notification_icon: mdi:motion-sensor
        actions:
          - action: scene.downstairs_light_on
            title: Turn Downstairs Light On
      title: Doorbell Motion
mode: single