Attach image to alert notifications?

Hi,

I have an alert set up for my camera that sends repeated notifications to my android phone if a person is detected. This has been working perfectly for me. However, I wanted to improve the notifications by adding a snapshot from the camera. I’ve tried adding the image field to the alert and the notify configs but neither seem to work. I do get the notification but it doesn’t contain any image.

Alert config (in alerts.yaml):

side_camera:
  name: "Alert Side Camera"
  message: "Person detected on side camera!"
  done_message: clear_notification
  title: "Alert!"
  entity_id: input_boolean.side_camera_alarm
  state: "on"
  repeat:
    - 0.1
  can_acknowledge: True
  skip_first: False
  notifiers:
    - notify_android_with_image
  data:
    tag: side_camera
    actions:
      - action: "acksidecameraalert"
        title: "Silence"

Notify config (in configuration.yaml):

notify:
  - platform: group
    name: "Notify Android With Image"
    services:
      - action: mobile_app_android
        data:
          data:
            ttl: 0
            visibility: public
            priority: high
            image: "/media/local/camera_snapshots/side/{{ states('input_datetime.side_last_event_timestamp') | as_timestamp | timestamp_custom('%Y-%m-%d_%H-%M-%S') }}.jpg"

I captured the service call using developer tools:

event_type: call_service
data:
  domain: notify
  service: mobile_app_android
  service_data:
    message: Person detected on side camera!
    title: Alert!
    data:
      image: >-
        /media/local/camera_snapshots/side/{{states('input_datetime.side_last_event_timestamp')
        | as_timestamp | timestamp_custom('%Y-%m-%d_%H-%M-%S') }}.jpg
      ttl: 0
      visibility: public
      priority: high
      tag: side_camera
      actions:
        - action: acksidecameraalert
          title: Silence
origin: LOCAL
time_fired: "2025-01-01T01:27:17.230755+00:00"
context:
  id: 01JGFQJSFE3SFRCQ24V47YXQ7E
  parent_id: null
  user_id: null

It seems like the issue is that the template expression is evaluated as a string?

I ran into a similar issue when I tried to send an attachment and ended up resolving it with this code:

action: notify.mobile_app_pixel
data:
  title: Image
  message: "{{ now().strftime(\"%d %b'%y-%H:%Mh\") }}"
  data:
    image: >-
      /media/local/SecurityCams/1_OutdoorCam/{{
      states('input_text.outdoorcam_snapshot_time') }}.jpg
    attachment:
      url: >-
        http://192.168.1.11:8123/media/local/SecurityCams/1_OutdoorCam/{{
        states('input_text.outdoorcam_snapshot_time') }}.jpg

As you can see, I use an imput_text helper that stores the timestamp/name of the image as text and then inserts it into the string.

BTW:
Not sure, why I have the image as well as the attachment/url info there, but that’s the only way I got it to work :confused:

1 Like

Thanks for the suggestion! I tried copying your example but still no success :frowning: . What’s odd is that I used developer tools to send a test notification with the exact same config and that works. But for some reason, a notification send by the Alert integration doesn’t work.

I guess I could use a fixed filename eg. last_snapshot.jpg but it would be really nice if I could keep a history of snapshots…

Maybe you can save the image twice, once with the fixed filename you can use in the alert (and which will be overwritten every time) and a second time with the timestamp as filename.

Yeah, that seems to be the best option right now. Thanks!