Attaching photo to persistent notification

Hello,

I am trying to figure out how to attach a photo to a persistent notification. I would like to send a notification when my front door camera detects a person with an image attached.

I have it working but for some reason it always sends the same photo. It’s like it is cached somewhere and doesn’t update the image even though a new image has been created.

Here’s the code that creates the snapshot:

metadata: {}
data:
  filename: /config/www/images/front_door/front-door-person.jpg
target:
  entity_id: camera.doorbell_clear
action: camera.snapshot

Running that creates this image (note the time: 08:26):

When I run this:

alias: Send a notification
action: notify.persistent_notification
data:
  message: >-
    Person Detected<p> ![Front Door
    Motion](/local/images/front_door/front-door-person.jpg)
  title: Front Door

It always sends this file (note time: 08:14):

If I obtain the link from the image in the notification it displays the old file until I refresh the browser then it shows the correct updated photo.

Is there a way to send the updated file via the notification?

I’d like the file to overwrite so I only have the last version of the photo only.

Thanks in advance.

Did you ever get this figured out. I am seeing the same thing

Can’t say I have.

I figured out the .jpg name needs to be unique for them to display right in the HA App/Web UI. I couldn’t get the variables to work in an automation from one command to another, so I went with a script which stores the file name in a helper, then call that script in the automation. I have setup a bunch of them and works significantly better than the DVR software alone, given the data I have in HA to work with.

I am using this in a script to take the snapshot:

alias: Snapshot-Mailbox
sequence:
  - variables:
      timestamp: "{{ now().strftime('%Y%m%d_%H%M%S') }}"
      snapshot_filename: snapshot_uvc_front_door_{{ timestamp }}.jpg
      snapshot_path: /config/www/tmp/{{ snapshot_filename }}
  - data:
      value: "{{ snapshot_filename }}"
    target:
      entity_id: input_text.snapshot_mailbox_filename
    action: input_text.set_value
  - data:
      filename: "{{ snapshot_path }}"
    target:
      entity_id: camera.uvc_front_door_high_resolution_channel_insecure
    action: camera.snapshot
  - wait_template: >-
      {{ snapshot_filename in
      state_attr('camera.uvc_front_door_high_resolution_channel_insecure',
      'entity_picture') }}
    timeout: "00:00:01"
mode: single

Then the action part of the automation:

actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - OPEN
              - CLOSED
              - ERROR
              - NOT-UPDATING
        sequence:
          - action: script.snapshot_mailbox
            data: {}
          - delay:
              hours: 0
              minutes: 0
              seconds: 1
              milliseconds: 0
          - data:
              title: |-
                Mailbox - {% if is_state('binary_sensor.mailbox_door', 'off') %}CLOSED
                         {% elif is_state('binary_sensor.mailbox_door', 'on') %} OPENED
                         {% else %} UNKNOWN {% endif %}
              message: |-
                {{ now().strftime("%m-%d-%Y - %r") }}
                Battery: **{{ states('sensor.mailbox_battery') }}%**
                Signal: **{{ states('sensor.mailbox_signal_strength') }} dBm**
                Status: {% if is_state('binary_sensor.mailbox_door', 'off') %} **Closed**
                        {% elif is_state('binary_sensor.mailbox_door', 'on') %} **Open**
                        {% else %} **Unknown** {% endif %}
                ![image](/local/tmp/{{
                states('input_text.snapshot_mailbox_filename') }})
                [Link](/config/devices/device/6ea919d6417bc8ffd735fd9df31f0589)
            action: notify.persistent_notification
          - data:
              title: |-
                Mailbox - {% if is_state('binary_sensor.mailbox_door', 'off') %} CLOSED
                         {% elif is_state('binary_sensor.mailbox_door', 'on') %} OPENED
                         {% else %} UNKNOWN {% endif %}
              message: |-
                {{ now().strftime("%m-%d-%Y - %r") }}
                Status: {% if is_state('binary_sensor.mailbox_door', 'off') %} Closed
                        {% elif is_state('binary_sensor.mailbox_door', 'on') %} Opened
                        {% else %} Unknown {% endif %}
              data:
                attachment:
                  content-type: jpeg
                  url: |-
                    /local/tmp/{{ states('input_text.snapshot_mailbox_filename') }}
            action: notify.mobile_app_joes_iphone
          - action: shell_command.delete_camera_snapshots
            metadata: {}
            data: {}
mode: single

Figured out that the Snapshots have to stay around until you view them in the App/Web GUI. So I do it on every run:

# Delete snapshots older than 7 days
  delete_camera_snapshots: "find /config/www/tmp -name '*.jpg' -mtime +7 -delete"
1 Like

Thanks for posting that. I will certainly be giving this a go. Thanks again :+1:.