Integrating Frigate with Home Assistant for Advanced AI-Powered Surveillance

0
0
  • #ai
  • #automation
Represent Integrating Frigate with Home Assistant for Advanced AI-Powered Surveillance article
5m read

Security cameras are a cornerstone of modern smart homes, providing peace of mind and crucial monitoring capabilities. While Home Assistant offers basic camera stream integration via protocols like RTSP and ONVIF, leveraging their full potential, especially with AI-powered object detection and robust network video recording (NVR), often requires dedicated systems. Enter Frigate, a high-performance, open-source NVR that utilizes AI (specifically Google Coral or compatible TPUs) to perform real-time object detection on camera streams. Integrating Frigate with Home Assistant elevates your surveillance system from simple viewing to intelligent, actionable insights.

Why Integrate Frigate with Home Assistant?

Frigate excels at identifying specific objects (like persons, cars, dogs) in your camera feeds with high accuracy, minimizing false positives compared to traditional motion detection. By bringing this data into Home Assistant, you can:

  • Trigger automations based on specific objects entering predefined zones (e.g., turn on porch light when a person is detected near the front door after dark).
  • Receive rich notifications with snapshots or short clips of detected events directly on your mobile device.
  • Use detection data for presence simulation or security states.
  • View camera streams, detection events, and recorded clips all within your Home Assistant dashboard.
  • Arm or disarm Frigate detection or specific cameras based on Home Assistant states (like home/away mode).

This integration moves beyond simple monitoring, making your cameras active participants in your smart home automations and security logic.

Prerequisites

Before diving into the integration, you'll need a few things:

  • A server capable of running Frigate: This could be a dedicated mini-PC (like an Intel NUC), a server, or even a powerful Raspberry Pi 4 (though AI performance might be limited without a TPU).
  • IP Cameras: Cameras that support RTSP or RTMP streams are necessary. Most modern IP cameras do.
  • AI Accelerator (Recommended): A Google Coral USB Accelerator or PCIe card significantly speeds up object detection, allowing for more cameras and higher frame rates. While CPU detection is possible, it's often resource-intensive.
  • MQTT Broker: Frigate communicates its detection events primarily via MQTT. You'll need an MQTT broker running, which can be the Mosquitto broker addon in Home Assistant.
  • Home Assistant Instance: A running Home Assistant instance (OS, Container, Supervised, or Core).
  • HACS (Home Assistant Community Store): The recommended way to install the Frigate integration in Home Assistant.

Setting up Frigate (Briefly)

