Home Assistant sends cached images in iOS notification?

Hi all,

I’ve made my own smart doorbell that consists of the old school doorbell (acting as a contact sensor) and a separate Tapo camera. I’ve got an automation that sends me a notification if someone presses the doorbell:

alias: Doorbell notification
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.doorbell_button
    to: "on"
condition: []
action:
  - service: notify.ios
    data:
      title: Ding Dong 🔔
      message: "[{{ now().strftime('%H:%M') }}] Er staat iemand voor de deur!"
  - service: camera.snapshot
    data:
      filename: >-
        /config/www/images/front_door/snapshot_latest.jpg
    enabled: true
    target:
      entity_id: camera.front_door_sd_stream
  - service: notify.ios
    data:
      title: Door snapshot 📸
      message: "[{{ now().strftime('%H:%M') }}] Er staat iemand voor de deur!"
      data:
        image: /local/images/front_door/snapshot_latest.jpg
    enabled: true

Note: I’ve separated the notification in two separate messages due to the ~5s delay in the notification that includes the snapshot. If someone has suggestions to improve this, I’m all ears!

Yesterday I was testing the automation and even though the snapshot_latest.jpg file is updated every time, it keeps on sending an older (cached?) image:


Note the timestamp in the text (10:12) and the timestamp in the image (21:58)

Meanwhile in the www folder the most recent image is the correct image with the correct timestamp:

It looks like it is sending a cached image, instead of the recently modified snapshot_latest.jpg file.
It is also not a timing issue; triggering the automation a few minutes later still sends the same image:


If it would be a timing issue, you would expect in the above screenshot to have the snapshot_latest.jpg with timestamp of 10:12 that we created earlier.

Does anyone know how to make Home Assistant pick the latest jpg-file from the www folder?

Thanks in advance!

I had the same issue, added 100ms delay to the notification and the problem was solved.
I use “notify.notify”
for some reason Android didn’t have this issue.

another solution would be to make the name of the image unique, use a variable for timestamp or something and add it to the filename

edit.
and I added a parameter to the filename

  - delay:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 100
  - service: notify.notify
    data:
      message: 'De Deurbel Gaat! GlsCode: {{ states(''input_text.text1'') }}'
      title: Deurbel
      data:
        url: /lovelace-doorbell/doorbell
        clickAction: /lovelace-doorbell/doorbell
        image: https://<myurl>.duckdns.org:8123/local/images/doorbell/front_door_snapshot.jpg?{{as_timestamp(now())}}
        priority: high
        ttl: 0
        importance: high
1 Like

Try generating a unique name everytime?

Thanks for the suggestions!
What is before your delay in your automation? And how do you specify a target for the notify.notify service? I’ll give it a try :slight_smile:

I might do this as a plan B, but it will also require me to clean up the www folder once in a while, which I’d like to prevent. But apart from that, I assume my approach should work so I’d like to figure out why it doesn’t!

My complete automation is like this

- id: Doorbell
  alias: DoorBell
  description: DoorBell
  trigger:
  - platform: state
    entity_id:
    - binary_sensor.doorbellbutton
    to: 'on'
  action:
  - service: downloader.download_file
    data:
      url: http://<user>:<pwd>@<cameraIP>:8080/cgi-bin/snap.cgi
      subdir: /config/www/images/doorbell/
      filename: front_door_snapshot.jpg
      overwrite: true
  - service: notify.living_room_tv
    data:
      message: 'De Deurbel Gaat! GlsCode: {{ states(''input_text.text1'') }}'
  - service: mqtt.publish
    data:
      topic: cmnd/tasmota_NSPanel_kamer/Backlog
      payload: 'CustomSend notify~De Deurbel Gaat~De Deurbel Gaat! GlsCode: {{ states(''input_text.text1'')
        }};CustomSend pageType;Buzzer 2,2,2'
  - type: turn_on
    device_id: 04b2adafc7f6aab75bc9ada506ac1bb1
    entity_id: switch.lamp_voordeur
    domain: switch
  - delay:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 100
  - service: notify.notify
    data:
      message: 'De Deurbel Gaat! GlsCode: {{ states(''input_text.text1'') }}'
      title: Deurbel
      data:
        url: /lovelace-doorbell/doorbell
        clickAction: /lovelace-doorbell/doorbell
        image: https://<myurl>.org:8123/local/images/doorbell/front_door_snapshot.jpg?{{as_timestamp(now())}}
        priority: high
        ttl: 0
        importance: high
  - service: notify.html5
    data:
      message: 'De Deurbel Gaat! GlsCode: {{ states(''input_text.text1'') }}'
      title: Deurbel
      data:
        url: /lovelace-doorbell/doorbell
        tag: doorbell_tag
        priority: highest
        image: https://<myurl>:8123/local/images/doorbell/front_door_snapshot.jpg?{{as_timestamp(now())}}
  - delay:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
  - type: turn_off
    device_id: 04b2adafc7f6aab75bc9ada506ac1bb1
    entity_id: switch.lamp_voordeur
    domain: switch
  - service: mqtt.publish
    data:
      topic: cmnd/tasmota_NSPanel_kamer/Backlog
      payload: CustomSend notify
  - service: html5.dismiss
    data:
      data:
        tag: doorbell_tag
  mode: restart

I send also some other notifications as well, and Turn on the lights.

I do not specify devices using notify.notify. Just everyone who has installed the app gets a message.
which in my case is ok. Maybe other scenarios are different. You could still use notify.ios.
but I just want to mention there is a difference in the script.

I’ve marked @bkbartk 's reply as the answer. The trick was to use the external URL (https:///local/…) in combination with the timestamp. Thanks!

For people wanting to do more research on this topic: I think it could also be related to the fact that I use Cloudflared to connect to my home-assistant instance. Maybe Cloudflare caches the image, instead of Home Assistant?

This just saved me hours of frustration, thank you! I recently moved from DuckDNS to a Cloudlfare tunnel, and couldn’t figure out why I was getting outdated, cached images in my doorbell notifications. Using the external URL and unique timestamp was the solution.

1 Like