Currently i have my IP cameras uploading snapshots when motion detected to the /share folder at my hassio installation. This all works great with the ftp addon i’m using and every time the camera detects motion it uploads the snapshot to my hassio install and it places the video recording on a nfs drive on my nas.
Works great BUT now i want to use the last uploaded snapshot inside my new lovelace setup with a picture glance.
The problem i have is, how do i get the last uploaded file? I tried the folder_watcher but i can’t get my head around how this thing should work to get the last uploaded file. Another option was the file_sensor but since my camera uploads in a folder structure based on date / format / hours / minutes / image.jpg this doesn’t seem to work also because the folder structure changes during time.
Anyone having a suggestion to get the last file uploaded inside /share/dahua/camera_name/ and is able to look also inside the time based subfolders?
I have a dahua hvcr and do picture processing (remove dups, rotate, add to animated gif) from a folder for HA consumption.
For your purposes, can you not just add a shell command in HA to move the last file to your config/www folder and then point the camera from url component to that picture.
If you have a problem not knowing what that file is called, you might need to use a small python script.
But that would just display the current image and not the last one when motion detected if i’m correct.
My idea is to use the last motion detected image in a picture glance with the ability to view the live feed when you click on it. Besides displaying it inside a picture glance i would also like to use it to send an alert.
The ffmpeg camera component setup mentioned by @RobDYI would allow you to use camera.snapshot service to take snapshot, and store to a user-defined folder, of the camera stream. I use an automation based on motion detection sensor to take snapshot and send with notification using this approach.
I was setting up my door bell picture taking. Do you find the snapshot service responsive and good quality? I was planning to use a shell command with this working snapshot
Both of you are correct… if you want to use the basic motion detection. However that gives me a lot of false positives so i decided to use the IVS / Smart detection the camera has by itself.
Dahua cams also have things like tripwire / intrusion detection and that gives me way much less false poositives (better said, none) so i would realy like to use the camera motion detection. It just works better than the “normal” motion detection that’s part of the onfiv standard.
I have it running now, images are uploaded, only thing is i need to get the last image uploaded.
I have the following in my automations config now:
Thing is… it’s not working when i have {{ trigger.event.data.file }} in my message (i end up with a Error rendering data template: UndefinedError: 'trigger' is undefined in the log), when i replace it by anything else like “hi” it works fine but i can’t get the last file nor filename.
Nope… i end up with the same trigger error mentioned before.
It seems that the message part is the issue because when i replace it with just “hi”, walk through the tripwire of the cam i’m getting the message so the following is working,
camera uploads image
folder_watcher detects the image
automation runs fine with message: "hi" and i’m notified but fails when using the data as described in the example.
I found the quality is camera-dependent, the HA snapshot service responsiveness, however, is worst with rtsp.
I same setup for both rtsp and mjpeg stream from different camera, HA snapshot on mjpeg stream has been more reliable and responsive, rtsp stream sometimes just don’t work.
If you plan to use the ffmpeg command, be aware that ffmpeg can take couple of second for snapshot (depends on your system), so you may want to adjust your HA script/automation for the delay.
Do you get any off the three? {{ trigger.event.data.folder }} {{ trigger.event.data.path }}, {{ trigger.event.data.file }} individually. I understand that it will fire when any file is created so you need a condition in the automation to narrow it down into a certain folder.
I have not try the folder_watch approach for snapshot, but notify for ios requires the file url to be something like http://ha_ip:8123/local/your_snapshot/snapshot.jpg, you may want to double check what {{trigger.event.data.folder}} resolves as. ios notify example
I really don’t have a clue where to “debug” this. The images are uploaded, the folder_watcher detects the changes (because when the {{…}} stuff is removed i’m getting the notification) but getting the actual file name and location doesn’t seem to work (it begins to become frustrating now ).
Images are uploaded… could it be the filename? (don’t think so else the folder would have worked).
I copied and tested your last version (only the message), did not get any error and {{ trigger.event.data.folder }} resolved correctly to the full path folder name on my iphone notification message. So, it’s not syntax.
A wild shot, try adding a “- delay: 3” before the notify service, don’t forget the dash before service for multiple actions.
Don’t think a delay will solve the issue because i’m firing the event from the hassio interface (automations card) so the image is already there.
Will do further testing today to see if I can find a solution.
———edit ———
Ok I’m available for the dumbest user of the month award. Seems that it’s just working fine when a image is uploaded but it doesn’t work when the automation is fired from home assistant automations card.
When I left the house this morning I received multiple notifications with the image path in it.
Next up, display that data inside a Lovelace picture glance.
hi,
in the last days, i set up a webcam with the plugin motion1, which creates a snapshot in the folder /share/motion. for this folder i set up the folder_watch component succesfully.
Now i’d like to get an ios notification with the last snapshot created. the push notification works fine, but i don’t see the snapshot, only the text is pushed to my iphone.
@R2D2: Which of your configs is working for you? Do you see an image? I tested all of them, but none works for me