The local outdoor cats kept bothering my indoor cats, so I built a sprinkler that turns on when Frigate sees a cat in the backyard.

The system has four parts:

  1. A cheap security camera
  2. A DIY sprinkler controller running ESPHome
  3. Frigate NVR
  4. Home Assistant

Below you can see the system deterring a cat that was approaching my house at night.

The camera points over the backyard and Frigate runs detection on the stream. I track people and cats, but only want the sprinkler to run when there is a cat and no person.

Backyard security camera used for Frigate cat detection

Frigate

In Frigate I added cat as a tracked object on the backyard camera. The cat threshold is lower than the person threshold because the cats are smaller and further from the camera.

backyard:
  ffmpeg:
    inputs:
      - path: rtsp://127.0.0.1:8554/backyard_record?video&audio
        roles:
          - record
          - detect
  detect:
    width: 1280
    height: 720
    fps: 5
  objects:
    track:
      - person
      - cat
    filters:
      person:
        threshold: 0.9
        min_area: 2500
      cat:
        threshold: 0.5
        min_area: 1250

Sprinkler Controller

The sprinkler controller is just an ESP32 switching a GPIO pin. It sits in an old outdoor irrigation box with a power supply and relay board.

Backyard sprinkler and controller box connected to the garden tap ESPHome sprinkler controller inside an outdoor irrigation box
esphome:
  name: sprinkler
  platform: ESP32
  board: az-delivery-devkit-v4

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  power_save_mode: none
  fast_connect: true

api:

ota:
  - platform: esphome

switch:
  - platform: gpio
    name: "Switch"
    pin: 22
    restore_mode: ALWAYS_OFF

Home Assistant

Home Assistant listens for Frigate's cat occupancy sensor. If there is no person in the backyard, it sends me a notification, turns on the sprinkler, waits 30 seconds, then turns it off.

alias: Backyard Cat Notification
mode: single
triggers:
  - entity_id: binary_sensor.backyard_cat_occupancy
    from: "off"
    to: "on"
    trigger: state
conditions:
  - condition: state
    entity_id: binary_sensor.backyard_person_occupancy
    state: "off"
actions:
  - action: switch.turn_on
    target:
      entity_id: switch.sprinkler_switch
  - delay:
      seconds: 30
  - action: switch.turn_off
    target:
      entity_id: switch.sprinkler_switch

Original Mastodon post