Dahua VTO to MQTT Broker

I found a solution:

I read it in the past, it basically means that we need to have a proxy server for push notifications to catch the message and forward it later,
I’m looking for bit less aggressive approach

Maybe create a plugin that will work as a SIP client?
For example, dahua VTO has own SIP server that can make group calls, for example 9901#1 and 9902#2. I tried to use sip-to-mqtt, but it doesn’t support phone numbers with #.

1 Like

I read more about it in that forum and found a PHP script, added to the script MQTT capabilities and now we have DahuaVTO2MQTT script, will wrap it up into docker, hope that we will have it ready soon

1 Like

I’ve found something else: https://github.com/denimjeans/DahuaVTO-Gong

it looks like it is listening to the Multicast packets the VTO is sending around which should occur realtime

as I’m not at home I didn’t test it yet.

(afaik this kind of communication is still in use with the SIP firmware as a second VTH at another location don’t receive videostream but only audiostream when being ringed)

I guess you have found this script: https://github.com/riogrande75/Dahua/blob/fc997f16f98d459f407737fe4a4f8cfb5aa28900/DahuaEventHandler.php is that right?
it seems to use the Internal API

I use the Dahua Event Hanlder, already wrapped it with container, added MQTT and set all configuration’s parameters from ENV variables.

STill checking, hopefully by end of the day it will be ready

Please let me know how it works for you:

DahuaVTO2MQTT

Description

Listens to events from Dahua VTO unit and publishes them via MQTT Message

Credits

All credits goes to @riogrande75 who wrote that complicated integration Original code can be found in @riogrande75/Dahua

Change-log

2020-Feb-03 - Initial version combing the event listener with MQTT

Environment Variables

DAHUA_VTO_HOST: 		Dahua VTO hostname or IP
DAHUA_VTO_USERNAME: 	Dahua VTO username to access (should be admin)
DAHUA_VTO_PASSWORD: 	Dahua VTO administrator password (same as accessing web management)
MQTT_BROKER_HOST: 		MQTT Broker hostname or IP
MQTT_BROKER_PORT: 		MQTT Broker port, default=1883
MQTT_BROKER_USERNAME: 	MQTT Broker username
MQTT_BROKER_PASSWORD: 	MQTT Broker password
MQTT_BROKER_TOPIC: 		Topic to publish all events, default=DahuaVTO/Events

Run manually

Requirements:

  • All environment variables above
  • PHP
php -f DahuaEventHandler.php

Docker Compose

version: '2'
services:
  dahuavto2mqtt:
    image: "eladbar/dahuavto2mqtt:latest"
    container_name: "dahuavto2mqtt"
    hostname: "dahuavto2mqtt"
    restart: always
    environment:
      - DAHUA_VTO_HOST=vto-host
      - DAHUA_VTO_USERNAME=Username
      - DAHUA_VTO_PASSWORD=Password
      - MQTT_BROKER_HOST=mqtt-host
      - MQTT_BROKER_PORT=1883
      - MQTT_BROKER_USERNAME=Username
      - MQTT_BROKER_PASSWORD=Password
      - MQTT_BROKER_TOPIC=DahuaVTO/Events	  

MQTT Message (Dahua VTO Event Payload)

Message with more than one event can take place by subscription, By default each message should be with one event in the list.

Events (With dedicated additional data)

CallNoAnswered: Call from VTO
IgnoreInvite: VTH answered call from VTO
VideoMotion: Video motion detected
RtspSessionDisconnect: Rtsp-Session connection connection state changed
BackKeyLight: BackKeyLight with State
TimeChange: Time changed
NTPAdjustTime: NTP Adjusted time
KeepLightOn: Keep light state changed
VideoBlind: Video got blind state changed
FingerPrintCheck: Finger print check status
SIPRegisterResult: SIP Device registration status
AccessControl: Someone opened the door
CallSnap: Call
Invite - Invite for a call (calling)
AccessSnap: ?
RequestCallState: 
PassiveHungup: Call was dropped
ProfileAlarmTransmit: Alarm triggered
1 Like

I get this mistake in docker

Unknown event received
Published message{"id":2,"method":"client.notifyEventStream","params":{"SID":513,"eventList":[{"Action":"Start","Code":"APConnect","Data":{"LocaleTime":"2020-03-02 19:19:57","Type":"Timerconnect","UTC":1583158797},"Index":0}]},"session":2147447600}

And in Mqtt

{"id":2,"method":"client.notifyEventStream","params":{"SID":513,"eventList":[{"Action":"Stop","Code":"APConnect","Data":{"Error":"SSIDNotValid","LocaleTime":"2020-03-02 19:20:07","Result":false,"Type":"Timerconnect","UTC":1583158807},"Index":0}]},"session":2147447600}

Unknown event means it’s unmapped, will add those 2 events to the list

Updated a bit the script, now it will publish a single event with topic DahuaVTO/[Event Name]/Event
Added also some unmapped events

I am fairly new with docker (never used, and started using HA on a Pi3 since last week) so I am a bit confused how to start

The docker file in the Repository differs from the one in the manual, which one should be used ?

hello, I have a vto3221D and I’m interested in this component, I added the custom component of the first post and the opening works and all the info.
however, when the bell rings, the sensor is always off.

how can I install the mqtt version? I didn’t understand how to do it

i also have 3 VTH and
I ordered another VTO3221 which is coming soon and I will add it to the system soon

