Build squirrel detector with sprinkler trigger

Detect squirrels in Frigate with a single-class model on the AI HAT+ NPU and publish an MQTT sprinkler trigger from a listener on the Raspberry Pi 5. No valve is wired.

Works with

AI HAT+Product overviewonRaspberry Pi 5

How it works

A single-class squirrel model runs as a native Frigate detector on the Sixfab AI HAT+ for Raspberry Pi 5 (DEEPX DX-M1M): Frigate’s DEEPX detector runs it on the NPU, and the rule logic runs on the Raspberry Pi 5 CPU, in a listener that turns each squirrel event into an MQTT sprinkler trigger. The project is part of the Raspberry Pi 5 AI projects series.

  1. An RTSP feed reaches Frigate as the camera garden (use your own camera name).
  2. Frigate’s DEEPX NPU detector runs the squirrel .dxnn model on the NPU through the DX-RT runtime.
  3. Frigate tracks each squirrel as an event (Frigate’s record of one tracked object across many frames) with the label Squirrel.
  4. Frigate publishes the event to the MQTT broker on the topic frigate/events (see Frigate’s MQTT docs).
  5. The listener, a systemd service that runs under your own user account instead of root, receives the event and checks it against its score and cooldown rules.
  6. The listener’s trigger function publishes a JSON trigger to squirrel_sprinkler/trigger and logs a line. A relay and valve would connect here.

Read the detections in Frigate’s web interface at https://[PI_IP]:8971 and each trigger on the squirrel_sprinkler/trigger topic; Verify shows both.

Requirements

Before starting

Set up first, in this order

Hardware

  • Raspberry Pi 5Host for Frigate and the listener. Tested on the 8 GB model
  • Sixfab AI HAT+ (DEEPX DX-M1M)Mounted on the Raspberry Pi 5
  • RTSP camera or streamrtsp://<stream-host>:8554/<stream-path>

Software

  • Raspberry Pi OS TrixieThe tested OS
  • MQTT brokerMosquitto on <broker-host>, port 1883
  • git, curl, sha256sum, ffprobeffprobe comes with ffmpeg
  • mosquitto_subFor Verify
  • python3 with venvThe installer adds paho-mqtt

DEEPX support is in Frigate’s dev branch

