The uiprotect 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. uiprotect 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# optional: set to false if you have a self-signed certificate# export UFP_SSL_VERIFY=falseuiprotectnvr
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 uiprotect 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.
For any subcommand you can use uiprotect COMMAND --help
Commands are split between the reverse-engineered private API
(username/password auth) and Ubiquiti's documented Public Integration API
(API-key auth — see Public vs. private API).
The API column marks which is which; note that viewers (private) and
viewers-public (public) are distinct command groups.
All adoptable device CLIs and the event CLI work on the idea you have multiple cameras, multiple lights or multiple events. As such, they have four variations:
# list all devices (or events)uiprotectcameras
# list short list of all devices (or events)uiprotectcameraslist-ids
# list a specific device (or event)uiprotectcamerasDEVICE_ID
# run a command against a specific device (or event)uiprotectcamerasDEVICE_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.
The liveviews command group is driven by the Public Integration API and
authenticates with an API key only (no username/password required). It exposes
four subcommands:
# list all liveviewsuiprotectliveviewslist
# show a single liveviewuiprotectliveviewsshowLIVEVIEW_ID
# create a new liveviewuiprotectliveviewscreate\--name"Garage"\--ownerUSER_ID\--layout4\--slots'[{"cameras":["CAMERA_ID"],"cycleMode":"motion","cycleInterval":10}]'# patch an existing liveviewuiprotectliveviewsupdateLIVEVIEW_ID--name"New name"
--slots takes a JSON array of slot objects with keys cameras, cycleMode
(motion or time), and cycleInterval. --layout must be between 1 and 26.
See uiprotect liveviews --help (and --help on each subcommand) for the
full flag list.
The following command groups are driven by Ubiquiti's documented
Public Integration API and authenticate with
an API key (set UFP_API_KEY, or create one with uiprotect create-api-key),
not username/password. Each exposes list and (where applicable) show
subcommands plus group-specific actions; run uiprotect <group> --help for the
full flag list.
# list public-API sirens (API key auth)uiprotectsirenslist
# rename a viewer over the public APIuiprotectviewers-publicset-nameVIEWER_ID"Living Room"
The top-level uiprotect get-meta-info command is also Public-API driven.
uiprotect create-api-key NAME runs against the private, session-authenticated
(username/password) surface — you must already have a private session to mint
an API key.
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.