šŸ“ø Notification with camera snapshot with blocking condition and clickaction

I have seen this behavior a couple times myself. But only when there have been multiple notifications sent in somewhat rapid succession. It has nothing to do with paths, thatā€™s a different discussion.

We could change the filename for the image to contain a unique identifier (like datetime) but then we would need to clean-up these photoā€™s at some point.

It could also just be a race condition, where the photo is not yet overwritten when the notification is send, because the snapshot service takes long to respond. In this last case this could easily be fixed by adding a wait before sending the notification.

Iā€™ll change the template later today.

I have added a (fixed for now) 2 second delay between creating the snapshot and sending it through notification.
Give that a try.

Thanks for the prompt reply, Stan. Honestly Iā€™m pretty perplexed by this. The 2 second delay didnā€™t seem to help (I changed it to 30 seconds also). I also added a 2 second delay per on when to take the snapshot, just to see if I could trace things.

Steps:

  1. manually execute the automation for testing (9:54:54 PM)
  2. through HA File Editor plugin, navigate to /config/www/tmp/ and check the timestamp on the file created (I manually deleted the prior files before the test). verify it is 2 seconds later due to the optional snapshot delay (9:54:56 PM)
  3. check the trace of the automation and verify the new 30 second blueprint delay (I overwrote your 2 second since that didnā€™t work the first try) is executed (9:54:56 PM)
  4. check the timestamp on when the notification was sent (9:55:26 PM)
  5. check the actual android notificaiton that came in at 9:54:56 PM and observe that the timestamp overlay is Friday at 2:44pm

I really donā€™t understand where it is pulling that image from. The image literally doesnā€™t exist in the directory. There have been probably 50+ snapshots since that time on Friday, where could it possibly still pull this one from? It seems to get ā€œstuckā€ sometimes on various old snapshots. Itā€™s not always 2:44pm Friday, I did get a few Sundays in there. Could it be cached in the app itself somehow?

I did restart HA after making the above changes and before this test. So if something was somehow in memory, I would assume that would have cleared out any 3+ day old snapshots.

Yes I got the same problem on iOS with a old snapshot always showing

Maybe iOS somehow caches the photo because itā€™s the same filename.
Letā€™s try with a unique filename.

Can you please try this blueprint. I have not tested it though, let me know how it goes.

It should create a file with the datetime stamp at the end.

1 Like

FYI, this appears to be working for me now. So based on Maxedmini, it doesnā€™t appear to be mobile OS specific. Iā€™m running latest Android OS on a Pixel for my testing. I will continue to test it tomorrow and see how it plays out and figure out the cleanup of the old files later.

The most curious thing is that the ā€œoldā€ images it shows are kind of all over the place. Most of the are from Friday, but then I had a few Sunday images in there, and then once or twice it was an actual fresh, new images. Thatā€™s the part I donā€™t quite get is how itā€™s mostly the same few old images, but itā€™s not consistent at all. The only thing I can think of is that Iā€™m running on a VM for years now and I know thatā€™s not the preferred installation approach for HA anymore, I just havenā€™t bother to migrate to docker.

Iā€™m running a VM with Home Assistant Operating System myself. I think itā€™s the preferred method next to running Home Assistant Operating System on bare metal.

Ya, I could be remembering wrong. I thought I recalled something in recent years about changing the recommended install methods.

Regardless, this does seem to be working well now. For my purposes, I did move the original delay to be ahead of the ā€œconditionā€ check. I did this so I could set the blocking entity state for the ā€œperson detectedā€ flag on my reolink camera which is slower to react/update to ā€œonā€.

I have two automations now, one triggered by the regular camera motion event, with a 1 second delay, and the condition check to see if a person has been detect. That sends the motion detected notification when there is no person. Then a separate notification triggered by the person detected sensor, with no blocking entity, that can send a different notification for the person.

Next will look at cleaning up old thumbnails.

#condition:
#  - condition: template
#    value_template: >
#      {{ (blocker_entity == none) or (states[blocker_entity].state == 'off') }}
action:
  - delay: "{{ delay }}"

  - condition: template
    value_template: >
      {{ (blocker_entity == none) or (states[blocker_entity].state == 'off') }}

  - service: camera.snapshot
    entity_id: !input camera
    data:
      filename: "{{ snapshot_create_file_path }}"

  - device_id: !input notify_device
    domain: mobile_app
    type: notify

Hi, the automation used to work perfectly even when I was connected to an external URL. Now it suddenly stopped sending and image when I am not on local URL. Is there a fix? I went through all the replies and I didnt find any fix :frowning:

On my iPhone - iOS HA app

There must be something wrong with your external URL.

Check if you can view the snapshot file in your browser.
The URL is something like below, check with internal URL and external URL.

https://home-assistant-server.domain.tld:8123/local/tmp/snapshot_camera_object_name.jpg

If you have the samba addon, you can use explorer to see the name of the file. Itā€™s in the config/www/tmp folder. You can also use SSH to lookup the name of the file.

thanks for the reply, i appreciate it a lotā€¦

i tried it and it works :confused: i tried it on my phone while on my local wifi, on cellular data, and also on my macbook, in all instances it worked fine via the external web adress for my home assistant

https://XXXXXXXXX.XXX/local/tmp/snapshot_192_168_101_33.jpg

Then I donā€™t know why itā€™s not working in the push notification on your iPhone.
Perhaps try a different SmartPhone for testing?