DEEPX support was merged into Frigate’s dev branch on September 21, 2026 (PR #24336) and is not in a stable release yet; the latest stable release is v0.18.0 (September 12, 2026). The ghcr.io/blakeblackshear/frigate:af0ba19-standard-arm64 image, which the Frigate setup page pulls, is built from commit af0ba19 of the dev branch. Sixfab develops and maintains DEEPX support in Frigate (Frigate’s DEEPX NPU detector docs).

Install

Run the install on the Raspberry Pi 5. It adds the squirrel camera and model to your running Frigate and starts the listener. The installer and the listener are in the project folder of sixfab-dx-frigate on GitHub; the model is a ready-compiled file from the project’s GitHub release.

Verify

API checks run inside the container; the browser reaches Frigate only through the authenticated port 8971. List the recent events of the garden camera:

docker exec frigate curl -s 'http://localhost:5000/api/events?camera=garden&limit=10'

The response is JSON; detected squirrels appear with the label Squirrel. To see the detections, open https://[PI_IP]:8971 and select the garden camera (or your own camera name). Switch on Bounding Boxes in the debug view to watch each detection, as in Figure 1.

Subscribe to the trigger topic:

mosquitto_sub -h [BROKER_HOST] -t squirrel_sprinkler/trigger -v

Each accepted trigger publishes one JSON message with the camera name, the score and a timestamp, at most one per camera every 30 s. This message was captured in the test:

squirrel_sprinkler/trigger {"camera": "garden", "score": 0.89, "timestamp": 1791272738.7976897}

The service status is active (running) in systemctl --user status squirrel-sprinkler-automation.service -l. At start the listener logs Connected to broker (<broker-host>:1883), listening on frigate/events, and each trigger logs SPRINKLER TRIGGER camera=garden score=<score> (simulated for now).

Details

Model

The COCO-80 label map that the Boss Detector project uses has 80 lines and no squirrel entry, so a COCO-80 detector cannot report a squirrel. This project’s model, squirrel-detector-model.dxnn, is a single-class squirrel detector compiled to .dxnn, DEEPX’s model format; its label map holds one line, Squirrel.

Detection settings

The installer merges these camera and model settings into your Frigate config.yaml and replaces the RTSP path with your RTSP URL:

models:
  - scene: outdoor
    model_type: yolo-generic
    width: 640
    height: 640
    path: /config/model_cache/squirrel-detector-model.dxnn
    labelmap_path: /config/model_cache/squirrel-only-labelmap.txt
    devices:
      - deepx:PCIe:0

cameras:
  garden:
    ffmpeg:
      inputs:
        - path: rtsp://[STREAM_HOST]:8554/[STREAM_PATH]
          roles:
            - detect
            - record
    detect:
      enabled: true
      width: 1280
      height: 720
      scene: outdoor
    objects:
      track:
        - Squirrel
      filters:
        Squirrel:
          min_score: 0.35
          threshold: 0.5

The scene: outdoor value ties the garden camera to this model, so another project’s camera keeps its own model in the same Frigate instance.

Listener rules

The listener runs as squirrel-sprinkler-automation.service. Its rules are defined at the top of automation/sprinkler.py:

SettingValue
Topicfrigate/events
Label filterSquirrel
Event typeOnly the first new event for each event ID
Minimum score0.6, read from top_score, falling back to score
Cooldown30 s per camera
BrokerBROKER and PORT constants (port 1883)

Relay or valve control goes in the trigger_sprinkler() function of automation/sprinkler.py. The function only publishes the trigger and logs a line; its comment suggests driving a relay pin with GPIO or sending a request to a relay HAT’s REST or MQTT interface. After editing it, run ./install.sh again.

Limitations

  • No relay or valve is connected. The listener publishes and logs each trigger. Valve control is not part of this build, and the valve host (the Raspberry Pi 5, another edge computer or a microcontroller) is undecided. The page gives no wiring, voltages or part numbers because no valve has been tested. Once you add a valve, keep the spray away from paths, doors and neighbors’ property, and check your local water-use rules before you automate a sprinkler.
  • No motion-activated sprinkler was tested, so the page makes no comparison with one.
  • Nothing is measured for the shipped model: no confidence scores across a test set, accuracy, false-positive rates under real lighting, angles and backgrounds, inference time or skipped frames. Figure 1 and the trigger in Verify are single frames (92% and 0.89), not a measurement. Test with your own camera before you rely on it.
  • No night, low-light or rain results exist.
  • Training a custom model is not covered.
  • The listener ignores events with a score below 0.6, while the Frigate filter tracks squirrels from 0.35. Detections between those values may appear in Frigate without a trigger.
  • The installer fixes the listener folder at ~/sixfab-apps/squirrel-sprinkler and overwrites the installed copy on every run, so edits made directly to ~/sixfab-apps/squirrel-sprinkler/sprinkler.py are lost. Edit automation/sprinkler.py in the repository and run ./install.sh again.
  • The listener connects to the broker on port 1883 without credentials or TLS, so any device that can publish to the broker can send it a fake frigate/events message.
  • Frigate chooses the DX-RT version its DEEPX detector uses. The tested build pins DX-RT v3.4.0, and this project cannot change it.
  • Frigate ran in Docker. Home Assistant OS and the Frigate add-on were not tested.

Privacy

A garden camera can record people. Aim the camera at your own garden, away from neighbors’ windows and public sidewalks. The garden camera input carries the detect and record roles; if recording is enabled in your Frigate config, Frigate stores recordings in [FRIGATE_MEDIA_DIR] under its own retention settings.

Detection runs locally on the Raspberry Pi 5. Frigate downloads the DX-RT Python bindings once at first start, and again when a release pins a new version, so the first start needs internet access.

Troubleshooting

The listener sends a trigger only for an event that passes its rules: see Listener rules. Check that the service is active (running):

systemctl --user status squirrel-sprinkler-automation.service -l

Raise min_score and threshold for Squirrel in Detection settings; the listener adds its own minimum score of 0.6. If that is not enough, train a custom model.

Run sudo loginctl enable-linger $USER once.

Restart the Frigate container with docker restart frigate. The Frigate setup page’s Troubleshooting covers this failure.

Stage 1 of the installer probes the RTSP URL you passed. Start your stream or correct the URL, then run the installer again.

Start Frigate first, or pass --container with your container name (CONTAINER when you run install.sh directly).

Next steps

License and credits

  • Frigate: Frigate NVR, the open-source NVR this project runs in.
  • Model: squirrel-detector-model.dxnn is built on Ultralytics YOLOv8m and licensed under AGPL-3.0. It was trained on two Roboflow datasets under CC BY 4.0. Details are in the squirrel-sprinkler-v1.0.0 release notes.
  • Code: MIT License.