Dahua VTO to MQTT Broker

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
3 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

i do this:



and i add this sensor in configuration.yaml

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

but I think some steps are still missing because nothing happens
in container log i have

standard_init_linux.go:211: exec user process caused "exec format error

I’m getting the same error

in portainer > Stacks I’ve added a new one (named it vto2111)

in webeditor i pasted this (passwords changed…):

version: '2'
services:
  dahuavto2mqtt:
    image: "eladbar/dahuavto2mqtt:latest"
    container_name: "dahuavto2mqtt"
    hostname: "dahuavto2mqtt"
    restart: always
    environment:
      - DAHUA_VTO_HOST=192.168.39.12
      - DAHUA_VTO_USERNAME=admin
      - DAHUA_VTO_PASSWORD=passwordofthedevice
      - MQTT_BROKER_HOST=localhost
      - MQTT_BROKER_PORT=1883
      - MQTT_BROKER_USERNAME=someuid
      - MQTT_BROKER_PASSWORD=somepwd
      - MQTT_BROKER_TOPIC=DahuaVTO/Events

after waiting a few minutes it’s deployed, when going to Containers > dahuavto2mqtt

logs says:

standard_init_linux.go:211: exec user process caused “exec format error”
standard_init_linux.go:211: exec user process caused “exec format error”
(above message repeated multiple times, and growing)

Inspect is telling me this

