HA: Camera Snapshots
How do you deal with camera snapshots?
Where do you store them, how do you archive them?
In short:
1. Take snapshot
2. Store snapshot
3. Copy to archive location
Let’s first think about what should trigger the creation of a camera snapshot.
Snapshot triggers
What triggers a camera to store an image?
- Motion
- Doors/windows opening
- Doors/windows open for a long time
- Daily snapshots (at 12:00 – I take these for a long-term stop-motion where you can see nature growing / changing)
- Doorbell
1. Where to store snapshots?
First of all I created a folder under /media/ called camera. You can store images:
A. in a fixed location with a fixed name
Now you can always access the “latest frontdoor open” image in a fixed location. Example:
/media/camera/cam_frontdoor_open.jpg
/media/camera/cam_frontdoor_bell.jpg
/media/camera/cam_backdoor_open.jpg
/media/camera/cam_garagedoor_open.jpg
Why? You can now refer to a fixed image name if you want to send these images using Webex Message (like, with a huge amount of features!), Pushover, HA notification or email
B. in an archive location with a dated name
Name example: IMAGE_NAME–yyyymmdd–HHmmss.jpg. With this filename a new snapshot won’t overwrite the old one.
You can store them in a folder structure to easily navigate and find specific snapshots. Example:
/media/camera/cam_frontdoor_bell/2023/11/cam_frontdoor_bell-20231201-093045.jpg
/media/camera/cam_frontdoor_open/2023/11/cam_frontdoor_open-20231130-132218.jpg
/media/camera/cam_frontdoor_open/2023/12/cam_frontdoor_open-20231201-093055.jpg
/media/camera/cam_frontdoor_bell.jpg
/media/camera/cam_frontdoor_open.jpg
Why? These files will not be overwritten.
2. Create & Save Snapshots:
In your configuration.yaml you can add generic camera integration.
camera: - platform: generic name: cam_homeaxis6 still_image_url: https://192.168.1.211/jpg/image.jpg username: !secret axis6_user password: !secret axis6_pwd
NOTE: after updating your configuration.yaml you probably have to restart HA.
There are other ways of capturing snapshots. One example is using the Synology DSM integration which allows you to call the snapshot function of the Surveillance Station.
Now call the “take snapshot” service from an automation or script:
I created a folder “camera” under the “media” folder. This seemed the appropriate location.
3. Copy snapshot to the right location
Now you have the snapshot you can copy it for archival purposes. To do this I created a script (.sh file) and used the shell_command in the configuration.yaml.
NOTE: tested on a Raspberry Pi with the HA OS.
The “copy_cam_snapshot.sh” script is stored in the /media/camera/ folder. Script content:
SNS_DATE=`date +%Y/%m` SNS_DATE_FILE=`date +%Y%m%d-%H%M%S` mkdir -p "/media/camera/$1/$SNS_DATE" cp "/media/camera/$1.jpg" "/media/camera/$1/$SNS_DATE/$1-$SNS_DATE_FILE.jpg"
In the configuration.yaml
add the following command_line entries:
shell_command:
copy_cam_frontdoor_open: "sh /media/camera/copy_cam_snapshot.sh cam_frontdoor_open"
copy_cam_frontdoor_motion: "sh /media/camera/copy_cam_snapshot.sh cam_frontdoor_bell"
These commands call the (above) shell script with the base filename as a parameter.
the command “copy_cam_snapshot.sh door_open“:
1. creates a folder /media/camera/door_open/_YEAR_/_MONTH_
2. copy /media/camera/door_open.jpg
to /media/camera/door_open/2023/12/door_open-20231204-1755.jpg
NOTE: after updating your configuration.yaml you probably have to restart HA.
From automations or scripts you can now call the “Shell Command” service
Long term archival
For long term storage you can think of running some kind of script that moves snapshot images to a NAS or cloud service.
At this moment I (manually) move them to a NAS that is synchronized with another NAS in a different location. This will change to an automated process
You could probably do something with cron-jobs, samba plugins, file-sync tools etc.
Final Thought
- You could probably turn this whole thing into a blueprint that’s easy for anyone to use. I just have the time (right now) to learn creating blueprints.
- Enable a date-timestamp on your camera to get the most accurate snapshot date/time.
Other than that, I just hope that this has helped you a little bit.
Of course I would love to hear about better/easier/more efficient ways of doing this.
Cheers!
DJ