To run docker please read the following documentation:

I personally use Portainer to manage my docker environment, but you can do it from CLI using the following steps:

EXPORT DAHUA_VTO_HOST=vto-host
EXPORT DAHUA_VTO_USERNAME=Username
EXPORT DAHUA_VTO_PASSWORD=Password
EXPORT MQTT_BROKER_HOST=mqtt-host
EXPORT MQTT_BROKER_PORT=1883
EXPORT MQTT_BROKER_USERNAME=Username
EXPORT MQTT_BROKER_PASSWORD=Password  

docker run -e DAHUA_VTO_HOST \
                  -e DAHUA_VTO_USERNAME \
                  -e DAHUA_VTO_PASSWORD \
                  -e MQTT_BROKER_HOST \
                  -e MQTT_BROKER_PORT \
                  -e MQTT_BROKER_USERNAME \
                  -e MQTT_BROKER_PASSWORD \
                  --rm eladbar/dahuavto2mqtt

alternative way is to clone the repo to your machine and run the script from there,
to do that you need:

  1. Clone repository
git clone https://github.com/elad-bar/Dahua.git ~/Dahua
cd ~/Dahua
  1. Install PHP
sudo apt install php libapache2-mod-php
  1. Set environment variables
EXPORT DAHUA_VTO_HOST=vto-host
EXPORT DAHUA_VTO_USERNAME=Username
EXPORT DAHUA_VTO_PASSWORD=Password
EXPORT MQTT_BROKER_HOST=mqtt-host
EXPORT MQTT_BROKER_PORT=1883
EXPORT MQTT_BROKER_USERNAME=Username
EXPORT MQTT_BROKER_PASSWORD=Password 
  1. Run script
php -f DahuaEventHandler.php

Please note that with that approach you will need to create a service to run it on every startup

that’s the main reason why I switched to the MQTT approach, I’m going to write in the OP that the component is deprected and the new approach is the MQTT.

2 options as in previous post:

  1. docker - preferable
  2. manual script invocation

Well, I tested DahuaVTO2MQTT. So, it works very well! Thank you!

My example of integration to get a photo from Dahua VTO to Telegram using DahuaVTO2MQTT.

configuration.yaml:

sensor:
  - platform: mqtt
    name: "DahuaVTO Event"
    state_topic: "DahuaVTO/CallNoAnswered/Event"
    value_template: "{{ value_json.Action }}"

automations.yaml:

- id: '1111111111111'
  alias: VTO Photo to Telegram
  trigger:
  - entity_id: sensor.dahuavto_event
    platform: state
    to: Start
  condition: []
  action:
  - data:
      authentication: digest
      caption: Ding-Dong!
      password: MYPASSWORD
      timeout: '1000'
      url: http://192.168.1.120/cgi-bin/snapshot.cgi?channel=1.jpg
      username: admin
    service: telegram_bot.send_photo
  - delay: 00:00:05
  - data:
      payload: '{"Action":"Stop"}'
      qos: 2
      topic: DahuaVTO/CallNoAnswered/Event
    service: mqtt.publish
4 Likes

Invite event is being sent once, it will be easier than checking for the action and publishing stop event

thanks for the replies.
I use hass.io and I can’t follow the doker procedure.
I noticed that there is the portainer.io component, I tried to install it and clone the git repository but I think I am missing several steps.
this is what i did:

  1. in ‘home’ I selected ‘primary’
  2. in ‘stacks’ add stacks
  3. created new stack:
    name: dahua
    webeditor:

version: ‘2’
services:
dahuavto2mqtt:
image: “eladbar / dahuavto2mqtt: latest”
container_name: “dahuavto2mqtt”
hostname: “dahuavto2mqtt”
restart: always
environment:
- DAHUA_VTO_HOST = vto-host
- DAHUA_VTO_USERNAME = Username
- DAHUA_VTO_PASSWORD = Password
- MQTT_BROKER_HOST = mqtt-host
- MQTT_BROKER_PORT = 1883
- MQTT_BROKER_USERNAME = Username
- MQTT_BROKER_PASSWORD = Password

URL repository: https://github.com/elad-bar/Dahua.git

Environment variables

DAHUA_VTO_HOST: Dahua VTO hostname or IP
DAHUA_VTO_USERNAME: Dahua VTO username to access (should be admin)
DAHUA_VTO_PASSWORD: Dahua VTO administrator password (same as accessing web management)
MQTT_BROKER_HOST: 192.168xxx
MQTT_BROKER_PORT: 1883
MQTT_BROKER_USERNAME: xxxxx
MQTT_BROKER_PASSWORD: xxxxxx

and I clicked: daploy the stack.

if I go to ‘Containers’
there is dahuavto2mqtt state ‘running’ but if I click on ‘log’ I get:

standard_init_linux.go: 211: exec user process caused “exec format error”
standard_init_linux.go: 211: exec user process caused “exec format error”

I know this goes off topic but can you tell me what other step to do? maybe I have to add something on the network? how can i manually run php -f DahuaEventHandler.php?

Seemsto be working like a charm.
Thanks for wrapping up the docker.
In the past I tried to setup the script but I was not so keen on @dirtyying@ the enviironment with yet another script.
docker was the way!

In portainer stack’s just copy the yaml, make sure it’s well indented and click on deploy, no need to redirect to the repo