Dahua VTO custom integration

A Home Assistant custom integration for control Dahua VTO/VTH devices.

The following models are reported as working:

Folowing models should work:

Following models may work:

  • VTO12xx, VTO2101, VTO4202, VTO6xxx, VTO6221
  • VTH15xx, VTH1550, VTH16xx, VTH2201, VTH2421, VTH5222, VTH5341, VTH5421
  • VTS5240

Installation:

Copy the dahua_vto folder and all of its contents into your Home Assistant’s custom_components folder. This is often located inside of your /config folder. If you are running Hass.io, use SAMBA to copy the folder over. If you are running Home Assistant Supervised, the custom_components folder might be located at /usr/share/hassio/homeassistant. It is possible that your custom_components folder does not exist. If that is the case, create the folder in the proper location, and then copy the dahua_vto folder and all of its contents inside the newly created custom_components folder.

Alternatively, you can install localtuya through HACS by adding this repository.

Configuration Examples

Add the following to your configuration.yaml file:

sensor:
  - platform: dahua_vto
    name: NAME_HERE
    host: HOST_HERE
    timeout: TIMEOUT_HERE optional, default 10
    port: PORT_HERE optional, default 5000
    username: USERNAME_HERE_OR_secrets.yaml
    password: PASSWORD_HERE_OR_secrets.yaml
    scan_interval: SCAN_INTERVAL_HERE optional, default 60

Example

  - platform: dahua_vto
    name: Dahua VTO
    host: 192.168.1.2
    username: admin
    password: password
    scan_interval: 5

Lock example with call to open door service

timer:
  door_lock:
    name: Door Lock
    icon: mdi:timer

lock:
  - platform: template
    name: Door Lock
    value_template: "{{ not is_state('timer.door_lock', 'active') }}"
    lock:
    unlock:
      - service: dahua_vto.open_door
        data_template:
          entity_id: sensor.dahua_vto
          channel: 1
          short_number: HA

Automation example with doorbell ring and unlock events

- alias: Dahua VTO All Events
  mode: queued
  trigger:
    - platform: event
      event_type: dahua_vto
  action:
    - service: persistent_notification.create
      data:
        title: "{{ trigger.event.data.Code }}"
        message: "{{ trigger.event.data }}"

- alias: Dahua VTO Command Result
  mode: queued
  trigger:
    - platform: event
      event_type: dahua_vto
  condition:
    - condition: template
      value_template: "{{ trigger.event.data.method | string != '' }}"
  action:
    - service: persistent_notification.create
      data:
        title: "{{ trigger.event.data.method }}"
        message: "{{ trigger.event.data }}"

- alias: Dahua VTO
  mode: queued
  trigger:
    - platform: event
      event_type: dahua_vto
      event_data:
        Code: BackKeyLight
  action:
    - choose:
        - conditions: >
            {{ trigger.event.data.Data.State | int in [0, 1, 2, 5, 6] }}
          sequence:
            - service: persistent_notification.create
              data:
                title: "{{ 'Doorbell Ring' if trigger.event.data.Data.State | int in [1, 2] else 'Doorbell No Ring' }}"
                message: "{{ trigger.event.data }}"
        - conditions: >
            {{ trigger.event.data.Data.State | int == 8 }}
          sequence:
            - service: timer.start
              data:
                entity_id: timer.door_lock
                duration: 00:00:02 # VTO Unlock Period
            - service: persistent_notification.create
              data:
                title: Unlock
                message: "{{ trigger.event.data }}"
        - conditions: >
            {{ trigger.event.data.Data.State | int == 9 }}
          sequence:
            - service: persistent_notification.create
              data:
                title: Unlock failed
                message: "{{ trigger.event.data }}"
      default:
        - service: persistent_notification.create
          data:
            title: "Unknown state {{ trigger.event.data.Data.State | int }}"
            message: "{{ trigger.event.data }}"

Commands and Events

You can send any command using the service dahua_vto.send_command and receive reply as event.
I doesn’t found documentation but you can grab some commands and their parameters from Dahua-JSON-Debug-Console-v2.py

All device client.notifyEventStream messages you will receive as events, information about some of them you can find here.

For most of the cases you can use BackKeyLight event State, the list of some of them you can found in table below.

Possible that in your case the State will be different and this depends from the device model.

BackKeyLight States

State Description
0 OK, No Call/Ring
1, 2 Call/Ring
5 Call answered from VTH
6 Call not answered
7 VTH calling VTO
8 Unlock
9 Unlock failed
11 Unknown, as result of magicBox.getExitTime command after VTO reboot

Some command examples

service: dahua_vto.send_command
data:
  entity_id: sensor.dahua_vto
  method: system.listService

service: dahua_vto.send_command
data:
  entity_id: sensor.dahua_vto
  method: magicBox.listMethod

service: dahua_vto.send_command
data:
  entity_id: sensor.dahua_vto
  method: magicBox.reboot
  params: {delay: 60}
  tag: alert

service: dahua_vto.send_command
data:
  entity_id: sensor.dahua_vto
  method: magicBox.getBootParameter
  params: {names: ['serverip', 'ver']}

Debugging

Whenever you write a bug report, it helps tremendously if you include debug logs directly (otherwise we will just ask for them and it will take longer). So please enable debug logs like this and include them in your issue:

logger:
  default: warning
  logs:
    custom_components.dahua_vto: debug

Useful Links

Thanks to:

