A Python application that connects to ZKTeco access control devices (C3-series) and publishes their events to MQTT, with built-in Home Assistant integration through MQTT Discovery.
- 🔌 Connects to ZKTeco C3-series access control devices
- 📊 Publishes device events to MQTT
- 🏠 Home Assistant auto-discovery for easy integration
- 🚪 Monitor doors, relays, aux inputs, card readers
- 🔄 Configurable polling interval
- 🌐 Timezone support for event timestamps
- Python 3.10+
- MQTT Broker (like Mosquitto)
- ZKTeco access control system
services:
zktaccess:
image: valentas/zkteco-mqtt-gateway:latest
platform: linux/amd64
container_name: zktaccess
environment:
- DEVICE_IP=192.168.1.201
- DEVICE_PORT=4370
# - DEVICE_PASSWORD=
# - MQTT_BROKER_HOST=localhost
# - MQTT_BROKER_PORT=1883
# - MQTT_USERNAME=
# - MQTT_PASSWORD=
# - MQTT_CLIENT_ID=
# - POLLING_INTERVAL_SECONDS=60
# - LOG_LEVEL=INFO
# - TIME_ZONE=UTC
# - HA_DISCOVERY_PREFIX=homeassistant
# - HA_DEVICE_IDENTIFIER=
# - HA_DEVICE_NAME=
# - HA_DEVICE_MANUFACTURER=ZKTeco
# - HA_DEVICE_SW_VERSION=zk_mqtt_bridge_1.0
docker compose up
- Clone this repository
- Copy
dist.env
to.env
and configure your settings - Build and run with Docker Compose:
docker compose up --build
All configuration is done through environment variables, which can be set in the .env
file or passed as environment variables to the container. Below is a description of all available configuration options:
Variable | Description | Default |
---|---|---|
DEVICE_IP |
(Required) IP Address of your ZKAccess controller | - |
DEVICE_PORT |
Port for the ZKAccess device | 4370 |
DEVICE_PASSWORD |
Communication Password (if set) | empty |
DEVICE_MODEL |
Device Model - Defaults to C3 if unset or invalid. | C3 |
Variable | Description | Default |
---|---|---|
MQTT_BROKER_HOST |
(Required) Address/Hostname of MQTT broker | localhost |
MQTT_BROKER_PORT |
Port for your MQTT broker | 1883 |
MQTT_USERNAME |
MQTT Username (if auth required) | empty |
MQTT_PASSWORD |
MQTT Password (if auth required) | empty |
MQTT_CLIENT_ID |
Custom client ID for this instance | auto-generated |
Variable | Description | Default |
---|---|---|
POLLING_INTERVAL_SECONDS |
How often to poll the device for events (seconds) | 60 |
LOG_LEVEL |
Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL) | INFO |
TIME_ZONE |
Timezone for event timestamps (IANA format) | UTC |
Variable | Description | Default |
---|---|---|
HA_DISCOVERY_PREFIX |
Home Assistant MQTT Discovery prefix | homeassistant |
HA_DEVICE_IDENTIFIER |
Custom device identifier | zkt_[serial_number] |
HA_DEVICE_NAME |
Custom device name in Home Assistant | ZKTeco [MODEL] Controller |
HA_DEVICE_MANUFACTURER |
Manufacturer name in Home Assistant | ZKTeco |
HA_DEVICE_SW_VERSION |
Software version in Home Assistant | zkt_mqtt_bridge_1.0 |
The bridge automatically creates the following entities in Home Assistant via MQTT Discovery:
- Door Sensors (
binary_sensor
): Status of each door (open/closed) - Auxiliary Inputs (
binary_sensor
): Status of each auxiliary input - Reader Events (
event
): Card scan events at each reader - Reader Cards (
sensor
): Last card number scanned at each reader - Relays (
binary_sensor
): Status of each relay
All entities are grouped under a single device for easy management and automations.
All MQTT messages use the following topic structure:
zkt_eco/[MODEL_NAME]/[SERIAL_NUMBER]/[ENTITY]/state
Where:
- MODEL_NAME: The configured device model (default: "C3")
- SERIAL_NUMBER: The device's serial number
- ENTITY: Entity type and ID (e.g., door_1, reader_2_card)
docker compose run --rm zktaccess pytest
The project supports two build modes:
-
Development build - Includes testing dependencies (default for docker-compose)
# Using docker-compose (automatically includes dev dependencies) docker compose build # Using Docker directly with dev dependencies docker build --build-arg INSTALL_DEV=true -t zktaccess .
-
Production build - Minimal footprint without dev dependencies
# Default Docker build excludes dev dependencies docker build -t zktaccess .
- Ensure the ZKAccess device is powered on and accessible on the network
- Verify the IP address, port, and password are correct
- Check firewall settings to ensure port 4370 TCP is open
- Set
LOG_LEVEL=DEBUG
for more detailed logs
- Verify your MQTT broker is running and accessible
- Check username/password if authentication is enabled
- Ensure there are no topic conflicts with other devices
This project is licensed under the MIT License - see the LICENSE file for details.
- Built using the zkaccess-c3 library for ZKTeco C3-series device communication
- Inspired by other ZKTeco integration projects