Caching issue with Camera snapshot notification

Guys, i have a problem with Camera snapshot.

I need to setup my config to create a snapshot with timestamp, with date and time when pushed on the ring. Then i need to show the latest created file on HA lovelace.

My current config is:

- id: '34223881256565'
  alias: Notify my Frontdoor
  description: ''
  trigger:
  - platform: state
    entity_id: binary_sensor.frontdoor_doorbell
    from: 'off'
    to: 'on'
  condition: []
  action:
  - service: notify.mobile_app_androidphone
    data:
      message: 🔔 Ring! 🔔
      data:
        image: /local/snapshots/cam_frontdoor.jpg
  - service: camera.snapshot
    target:
      entity_id: camera.cam1
    data:
      filename: /config/www/snapshots/cam_frontdoor.jpg

I would create a snapshot with name cam_frontdoor-latest.jpg and show that in HA front end

Since name is static HA should retrieve it

If you need Save this I think below would save with time.
cam_frontdoor-{{ now() }}.jpg’
Just use snapshot service to make second image. Maybe same service call can make both files

Ok, i have now added this one

    /config/www/images/snapshots/cam_frontdoor_{{
    now().strftime("%Y%m%d-%H%M%S") }}.jpg

and in lovelace this one

local/images/snapshots/cam_frontdoor-latest.jpg

It creates files with timestamp but i don’t see the image on lovelace and on the phone.

You are only creating file with time stamp
You must create both files.


action:
  - service: camera.snapshot
    target:
      entity_id: camera.cam1
    data:
      filename: /config/www/images/snapshots/cam_frontdoor_{{
    now().strftime("%Y%m%d-%H%M%S") }}.jpg
  - service: camera.snapshot
    target:
      entity_id: camera.cam1
    data:
      filename: /config/www/snapshots/cam_frontdoor-latest.jpg
  - service: notify.mobile_app_androidphone
    data:
      message: 🔔 Ring! 🔔
      data:
        image: /local/snapshots/cam_frontdoor-latest.jpg

I always send message last
If message send fails I think automation stops at that point
File creation is local so I trust it not fail over external service over internet

3 Likes

OK, with this config i receive a notification with the latest image on my phone and it create a imagefile with timestamp. But how can i get the latest image on the lovelace? Wich entity do i need to use and with which settings?

It is really some cacing issue with lovelace. I get the latest image on my phone as notification but lovelace will not update the image. How can i solve that?

I add as picture entity same as I would camera

File permission issue can cause your problem

it’s not a caching issue. If you want the image to update and you’re using the same image name, you need to display the image as a camera.

FYI, it doesn’t support the /local path, so you have to use the absolute path.

camera:
  - platform: local_file
    name: cam_frontdoor_latest
    file_path: /config/www/snapshots/cam_frontdoor-latest.jpg
1 Like

Problem solved at this manner!!! Thank you so much.

1 things what i also need to do with all the created snapshots with timestamp. That folder will be increased in HA with all the snapshots, how can i delete it automatically old files or something like save the last 10 items on the folder.

I want also see the last 10 snapshots on this folder automatically on the lovelace, just not only the latest snapshots. Is that possible?

Ideas

hi, new to camera snapshots, I made it so far the dated and fixed snapshots are in fact created in my Media share:

script:

  create_snapshot_poort:
    alias: Create snapshot Poort
    mode: restart
    sequence:
      - service: camera.snapshot
        data:
          filename: >
            /media/snapshots/poort_at_{{now().strftime('%H_%M_%M_%d_%m_%y')}}.jpg
        target:
          entity_id: camera.poort
      - service: camera.snapshot
        data:
          filename: >
            /media/snapshots/camera_poort.jpg
        target:
          entity_id: camera.poort
      - service: notify.mobile_app_marijn
        data:
          message: 🔔 Iemand bij de Poort!
          data:
            image: /media/snapshots/camera_poort.jpg

how ever, I get a notification with a 404 error in the message body:

please spot the issue for me? thanks

or can we only serve from /local (/config/www) maybe, and not from a media share?

No that cant be it: Standard Attachments | Home Assistant Companion Docs

using:

#             image: /media/snapshots/camera_poort.jpg
            entity_id: camera.poort

I can see my cam streaming nicely though, so the connection to the app and the cam is fine too. Now why cant I send that image

In my experience only public files can be sent/displayed in notification

You can temporarily store in www. I did this in past

right!

doing this now:

    sequence:
      - service: camera.snapshot
        data:
          filename: >
            /media/snapshots/poort_at_{{now().strftime('%H_%M_%M_%d_%m_%y')}}.jpg
        target:
          entity_id: camera.poort
      - service: camera.snapshot
        data:
          filename: >
            /config/www/snapshots/camera_poort.jpg
        target:
          entity_id: camera.poort
      - service: notify.mobile_app_marijn
        data:
          message: 🔔 Iemand bij de Poort!
          data:
            image: /local/snapshots/camera_poort.jpg

so writing a dated snapshot to the media share (and be able to browse it in the Media browser), write a overwrite able snapshot to the /config/www/snapshots/ folder, and serve that as /local/snapshots/camera_poort.jpg

thanks.
Would have hoped to keep my config share free of those file writes, but apparently that wont be…
remarkable, since the docs explicitly state the media share to serve the attachments from. Will ask in Discord #iOS_and_Mac to be sure

appreciate your help

EDIT

found my error!

I had to enter local to the path:

            image: /media/local/snapshots/camera_poort.jpg

writing to: /media/snapshots/camera_poort.jpg needs serving from /media/local/snapshots/camera_poort.jpg

just like
writing to /config/www/snapshots/camera_poort.jpg needs serving from /local/snapshots/camera_poort.jpg