ANPR MQTT bridge for Home Assistant
Project description
{ align=left }
anpr2mqtt
ANPR MQTT Bridge
A simple way to integrate CCTV cameras with built-in ANPR (Automatic Number Plate Recognition, aka ALPR or Automatic License Plate Recognition) to MQTT for Home Assistant integration, or any other MQTT consumer. Running under Docker is preferred but not necessary.
All that is needed is for the camera to be configured to upload images on plate recognition, by ftp, NAS or whatever else. ANPR2MQTT monitors the directory where the images lands and publishes plate information to MQTT. Its simple, requires no proprietary vendor APIs ( or differing ONVIF implementations ), and Home Assistant gets a copy of the actual annotated detection image to use on dashboards or to attach to notifications.
While intended for vehicle plate detection, it can be used to watch for and analyze any file, so for example uploaded face detection or line crossing images. A single anpr2mqtt instance can watch multiple paths and patterns for different cameras and events.
Features
- Minimal configuration
- Ready configured to work with popular Hikvision ANPR camera settings
- File System Integration
- Home Assistant Integration.
- Publishes events to MQTT for Home Assistant as a MQTT Sensor Entity
- Auto-discovery configuration for Home Assistant
- Creates MQTT Image Entity on Home Assistant for image snapshot, so no web access to ftp needed
- Optionally also creates an MQTT Camera Entity
- Plate Enrichment
- OCR-based extraction of fields using tesseract-ocr
- By default direction detection (Forward/Reverse)
- Corrections by regular expression to fix OCR mis-readings
- Tracks and counts previous sightings
- Configurable to classify plates as known, to be ignored or as a potential threat
- Regular expression based corrections, for known plates that the ANPR sometimes mis-reads
- Fuzzy match corrections for known plates, based on Levenshtein algorithm
- UK Only
- DVLA Lookup if API_KEY provided, for detailed MOT and tax information
- Lookups cached for configurable time
- OCR-based extraction of fields using tesseract-ocr
- Auto clear vehicle state optionally, after configurable time
- Debug Tools built-in
Docker Deployment
Build and run with Docker, example docker-compose.yaml provided.
Configuration
ANPR2MQTT uses pydantic-settings, which means configuration can happen in a variety of ways, and these can be combined - yaml configuration file, environment variables, Docker Secrets, built-in defaults, and .env file or command line arguments.
CLI Arguments
Every configuration setting can be passed as a command line argument, using dot notation for nested settings. This is the highest-priority source and overrides all other configuration.
uv run --with anpr2mqtt anpr2mqtt --mqtt.host 192.168.1.10 --mqtt.port 1884 --log_level DEBUG
Run uv run --with anpr2mqtt anpr2mqtt --help to see all available flags, and find more information at Debug Tools
Home Assistant Integration
See Home Assistant Integration for configuration and example notification automation.
Environment Variables
pydantic-settings needs double underscores for
environment variables in config sections. For example, MQTT__HOST means set the value host in the mqtt config section.
| Env Variable | Description | Default |
|---|---|---|
MQTT__HOST |
MQTT broker hostname | localhost |
MQTT__PORT |
MQTT broker port | 1883 |
MQTT__TOPIC_ROOT |
MQTT topic for events | anpr2mqtt |
MQTT__USER |
MQTT username | - |
MQTT__PASS |
MQTT password | - |
LOG_LEVEL |
Python logging level | INFO |
DVLA__API_KEY |
API Key for Gov API Lookup | - |
Image Filename Format
Expected format: YYYYMMDDHHMMSSmmm_PLATE_VEHICLE_DETECTION.jpg
Example: 20180502174029596_A2GEO_VEHICLE_DETECTION.jpg
A regular expression can be defined to match different file name formats.
Image Box Coordinates
Where cameras provide an estimated direction for the vehicle, this can be captured via OCR and included in the response. See OCR for an explanation and examples.
Auto Clear
By default, the state will be reset back to unavailable 5 minutes after a detection, while the image will
be left present as record of last known vehicle. This behavior can be changed ( to switch off auto clear,
or change the time lag, or also clear image ) using the autoclear configuration for each event.
- camera: shed
watch_path: /ftp/shedcam
autoclear:
post_event: 360
state: True
image: False
Corrections
The licence plate detection may mis-read or miss some of the characters of the plate. When the result is published to MQTT, both the raw original and corrected versions are provided.
Two mechanisms help with this:
Fuzzy Matching
The Levenshtein method is used to compare the plate against a list of known friendly or dangerous
plates in the configuration, subject to a maximum distance tolerance ( number of mismatched characters )
defined by auto_match_tolerance. If its a match for more than one, the plate with least distance is chosen.
Regex / String Matching
Each known plate can be associated with a list of regular expressions and/or plain strings, and these will be checked for every discovered licence plate.
Primary Dependencies
- watchdog - File system monitoring (cross-platform)
- paho-mqtt - MQTT client
- Pillow - Image processing
- pytesseract - OCR for direction detection
- structlog - Structured logging
- niquests - API Client
- requests-cache - API result caching
Distribution
ANPR2MQTT is free and open sourced under the Apache 2.0 license.
Rhizomatics Open Source for Home Assistant
HACS
- AutoArm - Automatically arm and disarm Home Assistant alarm control panels using physical buttons, presence, calendars, sun and more
- Remote Logger - OpenTelemetry (OTLP) and Syslog event capture for Home Assistant
- Supernotify - Unified notification for easy multi-channel messaging, including powerful chime and security camera integration.
Python / Docker
- Updates2MQTT - Automatically notify via MQTT on Docker image updates, with advanced handling to extract versions and release notes from images, and option to remotely pull and restart containers from Home Assistant. Also available on PyPI
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file anpr2mqtt-0.10.2.tar.gz.
File metadata
- Download URL: anpr2mqtt-0.10.2.tar.gz
- Upload date:
- Size: 20.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cabacc984807bd872bbbf0e4f7c9ba59e60b50f4727444f2836c27f42c8dd4f5
|
|
| MD5 |
6b6d4d855e1faa680fffa8d2bf7daceb
|
|
| BLAKE2b-256 |
295fd4e527f97c8ed882693115461f50b376dd9f90e786c40badd3632d3f140e
|
Provenance
The following attestation bundles were made for anpr2mqtt-0.10.2.tar.gz:
Publisher:
pypi-publish.yml on rhizomatics/anpr2mqtt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
anpr2mqtt-0.10.2.tar.gz -
Subject digest:
cabacc984807bd872bbbf0e4f7c9ba59e60b50f4727444f2836c27f42c8dd4f5 - Sigstore transparency entry: 1293660665
- Sigstore integration time:
-
Permalink:
rhizomatics/anpr2mqtt@55f59346ed9343f3b16d8aab49509c3931a0666f -
Branch / Tag:
refs/tags/v0.10.2 - Owner: https://github.com/rhizomatics
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@55f59346ed9343f3b16d8aab49509c3931a0666f -
Trigger Event:
release
-
Statement type:
File details
Details for the file anpr2mqtt-0.10.2-py3-none-any.whl.
File metadata
- Download URL: anpr2mqtt-0.10.2-py3-none-any.whl
- Upload date:
- Size: 22.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e72b6a4b63cc05bb6c948c5718bc75862c49bff33f7cb5f973c08f378bae9eb
|
|
| MD5 |
cba14558d2f92debb4952ca72f8a5fad
|
|
| BLAKE2b-256 |
332e0d8bbc75f781427871d1ec0ceeebbf2958ec69461150cee45cb109a981d8
|
Provenance
The following attestation bundles were made for anpr2mqtt-0.10.2-py3-none-any.whl:
Publisher:
pypi-publish.yml on rhizomatics/anpr2mqtt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
anpr2mqtt-0.10.2-py3-none-any.whl -
Subject digest:
2e72b6a4b63cc05bb6c948c5718bc75862c49bff33f7cb5f973c08f378bae9eb - Sigstore transparency entry: 1293660670
- Sigstore integration time:
-
Permalink:
rhizomatics/anpr2mqtt@55f59346ed9343f3b16d8aab49509c3931a0666f -
Branch / Tag:
refs/tags/v0.10.2 - Owner: https://github.com/rhizomatics
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@55f59346ed9343f3b16d8aab49509c3931a0666f -
Trigger Event:
release
-
Statement type: