The unifi-protect command is provided to give a CLI interface to interact with your UniFi Protect instance as well. All
commands support JSON output so it works great with jq for complex scripting.
Following traditional twelve factor app design, the preferred way to provided authentication
credentials to provided environment variables, but CLI args are also supported.
About Ubiquiti SSO accounts
Ubiquiti SSO accounts are not supported and actively discouraged from being used. There is no option to use MFA. You are expected to use local access user. pyunifiprotect is not designed to allow you to use your owner account to access the your console or to be used over the public Internet as both pose a security risk.
exportUFP_USERNAME=YOUR_USERNAME_HERE
exportUFP_PASSWORD=YOUR_PASSWORD_HERE
exportUFP_ADDRESS=YOUR_IP_ADDRESS
exportUFP_PORT=443# change to false if you do not have a valid HTTPS Certificate for your instanceexportUFP_SSL_VERIFY=True
unifi-protectnvr
A number of commands allow you to enter a datetime as an argument or output files with the datetime in the filename. As a result, it is very important for pyunifiprotect to know your consoles local timezone. If you on a physical machine (not docker/VM), chances are this is already set up correctly for you (/etc/localtime), but otherwise you may need to set the TZ environment variable. TZ can also be used to override your system timezone as well if for whatever reason you need to. It should be the Olson timezone name for the timezone that your UniFi Protect Instance is in.
If for whatever reason your system does not have then correct timezone data, you can install the tz extra to get the data. This just adds the package tzdata as a requirement. It is included by default in the Docker image.
All adoptable device CLIs, event and liveview CLI work on the idea you have multiple cameras, multiple lights, multiple events or multiple liveviews. As such, they have four variations:
# list all devices (or events/liveviews)unifi-protectcameras
# list short list of all devices (or events/liveviews)unifi-protectcameraslist-ids
# list a specific device (or event/liveview)unifi-protectcamerasDEVICE_ID
# run a command against a specific device (or event/liveview)unifi-protectcamerasDEVICE_IDCOMMAND
Note
The "list all devices" and "list a specific device" commands always return raw JSON. These commands can be paired with jq to parse and quick extra device data from them.
Command
Description
list-ids
Requires no device ID. Prints list of "id name" for each device.
set-person-track
Requires device ID. Sets person auto tracking on or off for PTZ cameras.
There are 5 options controlling output format for file names and metadata. This allows you to customize backups to your liking. All 5 options are a template string. Here are all of the available templating variables:
Variable
Description
year
UTC year of start of export.
month
UTC month of start of export.
day
UTC day of start of export.
hour
UTC hour of start of export.
minute
UTC minute of start of export.
datetime
ISO 8601 formatted UTC datetime of start of export. Uses sep between parts.
date
ISO 8601 formatted UTC date of start of export. Uses sep between parts.
time
UTC time of start of export. Uses sep between parts. 24 hour time.
time_sort_pretty
UTC time of start of export. Uses : between parts. 24 hour time.
time_pretty
UTC time of start of export. Uses : between parts. 12 hour time with AM/PM.
All datetimes for the Backup CLi can either be in ISO 8601 format or can be a human readable format that the Python library dateparse can understand. This will allow relative datetimes to be passed, such as "1 hour ago" which will make backing up incremental for cron jobs.
Smart Detection types to export. Can be used multiple time.
-p
--prune
boolean
False
Prune events older then start.
-f
--force
boolean
False
Force update all events and redownload all clips.
-v
--verify
boolean
False
Verifies files on disk.
--no-input
boolean
False
Disables confirmation prompt if -p and -f both passed.
--help
Show help message and exit.
The backup events command essentially mirrors all of the selected events from your UniFi Protect instance into a local sqlite database (events.db inside of the --output-folder). As a result, the initial run make take a really long time to run if your UniFi Protect instance has a lot of events inside of it.
As an example using a UniFi Protect instance with ~200k events and ~8 months of camera footage:
Building the database is in the range of hours
Doing the initial download of event thumbnails, gifs and video clips is in the range of tens of hours (potentially 1-2 days)
Incremental or targeted backups are much faster (<1 per event)
Cron Usage
For incremental backups in crons, it is recommended you run the command with an absolute start first to build your events database and do an initial download of files. This will significantly speed up the incremental backup commands.
$unifi-protectcameras61ddb66b018e2703e7008c19set-sshtrue# get current value to verify$unifi-protectcameras61ddb66b018e2703e7008c19|jq.isSshEnabled
true