7dc3a8aae066f6cde8345ff886bfb29d58cc1071226156bf31810f9ca0f4dde2
AppArmorProfile docker-default
Args [ /bin/sh, -c, php -f /app/DahuaVTO.php ]
Config { AttachStderr: false, AttachStdin: false, AttachStdout: false, Cmd: /bin/sh,-c,php -f /app/DahuaVTO.php, Domainname: , Entrypoint: docker-php-entrypoint, Env: DAHUA_VTO_HOST=192.168.39.12,DAHUA_VTO_USERNAME=admin,DAHUA_VTO_PASSWORD=deblau55,MQTT_BROKER_HOST=localhost,MQTT_BROKER_PORT=1883,MQTT_BROKER_USERNAME=mqttuid,MQTT_BROKER_PASSWORD=mqttpwd,MQTT_BROKER_TOPIC=DahuaVTO/Events,PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin,PHPIZE_DEPS=autoconf dpkg-dev file g++ gcc libc-dev make pkg-config re2c,PHP_INI_DIR=/usr/local/etc/php,APACHE_CONFDIR=/etc/apache2,APACHE_ENVVARS=/etc/apache2/envvars,PHP_EXTRA_BUILD_DEPS=apache2-dev,PHP_EXTRA_CONFIGURE_ARGS=--with-apxs2,PHP_CFLAGS=-fstack-protector-strong -fpic -fpie -O2,PHP_CPPFLAGS=-fstack-protector-strong -fpic -fpie -O2,PHP_LDFLAGS=-Wl,-O1 -Wl,--hash-style=both -pie,GPG_KEYS=1729F83938DA44E27BA0F4D3DBDB397470D12172 B1B44D8F021E4E2D6021E995DC9FF8D3EE5AF27F,PHP_VERSION=7.2.2,PHP_URL=https://secure.php.net/get/php-7.2.2.tar.xz/from/this/mirror,PHP_ASC_URL=https://secure.php.net/get/php-7.2.2.tar.xz.asc/from/this/mirror,PHP_SHA256=47d7607d38a1d565fc43ea942c92229a7cd165f156737f210937e375b243cb11,PHP_MD5=, ExposedPorts: [object Object], Hostname: dahuavto2mqtt, Image: eladbar/dahuavto2mqtt:latest, Labels: [object Object], OnBuild: null, OpenStdin: false, StdinOnce: false, Tty: false, User: , Volumes: null, WorkingDir: /app }
Created 2020-03-05T21:18:43.153984926Z
Driver overlay2
ExecIDs
GraphDriver { Data: [object Object], Name: overlay2 }
HostConfig { AutoRemove: false, Binds: , BlkioDeviceReadBps: null, BlkioDeviceReadIOps: null, BlkioDeviceWriteBps: null, BlkioDeviceWriteIOps: null, BlkioWeight: 0, BlkioWeightDevice: null, CapAdd: null, CapDrop: null, Capabilities: null, Cgroup: , CgroupParent: , ConsoleSize: 0,0, ContainerIDFile: , CpuCount: 0, CpuPercent: 0, CpuPeriod: 0, CpuQuota: 0, CpuRealtimePeriod: 0, CpuRealtimeRuntime: 0, CpuShares: 0, CpusetCpus: , CpusetMems: , DeviceCgroupRules: null, DeviceRequests: null, Devices: , Dns: null, DnsOptions: null, DnsSearch: null, ExtraHosts: null, GroupAdd: null, IOMaximumBandwidth: 0, IOMaximumIOps: 0, IpcMode: shareable, Isolation: , KernelMemory: 0, KernelMemoryTCP: 0, Links: null, LogConfig: [object Object], MaskedPaths: /proc/asound,/proc/acpi,/proc/kcore,/proc/keys,/proc/latency_stats,/proc/timer_list,/proc/timer_stats,/proc/sched_debug,/proc/scsi,/sys/firmware, Memory: 0, MemoryReservation: 0, MemorySwap: 0, MemorySwappiness: 0, NanoCpus: 0, NetworkMode: vto2111_default, OomKillDisable: false, OomScoreAdj: 0, PidMode: , PidsLimit: null, PortBindings: [object Object], Privileged: false, PublishAllPorts: false, ReadonlyPaths: /proc/bus,/proc/fs,/proc/irq,/proc/sys,/proc/sysrq-trigger, ReadonlyRootfs: false, RestartPolicy: [object Object], Runtime: runc, SecurityOpt: null, ShmSize: 67108864, UTSMode: , Ulimits: , UsernsMode: , VolumeDriver: , VolumesFrom: null }
HostnamePath /mnt/data/docker/containers/7dc3a8aae066f6cde8345ff886bfb29d58cc1071226156bf31810f9ca0f4dde2/hostname
HostsPath /mnt/data/docker/containers/7dc3a8aae066f6cde8345ff886bfb29d58cc1071226156bf31810f9ca0f4dde2/hosts
Id 7dc3a8aae066f6cde8345ff886bfb29d58cc1071226156bf31810f9ca0f4dde2
Image sha256:3f2212948cdc13c61931a593ecd8d108717be5948888efb11b99ed13213a849b
LogPath
MountLabel
Mounts [ ]
Name /dahuavto2mqtt
NetworkSettings { Bridge: , EndpointID: , Gateway: , GlobalIPv6Address: , GlobalIPv6PrefixLen: 0, HairpinMode: false, IPAddress: , IPPrefixLen: 0, IPv6Gateway: , LinkLocalIPv6Address: , LinkLocalIPv6PrefixLen: 0, MacAddress: , Networks: [object Object], Ports: [object Object], SandboxID: 4e28e351c0d5d8a625a3c39b55f1fefbb169a5cfe4969da57ae3ebb6cf657217, SandboxKey: /var/run/docker/netns/4e28e351c0d5, SecondaryIPAddresses: null, SecondaryIPv6Addresses: null }
Path docker-php-entrypoint
Platform linux
Portainer { ResourceControl: [object Object] }
ProcessLabel
ResolvConfPath /mnt/data/docker/containers/7dc3a8aae066f6cde8345ff886bfb29d58cc1071226156bf31810f9ca0f4dde2/resolv.conf
RestartCount 15
State
Dead false
Error
ExitCode 1
FinishedAt 2020-03-05T21:26:20.373584472Z
OOMKilled false
Paused false
Pid 0
Restarting true
Running true
StartedAt 2020-03-05T21:26:19.007468131Z
Status restarting

I see somewhere it’s build at a AMD64 system, can I assume you are not using a raspberrypi3/4 ?
could that be a problem somehow?

It could be the problem, I will try setting it up on raspberry pi 3 to find a solution

Will update once i’ll fix it

with DahuaVTO2MQTT is it possible to receive an event when someone brings the card to the reader (VTO2000A-R) and the card number?

Hello is the integration ready to add it through HASSIO (running through ESXI) ?

Yes. the card number should also tell you. at the moment however it only works on amd64 platforms on docker. tested and working on my notebook. But it doesn’t work on the raspberry (AMR) docker