Security Cameras in Home Assistant with Frigate

0 Shares
0
0
0
0

Home security systems are common-place nowadays, and smart cameras are even more common with the advent of Ring doorbells. Now the industry is more competitive than ever, with big security brands such as ADT and Verisure in the market. Everyone wants a piece of the pie, and subscriptions for ‘cloud-connected’ home security is big business… but can we use Home Assistant to do this subscription free and can we do it better?

Its 2024, and I don’t think there are many tech companies who don’t have a home security brand under their umbrella. Lets list a few

  • Ring.com owned by Amazon
  • Nest owned by Google
  • Hue Security by Philips
  • Smart Security by Yale

I could continue writing the list for hours to come. However on top of the cost of the cameras or doorbells, there is a theme with all of these vendors – subscriptions.

  • Ring’s subscriptions in the UK start at £50 per year
  • Nest starts at £6 per month, so £72 a year
  • Phillips Hue starts at £36 per camera per year
  • Yale starts at £3.50 per month, per camera, so £42 a year

I’m not saying that these products aren’t great, they all have their value and peace of mind. But lets say you decide you want a 2 camera + doorbell system. Cameras are on average going to cost you £150 each, same again for the doorbell, so over 3 years you’re looking at in investment of around £600ish assuming you self-install.

Well round here, we’re geeks and we’re going to see how Home Assistant, with a rather nice app called Frigate can help out for a lot cheaper, with a lot more features.

Introducing Frigate

Frigate NVR is an open source product built with AI object detection to locally process video feeds. Right up our street huh? Its had over 15k stars on github and over 2 million pulls on Docker. It might still on version 0.13.2 as of the time of this post, but this is a very good application indeed.

I want to go through some of the high level features its got, and why I think it can not only compete with some of the subscription services above, but in a lot of cases, beat them.

Object Detection

First, lets talk object detection – pretty much every smart camera is promoting this as a premium feature. Essentially what it does is determine whether an object is a person, a car, or another object. Frigate works really well with the Google Coral TPU which means its running detections 100s time a second, locally instead of sending your data to the cloud – which firstly reduces the number of false positives, and secondly means your face isn’t getting uploaded to somewhere on the planet.

Oh and out of the box, Frigate can detect people, cars, umbrellas, toothbrushes, donuts, the list goes on. In fact the list goes on to 91 different types of objects. If I’m honest, I’m yet to see an alert for donuts, but hey – there are some creative folks out there!

Zones

Now zones aren’t particularly unique – they purely allow you to create areas within the camera view and then notify you if it see’s movement. Frigate is a bit smarter than that though, it can alert you when something leaves or enters that area. Lets use the example of your husband’s car pulling on to the driveway, you might want to know – but you don’t want to know every few mins until he moves it the next day do you?

Integration with Home Assistant

I know I’m kinda cheating by using this as a feature, but what’s cool here is that object detection can be a trigger for an automation, so lets say your wife arrives home from work, and she really likes to listen to some relaxing music when she gets in, you can make your smart speaker play her favourite song, and set the lighting low in the living room so she can relax. Think of the brownie points huh?

Integration with Third Parties

Yeah, I know – the most over-used term in tech. But here, it’s more relevant than ever. Firstly, it supports use of an external TPU which to you and I could mean something like a USB-powered Google Coral which is fantastic for enhancing the detection element of your camera streams.

Secondly, it supports Doubletake, a UI and API for processing and training images for facial recognition as well as other facial-recognition app such as Compreface or Facebox. This is what sets Frigate above the likes of Ring because you can literally train it to recognise your family or friends and perform automations such as a simple notification or more complex automations based on who is on the camera.

Getting Set Up

Frigate install on Home Assistant is pretty simple, you can find it in the Add-ons store (Settings > Add-ons).

If you haven’t already installed it as part of a requirement for other addons, MQTT (install instructions) is pretty much a mandatory at this point. It’s a very simple IoT protocol built on top of TCP/IP (much like HTTP) which is used to pass messages between different devices in a reliable and secure way. This thread in the Home Assistant Community forums explains it really well.

Anyway, once you’ve got Frigate installed you need to provide it a base configuration in which to accept your local IP cameras and connect to MQTT. This is easiest done within Frigate, so once it’s installed start the service and head over to the Web UI and on the left click ‘config’. Here is my first base config I used to get a test camera up and working:

