Translate ONVIF events (from IP Cameras) to MQTT messages.
:warning: Unmaintained: Due to lack of time, this project is currently not maintained. We are searching for active contributors / maintainers. If interested, please message @dmitrif
This package aims to implement a transformation layer between the ONVIF event stream (sourced from IP cameras / camera doorbells) and MQTT (a messaging protocol largely used in home automation).
Any number of ONVIF devices is supported.
After acquiring an EzViz DB1 camera doorbell, I was happy to find a PIR sensor on it. I was then dismayed to find out that there is no open API to consume the triggered status of it. This project was written to scratch that itch, but it should work for any other ONVIF compliant devices with built-in sensors.
This is the recommended method of consumption for everyday users.
docker pull dfarkov/onvif2mqtt:latest
config.yml
)docker run -v PATH_TO_CONFIGURATION_FOLDER:/config dfarkov/onvif2mqtt
This method requires an installation of NodeJS / NPM. This is the recommended installation method for development purposes.
git clone https://github.com/dmitrif/onvif2mqtt
cd ./onvif2mqtt
npm install
touch config.dev.yml
# For development
npm run dev
# For production build
npm run build
CONFIG_FILE=./config.dev.yml npm run start
Configuration can be placed into a config.yml
file, containing valid YAML. This file should be placed into the host-mounted config volume; if another location is preferred then the file path can be provided as an environment variable CONFIG_PATH
.
By default this package publishes events to an topic onvif2mqtt/$ONVIF_DEVICE/$EVENT_TYPE/
with a value of on | off
for each captured event type.
However, by using the api.templates
option in configuration, one can define a custom subtopic
and specify a custom template. The following tokens will be interpolated in both the subtopic
and the template
values:
${onvifDeviceId}
- name of the ONVIF device (e.g. doorbell
)${eventType}
- type of event captured (e.g. motion
)${eventState}
- boolean state of the event (if applicable)The messages will be sent to a topic of the following format: onvif2mqtt/$ONVIF_DEVICE/$SUBTOPIC
.
api:
templates:
#Subtopics can be nested with `/` and are interpolated
- subtopic: ${eventType}/json
# Should this message be retained by MQTT
# Defaults to true
retain: false
# Template that should be published to the topic,
# values are interpolated
template: >-
{
"device": "${onvifDeviceId}",
"eventType": "${eventType}",
"state": "${eventState}"
}
# You can specify any number of custom subtopics.
- subtopic: hello_world
template: hello from ${onvifDeviceId}
# MQTT Broker configuration,
# required due to nature of project.
mqtt:
host: 192.168.0.57
port: 1883
username: user
password: password
clientId: clientId
# All of your ONVIF devices
onvif:
# Name for the device (used in MQTT topic)
- name: doorbell
hostname: localhost
port: 80
username: admin
password: admin
mqtt
...
api:
templates:
- subtopic: shinobi
retain: false
template: >-
{
"plug": "${onvifDeviceId}",
"reason": "${eventType}",
"name": "${onvifDeviceId}"
}
...
binary_sensor
in HomeAssistant's configuration.yaml
:binary_sensor doorbell_motion:
- platform: mqtt
name: doorbell_motion
state_topic: "onvif2mqtt/doorbell/motion"
Simplest way forward is to base your configuration off config.sample.yml
.
Thanks goes to these wonderful people (emoji key):
Michael Bogatyrev 💻 |
Dmitri Farkov 💻 📖 🚧 |
Domenico Casillo 💻 |
brilthor 💻 |
Brad Gilmer 📖 |
DJTim 📖 |
Roman 💻 |
This project follows the all-contributors specification. Contributions of any kind welcome!