Skip to main content

Unifi cameras are great versatile devices that you can use in pretty much any situation. In this case, I needed to make a timelapse from a construction site. I have chosen to use a G3 bullet for this because it’s easy to mount and has great video quality.

Unifi Protect doesn’t come with any timelapse features, but you can get a snapshot from the camera. With a small script, we can automate this, to get a snapshot from one or multiple cameras every x minutes.

In this particular case the camera, and Cloudkey, was placed offsite. So besides storing the snapshots on the CloudKey alone, I also wanted to upload the files to a cloud storage provider so we have a backup of all the snapshots.

Capturing snapshots from an Unifi Protect Camera

The first part is to automatically get snapshots from the camera. First, you need to allow anonymous snapshots from the cameras. You will need the device password for this, which you can find in Unifi Protect:

  1. Open Unifi Protect
  2. Select Settings
  3. Expand Advanced
  4. Click on Reveal to copy the password

Next, we need to open the camera directly. Make sure you have the IP address of the camera, you can also find it under devices in Unifi Protect.

  1. Navigate to http://<ip-address-camera>
  2. Login with ubnt and your device password
  3. Enable anonymous snapshot and click Save Changes

You should now be able to see a snapshot of the camera by navigating to http://<ip-of-your-camera>/snap.jpeg

Automating the snapshots

To get the snapshots automatically we are going to use a small shell script. There is no need to re-invent the wheel, sfeakes @Github create a script that we can use perfectly for this. It also comes with a bonus, because you can also create the timelapse video with the script.

I have placed the scripts on the CloudKey, to do this you will need to enable SSH access. You can do this on the CloudKey under Advanced. Make sure you set a strong password.

To copy or edit the scripts below, you can either use WinSCP to make an SFTP connection or use the terminal if you like.

  • Copy the script to the CloudKey in the folder /home
  • We need to edit the script:
    • Add the IP Address(es) and name(s) of the camera(s) that you want to capture
    • Change the snap_base path to /media:
1. # Set the local directory to store the snapshots
2. SNAP_BASE="/media"
4. # Add the list of cameras with the details of your camera(s)
5. CAMS["LA Driveway"]=""

You should now be able to create a snapshot by running the command below. Make sure you use the camera name as you have defined in the file

1. /home/ savesnap "name camera 1" "name camera 2"

If you configured everything correctly you should see an output similar to:

1. savingSnap to /media/LA Driveway/LA Driveway - 2021-02-22 20:15.jpg

If you get a permission error, then you will need to change the chmod rights on the file to 755:

1. chmod 755 /home/

We only need to create a cronjob to automatically great the snapshots, which we will do at the end of the article.

Copy the snapshots to the cloud

The next step is to copy all the snapshots to an external (cloud) storage. This step is optional, but if anything happens to the Cloudkey or the hard disk in the Cloudkey, then we still have all the snapshots.

We are going to use Rclone for this. I have written about making backups of your Cloudkey with Rclone before. For the timelapse, I have used cloud storage from Mega. The advantage of Mega is that you get 50Gb of storage for free, which is more than enough for this situation.

Install and configure rclone

First we need to install rclone and configure our cloud storage, Mega, in this case. We start with installing rclone on our Cloudkey:

1. curl | sudo bash

Run rclone config when the installation is finished:

1. rclone config
3. # Add a new remote
4. n
6. # Enter a name
7. mega_timelapse
9. # Choose storage provider

And your username and password from rclone to finish the configuration.

Copying the files to the cloud storage

With the remote connection set up, we can now start with copying the files. Rclone comes with two options to copy the files, you can either use sync or copy. Because we want to create a backup, we are going to use the copy method.

Sync will keep your Cloudkey and remote synchronized, so files that are deleted on your Cloudkey will also be deleted on the remote, and we don’t want that.

I have created a folder in Mega named “timelapse”. You can test the reclone configuration with the following command:

1. # Copy the files to the cloud: rclone copy <folder-on-cloudkey>  <rclone-remote-name>:<remote-folder-name>
2. rlcone copy /media/ mega_timelapse:timelapse

The files should now be copied to your cloud storage.

Creating the Cronjobs

We have everything configured, we only need to create the cronjobs so the timelapse pictures are taking every x minutes and the files are backed-up to our cloud storage.

Type crontab -e and add the following to the end of the file:

1. # Create the timelapse snapshot every 5 minutes
2. */5 * * * /home/ savesnap "name camera 1" "name camera 2"
4. # Copy the timelapse pictures every hour
5. 0 * * * rclone copy /media mega_timelapse:timelapse
7. # Press Ctrl + X to close and choose Y to save.
8. # On the CloudKey press Ctrl + C twice and then type :wq to save and close

Save and close the file and you are all set.

If you want to create the snapshots between specific times, then you can use the following format to create the snapshots:

1. */5 07-19 * * * /home/ savesnap "name camera 1" "name camera 2"

This will create a snapshot every 5 minutes between 07.00 and 19.00.