mqtt:
  user: "{FRIGATE_MQTT_USER}"
  password: "{FRIGATE_MQTT_PASSWORD}"

Note: It’s worth adding at this point, having your passwords in clear text in your config is bad practice, so I would recommend using secrets.yaml (link on set up here) as it means that sharing your config at any point doesn’t leave you sharing your passwords and all of your secrets stay in one safe place.

Frigate will work with pretty much any camera as long as the feed is given to it in the correct format. This is often an RTSP feed (e.g. rtsp://10.0.10.10:554/rtsp) and can often be configured on your cameras local management page.

Often a quick Google of your camera model and the word frigate will often find you with some guidance

Next up, if you’ve got an external Google Coral TPU plugged in to Home Assistant, that’s just a simple matter of telling frigate to use it:

ffmpeg:
  hwaccel_args: preset-vaapi

detectors:
  coral:
    type: edgetpu
    device: usb

Once you’ve saved and restarted Frigate you should see your camera stream on the Frigate home page. When saving, Frigate handily checks your configuration is valid before restarting so it’s difficult to put a foot wrong as such.

At this point you’ve got a camera stream in frigate, and no doubt you’re doing a dance in front of your camera to check it’s working. If so, well done!

Now we need to get a little clever, so its back into the config we go

cameras:
  front_doorbell:
    enabled: true
    ffmpeg:
      inputs:
        # High Res Stream
      - path: rtsp://127.0.0.1:8554/front_door_main
        input_args: preset-rtsp-restream
        roles:
        - record
        # Low Res Stream
        #- path: rtsp://192.168.x.xxx:8554/front_door
      - path: rtsp://127.0.0.1:8554/front_door_sub
        input_args: preset-rtsp-restream
        roles:
        - detect
      output_args:
        record: preset-record-generic-audio-copy
    live:
      stream_name: front_door_main
    detect:
      max_disappeared: 10
    objects:
      track:
      - person
    snapshots:
      enabled: true
      timestamp: false
      bounding_box: true
      retain:
        default: 10
    record:
      enabled: true
      events:
        retain:
          default: 10
    zones:
      zone_driveway:
        coordinates: 489,672,896,672,896,353,382,380,131,379,0,416,0,672

Lets break this down a little bit, firstly you can see two inputs: a high and low res stream. I have a high res stream for recording – I want the best quality stream from my camera should I need to look back at a clip but when it comes to detecting, a lower res is fine – speed here is more important (i.e. a quick detection of an object). Obviously this depends on the camera(s) you have, and the hardware that Home Assistant is running on. This is a CPU (or TPU) heavy task, so think about how many and which cameras you’re going to add to Frigate when you spec your Home Assistant hardware.

Within detect, you can see max_disappeared. This defines the number of frames from when the object is gone and the ‘event’ is ended. This is important as you don’t want the event continuing to record long after the person or object has left the view of the camera

Next are the objects you wish to track – for now I just have a person – but we will build on this later. We could add cars here and all number of things

Next is defining the snapshots of images and the configuration of them. I want them available so we set that true, I am not bothered about them being timestamped so I set that to false. The bounding box surrounds the object that has trigged the snapshot, and displays its confidence that the object is a person, thats an personal preference, but I prefer it on. Lastly, its the retain settings, the number of days that the snapshots will be retained which for me is 10.

We then have the record settings, which are essentially the clips (or videos) that the camera records when an event occurs. The settings available here are much the same as the snapshots – I just chose not to have the bounding box on these.

Lastly is a feature called zones. This is a pretty common setting in cameras, which allows you to define a zone on the camera view to only create events on. My zone is called ‘zone_driveway’ and you can see a number of coordinates. To get this part of the config, you can use the GUI – and I’ve put together a quick video showing you how:

The best reference you can probably look at is here, Frigate’s reference config where it gives you a description of every option, and an example reference configuration and it’s where I first started.

I was going to make this a bit of a monster post, but I’m going to do a second blog where I focus on the integration aspect of Frigate (in other words – AI!) , and the notifications you can product using Frigate and Home Assistant. Stay tuned for part 2

0 Shares