Frigate » Forward events and snapshots to ntfy#

About#

This tutorial presents a notification pipeline, which implements forwarding Frigate events to ntfy notifications, using mqttwarn. It looks like this:

Frigate -> Mosquitto -> mqttwarn -> ntfy

Components#

Frigate (Frigate on GitHub) is a network video recorder (NVR) with realtime local object detection for IP cameras. It uses MQTT to publish events in JSON format and camera pictures in JPEG format.

Eclipse Mosquitto (Mosquitto on GitHub) is an open source message broker that implements the MQTT protocol versions 5.0, 3.1.1 and 3.1. Mosquitto is lightweight and is suitable for use on all devices from low power single board computers to full servers.

mqttwarn (mqttwarn on GitHub) is a highly configurable MQTT message router, where the routing targets are notification plugins, written in Python. mqttwarn has a corresponding notification plugin adapter for ntfy.

ntfy (ntfy on GitHub) is a simple HTTP-based pub-sub notification service, allowing you to send notifications to your phone or desktop from any computer, entirely without signup, cost or setup.

Synopsis#

  1. Publish Frigate sample events.

cat assets/frigate-event-new-good.json | jq -c | mosquitto_pub -t 'frigate/events' -l
mosquitto_pub -f goat.png -t 'frigate/cam-testdrive/goat/snapshot'
  1. Enjoy the outcome.

https://user-images.githubusercontent.com/453543/233172276-6a59cefa-6461-48bc-80f2-c355b6acc496.png

Usage#

Configuration#

Please inspect the frigate.ini mqttwarn configuration file and adjust it to your needs before running mqttwarn on it. If you also want to inspect the corresponding user-defined functions, you are most welcome. They are stored within frigate.py.

Prerequisites#

Acquire sources and go to the right directory:

git clone https://github.com/mqtt-tools/mqttwarn
cd mqttwarn/examples/frigate

In a box#

Start the Mosquitto MQTT broker and the ntfy service:

docker compose up

Subscribe to ntfy topic by visiting http://localhost:5555/frigate-testdrive.

Run mqttwarn:

MQTTWARNINI=frigate.ini mqttwarn

Run the example publisher program:

./publish.sh

Manually#

Publish a few example events individually:

cat assets/frigate-event-new-good.json | jq -c | mosquitto_pub -t 'frigate/events' -l
cat assets/frigate-event-end.json | jq -c | mosquitto_pub -t 'frigate/events' -l
cat assets/frigate-event-false-positive.json | jq -c | mosquitto_pub -t 'frigate/events' -l

Publish an example image:

wget -O goat.png https://user-images.githubusercontent.com/453543/231550862-5a64ac7c-bdfa-4509-86b8-b1a770899647.png
mosquitto_pub -f goat.png -t 'frigate/cam-testdrive/goat/snapshot'
open /tmp/mqttwarn-frigate-cam-testdrive-goat.png

Details#

The implementation is based on mqttwarn core, its ntfy service plugin, the mqttwarn configuration file frigate.ini, as well as the user-defined function file frigate.py. You can inspect them below.

Tests#

The test_frigate.py file covers different code paths by running a few Frigate event message samples through the machinery, and inspecting their outcomes. You can invoke the test cases either as part of the complete test suite, or by running them from this directory:

pytest --no-cov -k frigate
pytest --no-cov test_frigate.py

Attributions#

Acknowledgements#

Content#

The copyright of data, particular images, and pictograms, are held by their respective owners, unless otherwise noted.

Example snapshot image#