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:
- A cheap security camera
- A DIY sprinkler controller running ESPHome
- Frigate NVR
- 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.
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.
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