Expose all events from an Amcrest device to an MQTT broker
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
Go to file
Jeff Culverhouse ebe8d04332 feat: add automatic cleanup of old media recordings
Add configurable retention period for saved clips (default: 7 days).
Recordings older than the retention period are automatically deleted
once per day. Dangling symlinks are also cleaned up when their target
files are removed.

Configure via `media.retention_days` in config.yaml or
`MEDIA_RETENTION_DAYS` environment variable. Set to 0 to disable.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 month ago
.github chore: more python support; build tests 3 months ago
src feat: add automatic cleanup of old media recordings 1 month ago
tools chore: add clear.sh tool for clearing retained messages in MQTT broker 3 months ago
.dockerignore feat!: complete MQTT and service refactor, add timestamp + event tracking, and new modular mixins 3 months ago
.gitignore chore: add clear.sh tool for clearing retained messages in MQTT broker 3 months ago
.releaserc chore: skip invalid PR references 4 months ago
.trivyignore chore: minor fixes 3 months ago
CHANGELOG.md chore(release): 2.3.3 [skip ci] 2 months ago
Dockerfile refactor: Dockerfile updates 3 months ago
LICENSE Initial commit 5 years ago
README.md chore: update README.md 3 months ago
VERSION chore: update VERSION to v2.3.3 2 months ago
config.yaml.sample feat: add automatic cleanup of old media recordings 1 month ago
docker-compose.yaml chore: no need for timezone in config, just set in ENV; update sample files and README 3 months ago
package-lock.json chore: needed to add dev-deps 4 months ago
package.json chore: needed to add dev-deps 4 months ago
pyproject.toml chore: more python support; build tests 3 months ago
requirements.txt add support for config.yaml; sample config; revamp config 12 months ago
uv.lock refactor: upgrade packages 2 months ago

README.md

weirdtangent/amcrest2mqtt

Expose multiple Amcrest cameras and events to an MQTT broker, primarily designed to work with Home Assistant. Also exposes a webrtc link, if you have one, so a live feed can be viewed from within Home Assistant (on a dashboard, not on the entity page for the camera)

Uses the python-amcrest library. Forked from dchesterton/amcrest2mqtt

Docker

For docker-compose, use the configuration included in this repository.

Using the docker image, mount your configuration volume at /config (and see the included config.yaml.sample file to include in there as config.yaml) or use the ENV variables if you must. You can also mount a media volume at /media and motion recordings (up to a max size you specify) will be stored there to fill up your disk space!

It supports the following environment variables - but these are a pain, the config file is easier!

  • AMCREST_HOSTS (required, 1+ space-separated list of hostnames/ips)

  • AMCREST_NAMES (required, 1+ space-separated list of device names - must match count of AMCREST_HOSTS)

  • AMCREST_PORT (optional, default = 80)

  • AMCREST_USERNAME (optional, default = admin)

  • AMCREST_PASSWORD (required)

  • AMCREST_WEBRTC_HOST (optional, webrtc hostname for link, but then link/sources below become required:)

  • AMCREST_WEBRTC_PORT (webrtc port, default = 1984)

  • AMCREST_WEBRTC_LINK (webrtc stream link, default = 'stream.html')

  • AMCREST_WEBRTC_SOURCES (webrtc "Source" param for each camera, same count and order of AMCREST_HOSTS above)

  • MQTT_USERNAME (required)

  • MQTT_PASSWORD (optional, default = empty password)

  • MQTT_HOST (optional, default = 'localhost')

  • MQTT_QOS (optional, default = 0)

  • MQTT_PORT (optional, default = 1883)

  • MQTT_TLS_ENABLED (required if using TLS) - set to true to enable

  • MQTT_TLS_CA_CERT (required if using TLS) - path to the ca certs

  • MQTT_TLS_CERT (required if using TLS) - path to the private cert

  • MQTT_TLS_KEY (required if using TLS) - path to the private key

  • MQTT_PREFIX (optional, default = amgrest2mqtt)

  • MQTT_DISCOVERY_PREFIX (optional, default = 'homeassistant')

  • MEDIA_PATH (optional) - path to store motion recordings (mp4) files

  • MEDIA_SOURCE (optional) - HomeAssistant url for accessing those recordings (see config.yaml.sample)

  • STORAGE_UPDATE_INTERVAL (optional, default = 900) - how often to fetch storage stats (in seconds)

  • SNAPSHOT_UPDATE_INTERVAL (optional, default = 60) - how often to fetch camera snapshot (in seconds)

It exposes through the new 2024 HomeAssistant device discovery a service plus a camera with multiple components for each camera you specify:

  • homeassistant/device/amcrest2mqtt_service - service config
  • homeassistant/device/amcrest2mqtt_[SERIAL_NUMBER] per camera, with components:

Snapshots/Eventshots plus Home Assistant Area Cards

The camera snapshots work really well for the HomeAssistant Area cards on a dashboard - just make this MQTT camera device is the only camera for an area and place an Area card for that location on a dashboard.

An "event snapshot" (eventshot) is separately (and specifically, by filename) collected IF the camera automatically records a snapshot because of an event. Note, that if the Amcrest camera is configured to record 3 or 5 snapshots on an event - each of those may be seen and updated by amcrest2mqtt and you will very quickly end up with the last snapshot.

WebRTC

The WebRTC option works with the go2rtc package which is a streaming server that works very well for (my) Amcrest cameras. If you setup the WebRTC config here, there will be a camera.<name> webrtc which you can put on a dashboard with the entity card. It will show a small camera icon and likely say "Idle", but if you click on it (and give it a little time to warm up) you will see the live-streaming feed from the webrtc server.

Device Support

The app supports events for any Amcrest device supported by python-amcrest.

Running the app

To run via env variables with Docker Compose, see docker-compose.yaml or make sure you attach a volume with the config file and point to that directory, for example:

CMD [ "python", "-m", "amcrest2mqtt", "-c", "/config" ]

Healthcheck

There is a simple healthcheck that can be run, as seen in the sample docker-compose. The app simply touches a file in /tmp every 60 seconds, so while the app is functional, that file should keep getting hit. /app/src/healthcheck.py will check that and return true or false.

Mounted Volume Permissions (Synology)

If you mount a host folder into /media for saving recordings, ensure the container has write access. On Synology NAS, shared folders use ACLs that can block Docker containers even when chmod 777 appears open.

To reset permissions and make the volume writable by the containers default user (uid=1000, gid=1000), run the following via SSH (alter for your path):

sudo synoacltool -del /volume1/photo/Amcrest
sudo chmod 777 /volume1/photo/Amcrest
sudo chown 1000:1000 /volume1/photo/Amcrest

Then verify inside the container:

docker exec -it amcrest2mqtt ls -ld /media

You should see permissions like:

drwxrwxrwx 1 appuser appuser ... /media

Once configured correctly, you should see new recordings appear in your mounted folder with ownership 1000:1000 and a symlink to the latest file.

Also, make sure you have

environment:
  - TZ=America/New_York

in your docker-compose if you want the recording filenames to by local time and not UTC.

Out of Scope

Non-Docker Environments

Docker is the only supported way of deploying the application. The app should run directly via Python but this is not supported.

See also

Buy Me A Coffee

Buy Me A Coffee


Build & Quality Status

Build & Release Lint Docker Build Python Release Docker Image Version Docker Pulls License