@elad-bar
@mcw0
@riogrande75

Hi, I thank you for the nice work.
Please let me ask, sorry I’m a newbie, does this project will allow two way audio between the HA and Dahua VTO? anf if so will it be possible to do it through a dasboard card?
thanks in advance for you time
bests

it’s fail in github. does it work now ?

No, this integration for now allow only to receive events from VTO, send commands and open the locks (actually it’s a set of commands inside integration). I’m not sure if it’s even possible to do two way audio using this DHIP protocol. Latest versions of VTO firmware has SIP server and you can try to make two way audio using SIP softphone.

Validate failing on github means that it’s doesn’t pass HA integration validation (because vendor images pull request doesn’t approved yet). But sure the integration is working.

thanks. BTW the comands sent to VT from HA will go through ethernet and acitvate terminals connected to the lock. Is it right?

Yes, it’s go through ethernet directly to VT and use same protocol as for events (you can open lock using http protocol as well as it’s done at Dahua VTO to MQTT Broker) but I think to use same communication for opening the lock it’s more reliable than http. Integration open the lock exactly as Dahua DMSS application.
What you mean under terminals - Dahua VTH devices?

BTW You can use same integration for Dahua VTH devices but you should look to events which you will receive and thinks if it’s report something useful for you.

I have tried the 2-way communication with the SIP server FW in the past but didn’t succeed
I have used a VTO2111D-WP-S1 with a softphone and I only managed to get a call from VTO to the softphone without audio
If someone can try and get it work it would be great!
actually, I believe your integration with a SIP integration for VTO it would be perfect for HA

@myhomeiot
Thanks for you integration. I have questions concerning event, is it possible to get door status event as a binary sensor ?
I can get this info on my vto2202fp.

Hello,
I can’t say exactly because my door sensor doesn’t connected to VTO but if you see corresponding events when you open and close door, sure it’s possible to do by using input_boolean. Turn it on when you receives door open event and turn it off when door close. If you post here data from door open and close event I will help you with configuration.

I tried to add it to my HA but for some reason it would not work! It failed and this is my log:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 143, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1480, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1515, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 206, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 649, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 692, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 686, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/template/lock.py", line 146, in async_unlock
    await self._command_unlock.async_run(context=self._context)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1195, in async_run
    await asyncio.shield(run.async_run())
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 341, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 359, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 559, in _async_call_service_step
    await service_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1480, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1515, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 719, in admin_handler
    await result
  File "/config/custom_components/dahua_vto/__init__.py", line 59, in service_open_door
    raise HomeAssistantError("entity not found")
homeassistant.exceptions.HomeAssistantError: entity not found 

@aalmarshad As I see you try to call open_door service and get “entity not found”, in Developer Tools check that you have sensor.dahua_vto entity (or simular if you specified the name in integration configuration) and check that you specified correct entity_id in open_door service call, example you can see here

Yes, for some reason I cannot find sensor.dahua_vto even I did the configuration in the configuration.yaml as explained in the GitHub page

@aalmarshad Can you turn on debugging as explained here and check if you have communication with a VTO.

You should see something similar to:

2021-04-08 08:46:59 DEBUG (MainThread) [custom_components.dahua_vto.sensor] Connecting 192.168.x.x:5000, username xxxxx
2021-04-08 08:46:59 DEBUG (MainThread) [custom_components.dahua_vto.sensor] >>> {"method":"global.login","params":{"clientType":"","ipAddr":"(null)","loginType":"Direct"},"id":1,"session":0}
2021-04-08 08:46:59 DEBUG (MainThread) [custom_components.dahua_vto.sensor] <<< {"error":{"code":268632079,"message":"Component error: login challenge!"},"id":1,"params":{"authorization":"5dfb193508f162df191c8a12f96f82af75589683","encryption":"Default","mac":"14A78B0CB798","random":"1827976903","realm":"Login to XXXXXXXXXXXXXXX"},"result":false,"session":2147483500}
2021-04-08 08:46:59 DEBUG (MainThread) [custom_components.dahua_vto.sensor] >>> {"method":"global.login","params":{"clientType":"","ipAddr":"(null)","loginType":"Direct","userName":"admin","password":"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"},"id":2,"session":2147483500}
2021-04-08 08:46:59 DEBUG (MainThread) [custom_components.dahua_vto.sensor] <<< {"id":2,"params":{"keepAliveInterval":60},"result":true,"session":2147483500}
2021-04-08 08:46:59 DEBUG (MainThread) [custom_components.dahua_vto.sensor] >>> {"method":"eventManager.attach","params":{"codes":["All"]},"id":3,"session":2147483500}
2021-04-08 08:46:59 DEBUG (MainThread) [custom_components.dahua_vto.sensor] >>> {"method":"magicBox.getSystemInfo","id":4,"session":2147483500}
2021-04-08 08:46:59 DEBUG (MainThread) [custom_components.dahua_vto.sensor] <<< {"id":3,"params":{"SID":513},"result":true,"session":2147483500}

I found my problem. I was naming the service main instead of dahua_vto. it works like charm now. Thanks for your help and support

Great! Can you share the model of your VTO, I will update a list of supported models here

1 Like

Sure, it’s VTO2202F

I wish to see the integration on the official HA list.

best wishes and thanks for your hard work

Thanks!
I’m not sure about HA official list, but I hope soon we will see this integration in HACS default. This will make installation and maintenance of integration much easy.