Installing and configuring Frigate itself is a detailed process best covered by the official Frigate documentation (https://docs.frigate.video/). The most common installation method is using Docker. Your Frigate configuration file (`config.yml`) is crucial. Key sections you'll configure include:

  • MQTT: Connection details for your MQTT broker, which Home Assistant will also connect to.
  • Cameras: Define each camera, its RTSP feed URL, potential detection zones, objects to track, and resolution settings.
  • Model: Specify your AI accelerator type.
  • Storage: Where recordings and snapshots are saved.

Ensure Frigate is running and successfully publishing events to your MQTT broker before proceeding to the Home Assistant side.

Integrating Frigate with Home Assistant

1. Install the Frigate Integration via HACS

If you don't have HACS installed, follow the instructions on the HACS website (https://hacs.xyz/). Once HACS is set up in Home Assistant:

  1. Go to HACS -> Integrations.
  2. Click the '+' button in the bottom right.
  3. Search for "Frigate".
  4. Select the "Frigate Integration" by @blakeblackshear (the creator of Frigate).
  5. Click "Download" and choose the latest version.
  6. Restart Home Assistant.

2. Configure the Frigate Integration

After restarting Home Assistant:

  1. Go to Settings -> Devices & Services.
  2. Click the '+ ADD INTEGRATION' button.
  3. Search for "Frigate".
  4. Select the "Frigate" integration.
  5. A configuration window will appear.
  6. Frigate Host/IP: Enter the IP address or hostname of the server running Frigate (e.g., 192.168.1.100). If Frigate is running on the same machine as Home Assistant and configured to use host networking in Docker, you might use localhost or 127.0.0.1, but using the actual IP is generally safer.

  7. MQTT Enabled: Ensure this is checked.

  8. MQTT Topic Prefix: This should match the topic_prefix configured in your Frigate config.yml (defaults to frigate).

  9. Click "Submit".

  10. If the connection is successful, Home Assistant will discover your cameras and their associated sensors from Frigate via MQTT.

Exploring the Entities

Once configured, the Frigate integration will create various entities in Home Assistant for each camera defined in Frigate:

  • Camera Entities: (e.g., camera.front_door). These provide the camera stream and often a low-resolution sub-stream for dashboards.
  • Binary Sensors: (e.g., binary_sensor.front_door_person, binary_sensor.front_door_car). These turn on when the specific object is detected and off after a configurable timeout. These are your primary automation triggers.
  • Sensors: (e.g., sensor.front_door_person_count, sensor.front_door_detections). These provide counts or other numerical data.
  • Switches: (e.g., switch.front_door_detection). Allows enabling or disabling detection for a specific camera from Home Assistant.
  • Other Entities: Depending on your Frigate setup, you might see entities for motion, snapshots, etc.

Building Automations with Frigate Data

The real power lies in using the binary sensors to trigger actions. Here are a few examples:

Example 1: Turn on Light When Person Detected After Dark


automation:
  - alias: Turn on porch light on person detection
    trigger:
      - platform: state
        entity_id: binary_sensor.porch_person
        to: 'on'
    condition:
      - condition: sun
        before: sunset
        after: sunrise
        before_offset: "-00:30:00" # Example: 30 mins before sunset
        after_offset: "+00:30:00"  # Example: 30 mins after sunrise
    action:
      - service: light.turn_on
        target:
          entity_id: light.porch_light
        data:
          brightness_pct: 100
      - delay: "00:02:00" # Keep light on for 2 minutes
      - service: light.turn_off
        target:
          entity_id: light.porch_light

Example 2: Send Notification with Snapshot on Car Detection in Driveway


automation:
  - alias: Notify on driveway car detection
    trigger:
      - platform: state
        entity_id: binary_sensor.driveway_car
        to: 'on'
    action:
      - service: notify.mobile_app_your_phone # Replace with your notification service
        data:
          title: "Car Detected in Driveway"
          message: "A car was detected in the driveway."
          data:
            # Include a snapshot with the notification
            image: "/api/frigate/notifications/{{trigger.id}}/snapshot.jpg"
            clickAction: "/dashboard-frigate" # Optional: Open a Frigate dashboard view
            # Android-specific actions for viewing clip/snapshot
            actions:
              - action: URI
                title: View Clip
                uri: "/api/frigate/notifications/{{trigger.id}}/clip.mp4"
              - action: URI
                title: View Snapshot
                uri: "/api/frigate/notifications/{{trigger.id}}/snapshot.jpg"

Note: Snapshot/clip URLs require the Frigate integration to be configured correctly and accessed via the Home Assistant proxy. The trigger.id variable is crucial for referencing the specific detection event.

Best Practices for a Reliable System

  • Optimize Frigate Configuration: Ensure your camera resolutions, frame rates, and detection zones in Frigate are set up efficiently. Too high settings can overload your hardware. Use the Frigate UI to monitor resource usage.
  • Use Detection Zones: Define specific zones in Frigate where detection matters (e.g., excluding public sidewalks). This reduces false positives and saves processing power.
  • Leverage MQTT: Frigate relies heavily on MQTT. Ensure your broker is stable and accessible by both Frigate and Home Assistant.
  • Invest in a Coral Accelerator: If you plan on using multiple cameras or detecting at higher frame rates, a Coral TPU is highly recommended for performance and stability.
  • Manage Storage: Frigate records events and potentially full-time video. Plan your storage solution (local disk, NAS mount) and configure retention policies in Frigate's config.
  • Utilize the Frigate Lovelace Card: The Frigate HACS integration provides a dedicated Lovelace card that beautifully displays camera feeds, recent events, and clips directly in your dashboard, offering a unified surveillance view.
  • Secure Access: If accessing Frigate or Home Assistant externally, ensure you use secure methods like Nabu Casa Cloud, a VPN, or a reverse proxy with SSL.

Conclusion

Integrating Frigate with Home Assistant transforms your security cameras into intelligent sensors capable of triggering sophisticated automations. By combining Frigate's powerful AI object detection and NVR capabilities with Home Assistant's automation engine and unified interface, you create a robust, responsive, and smart surveillance system that adds significant value and security to your home.

Avatar picture of NGC 224
Written by:

NGC 224

Author bio:

There are no comments yet
loading...