Replacing Unifi Video with Frigate and Home Assistant

Ubiquiti deprecated Unifi Video and don't support custom hardware with Unifi Protect, its replacement. Also there's that data breach malarky. I've been wanting to replace it for a while, and finally found something that works.

by Robert May on Afternoon Robot

Over the past few years I have tried every open source Network Video Recorder (NVR) available. Every one has had major flaws for my use-case, so I basically just stuck with Unifi Video, which isn't even particularly good itself. Then Ubiquiti replaced it with Unifi Protect and stopped publishing packages for you to install on custom hardware, requiring you to buy their inadequate pre-built solutions. And then they had a massive data breach, which is great for a company trying to force its users to "the cloud". God I hate the fucking cloud.

Anyway, there's finally an alternative which works, not only "well-enough", but better, for those of us who like to do things ourselves:

Frigate, integrated with Home Assistant.

I've written about a few of my HA setups already, and I'm generally a big fan of how it works. In the brief time I used Zoneminder, before I got bored of it dropping my camera streams, I had it working nicely with HA doing two things that I find very useful:

  • Automating when cameras are on and off
  • Notifying me of events on the cameras

Frigate finally brings those features directly into HA and they work amazingly well. Except when it identifies me with a 78% chance of being a cat, but hey, machine-learning. It provides a ton of nice sensors and switches to HA:

The cat sensor even has a cat icon. Now that's progress!

One big aspect to consider with any NVR is the ability to set up its recording, which is almost certainly using ffmpeg, to use as little CPU as possible. Frigate has the ability to specify multiple streams per camera, allowing you to use a low-resolution RTSP feed for object detection, but stream and record clips from the full-resolution stream. This is something I believe Unifi Video does, and which results in generally much less system load than a lot of alternatives. It's probably possible to set this up in other software, but I doubt it's as simple as a short YAML config:

# I run a mosquitto server for this
mqtt:
  host: localhost

# To be replaced once I receive my Coral USB device
detectors:
  cpu1:
    type: cpu
  cpu2:
    type: cpu

clips:
  retain:
    default: 180

# I dropped `-pix_fmt yuv420p` from the default setting here,
# as for my cameras this resulted in additional processing but
# has no noticeable effect.
ffmpeg:
  output_args:
    detect: -f rawvideo

objects:
  track:
    - person
    - cat

cameras:
  kitchen:
    ffmpeg:
      inputs:
        - path: rtsp://localhost:7447/one_1
          roles:
            - detect
        - path: rtsp://localhost:7447/one_0
          roles:
            - rtmp
            - clips
    width: 1024
    height: 576
    fps: 5

  not_kitchen:
    ffmpeg:
      inputs:
        - path: rtsp://localhost:7447/two_1
          roles:
            - detect
        - path: rtsp://localhost:7447/two_0
          roles:
            - rtmp
            - clips
    width: 1024
    height: 576
    fps: 5

I've ordered a suggested Coral device to speed up object recognition, as although my server can handle processing it itself, it does use rather a large amount of CPU to perform image recognition. Once this arrives I'll swap out the detectors section, but it works well even with this basic setup:

Basically just 20 images of me carrying cups of tea or playing saxophone

It took me about an hour to get a basic setup working with motion detection triggering automated recording, and this is already enough to replace my existing Unifi Video setup. Next I'll be reimplementing my home/away automations with the cameras.

And buying a catsuit, I guess.