Dahua VTO custom integration

You can try to enable extra logging for integration in Home Assistant configuration.yaml as it’s described here and attach here the log file.

Edit: You can also try to use this integration and see if it’s works with your VTO.

I see that in the logs:

This error originated from a custom integration.

Logger: homeassistant
Source: custom_components/dahua_vto/sensor.py:147
integration: Dahua VTO (documentation, issues)
First occurred: 13:48:28 (12 occurrences)
Last logged: 13:49:23

Error doing job: Exception in callback _SelectorSocketTransport._call_connection_lost(None) (None)
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/local/lib/python3.12/asyncio/selector_events.py", line 1181, in _call_connection_lost
    super()._call_connection_lost(exc)
  File "/usr/local/lib/python3.12/asyncio/selector_events.py", line 901, in _call_connection_lost
    self._protocol.connection_lost(exc)
  File "/config/custom_components/dahua_vto/sensor.py", line 147, in connection_lost
    self.on_connection_lost.set_result(True)
asyncio.exceptions.InvalidStateError: invalid state

I also tried the other integration, and it also doesn’t seem to work for me.
I see all the entities but none of them is updating, and the camera entity shows nothing.

The only thing that works for me so far is ONVIF, which lets me see the camera well

I also see that:

2024-08-04 13:48:28.475 DEBUG (MainThread) [custom_components.dahua_vto.sensor] >>> {"method":"global.login","params":{"clientType":"","ipAddr":"(null)","loginType":"Direct","userName":"admin","password":"05D19825D5583D04335AA0CE558E55BB"},"id":2,"session":593263706}
2024-08-04 13:48:28.484 DEBUG (MainThread) [custom_components.dahua_vto.sensor] <<< {"error":{"code":268632085,"message":"Component error: User or password not valid!"},"id":2,"params":{"remainLockSecond":0,"remainLoginTimes":0},"result":false,"session":1476859084}

But these are the same username and password that i’m using for the ONVIF, and it works there

For the integration you should use user name and password which you use for VTO web interface which you can access by http://VTO-IP

Edit: Can you access your VTO using Dahua DMSS application from the mobile?

Thank you. It was a username and password problem, now the sensor is working. I’ll check everything else. Thanks a lot!

Hi,
I have connected my DAHUA VTO2022 to my HA.
My door is not directly connected to VTO but to HA with zigbee button.
I would like : When i press “open the door” on DMSS, HA open the door.
How i can see (entity?) when i press the button on DMSS (when i do it, my VTO say “the door is opened” but " [binary_sensor.portier_video_button_pressed]" stay at OFF).

I have seen message with the magnetic sensor but i don’t want to add fire as possible from door to VTO, i don’t want to drill :upside_down_face:)

Thanks for your answer

I wich you can understand, i’m french and i try to not use a translator :slight_smile:

Thank you @myhomeiot for your great work! and for everyone here
I am a newpie who tried dozen of times to understand this without success

I did install HACS and Dahua + Dahua+VTO integrations.
Then I copied your examples to my yaml file but no success!

Here is my full yaml file hope you can help:

# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

#Dahua

sensor:
  - platform: dahua_vto
    name: myvto
    host: http://192.168.1.10
    ##timeout: TIMEOUT_HERE optional, default 10
    ##port: PORT_HERE optional, default 5000
    username: !secret myvto_username
    password: !secret myvto_password
    ##scan_interval: SCAN_INTERVAL_HERE optional, default 60

  - platform: dahua_vto
    name: vh1
    host: http://192.168.1.11
    ##timeout: TIMEOUT_HERE optional, default 10
    ##port: PORT_HERE optional, default 5000
    username: !secret vh1_username
    password: !secret vh1_password
    ##scan_interval: SCAN_INTERVAL_HERE optional, default 60

automation myvto:
  - 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 if trigger.event.data.Code is defined else 'Unknown 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 is defined }}"
    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 }}"
          - conditions: >
              {{ trigger.event.data.Data.State | int == 11 }}
            sequence:
              - service: persistent_notification.create
                data:
                  title: Device rebooted
                  message: "{{ trigger.event.data }}"
        default:
          - service: persistent_notification.create
            data:
              title: "Unknown state {{ trigger.event.data.Data.State | int }}"
              message: "{{ trigger.event.data }}"

              
  - service: dahua_vto.send_command
    data:
      entity_id: sensor.myvto
      method: console.runCmd
      params: { "command": "od" }
      event: false

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

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

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

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

    # Make VTO Call
  - service: dahua_vto.send_command
    data:
      entity_id: sensor.myvto
      method: console.runCmd
      params: { "command": "call 9901" }
      event: false

    # Cancel VTO Call
  - service: dahua_vto.send_command
    data:
      entity_id: sensor.myvto
      method: console.runCmd
      params: { "command": "hc" }
      event: false

    # Clear VTH Call Records
  - service: dahua_vto.send_instance_command
    data:
      entity_id: sensor.dahua_vth
      method: RecordUpdater.clear
      instance_params: { "name": "VideoTalkMissedLog" }
      event: false

    # Arming the VTH alarm
  - service: dahua_vto.send_command
    data:
      entity_id: sensor.dahua_vth
      method: configManager.setConfig
      params:
        {
          "table": { "AlarmEnable": true, "CurrentProfile": "Outdoor" },
          "name": "CommGlobal",
        }
      event: false

    # Disarming the VTH alarm
  - service: dahua_vto.send_command
    data:
      entity_id: sensor.dahua_vth
      method: configManager.setConfig
      params:
        {
          "table": { "AlarmEnable": false, "CurrentProfile": "AtHome" },
          "name": "CommGlobal",
        }
      event: false

    # Getting the VTH alarm status
  - service: dahua_vto.send_command
    data:
      entity_id: sensor.dahua_vth
      method: configManager.getConfig
      params: { "name": "CommGlobal" }
      event: true

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.myvto
          channel: 1
          short_number: HA

template:
  - trigger:
      - platform: event
        event_type: dahua_vto
        event_data:
          Code: DoorStatus
    binary_sensor:
      - name: VTO Door Status
        state: "{{ trigger.event.data.Data.Status | string == 'Open' }}"
        device_class: door

Button:
type: "custom:button-card"
icon: "mdi:doorbell-video"
name: Doorstation - Door 1
tap_action:
  action: call-service
  service: dahua_vto.open_door
  service_data:
    entity_id: sensor.myvto
    channel: 1
    short_number: HA
styles:
  card:
    - font-size: 12px
    - font-weight: bold
color: auto
show_state: false

Sample commands are provided for some VTH actions, such as setting alarm status and clearing missed call records. The VTH can be configured to stream video feeds from IP cameras other than the VTO. Does anybody know of a command(s) to make the VTH display one of these preconfigured camera feeds?

My use case would be an automation flow such that a motion detection event, if classified by AI tools as involving a person, would cause the relevant camera’s video stream to be displayed on the VTH.

Thanks.

Hello,

In my case in DMSS application when I try open the door which is not connected I get BackKeyLight event with State equal 9 (Unlock failed) you can use it to send command which press your zigbee button which will open the door.

Try Dahua VTO All Events or Dahua VTO automation from readme and check if you get this state when you try to open the door with DMSS application.

Hello,

You copied too much, the readme doesn’t not have configuration - it’s contains different code snippets which you need to use as example to automate your needs. So first try only with sensors definition and after restarting Home Assistant check that sensors in OK state, when add Dahua VTO All Events automation from this example and check events you get, etc

PS: If you a new in Home Assistant YAML programming and you just start integration of Dahua VTO/VTH you can try this integration which is much user friendly.

sensor:
  - platform: dahua_vto
    name: myvto
    host: http://192.168.1.10
    ##timeout: TIMEOUT_HERE optional, default 10
    ##port: PORT_HERE optional, default 5000
    username: !secret myvto_username
    password: !secret myvto_password
    ##scan_interval: SCAN_INTERVAL_HERE optional, default 60

  - platform: dahua_vto
    name: vh1
    host: http://192.168.1.11
    ##timeout: TIMEOUT_HERE optional, default 10
    ##port: PORT_HERE optional, default 5000
    username: !secret vh1_username
    password: !secret vh1_password
    ##scan_interval: SCAN_INTERVAL_HERE optional, default 60

Hi,
just to inform you I have a VTO9541D running with this integration. Works quite well.
I am just working on an automation to combine it with a nuki doorlock. I think just some small finetuning, and it works like a charm. Well done for this integration.

1st question: does this integration work with hacs 2.x? I am not sure if I should upgrade.

2nd question: my automation currently does not work with face unlock. Does this face unlock use a different return code, different from 8? Or why does my automation not respond as exptected to open the nuki.

Thanks

Hello, I’m glad that integration helps you.

  1. Yes, it’s works with HACS 2.x same as before (without GUI configuration).
  2. I’m not familiar with face unlock, but as you thinking it’s can have another BackKeyLight State code, please test it with your code or Dahua VTO All Events automation and let’s me know, if it’s different codes I will update readme. Please check also unlock failed with face unlock.

Hi Guys, im looking at buying either the VTO2211 or VTO3211. Wondering which has better compatibility with HA and this addon for various functions like lock control/video/audio.

Also do others have any suggestions or preference between the 2?

It has to be POE powered and work standalone without an indoor screen

Just wanted to mention that I got this working with my Lorex 2k doorbell (so it should also work with the Amcrest and Dahua doorbells). I was already using DahuaVTO2MQTT to detect doorbell presses (which is all I needed it for), so when I found this integration, I figured I’d try it out.

Works perfectly:

trigger:
  - alias: When Lorex 2K Doorbell button pressed
    platform: event
    event_type: dahua_vto
    event_data:
      Code: PhoneCallDetect
      Action: Start

Since it just blindly parses all messages, I was able to use it for the PhoneCallDetect event which is triggered on button press.

This greatly simplifies my setup by eliminating the need for the docker container and monitoring it to ensure it’s working. I also really like how small and simple the code is… I don’t need video or anything else - literally bare bones just to get doorbell events, so this is perfect.

hello community, I have a VTO 4202f-p-s2 which has more bells ( buttons). How to automate so that a light bulb turns on at home after pressing a button number 3? Thank you!

Hi,
The connection to my doorbell is lost after a while, do you know how to restart it ?
Best regards,

It retries after a delay (timeout) of 10 seconds by default. It also tries to maintain a connection using a 60s keepalive (scan_interval). Both are configurable.

For those that may have a fully integrated doorbell like I do (Dahua ASI6214S-PW) and were unable to get it working with the custom VTO integration, after reading this thread and not seeing it, here is how I got the doorbell unlocking with home assistant:

Add the following shell command in your configuration.yaml file:

  unlock_door: 'curl --digest -u "username:password" "http://<device_ip>/cgi-bin/accessControl.cgi?action=openDoor&channel=1&UserID=<user_id>"'

Replace username, password, <device_ip> and ‘<user_id>’ with your actual credentials and device IP address.

Here my full post/explanation below if interested or if you have a similar device…

Dahua integrated doorbell and Home Assistant - Share your Projects! - Home Assistant Community (home-assistant.io)

You can try Dahua VTO All Events or Dahua VTO automation from readme and check if you get extra data for events where you pressed different buttons.

alias: Dahua bell
triggers:

  • event_type: dahua_vto
    event_data:
    Code: VideoTalkLog
    Action: Pulse
    trigger: event
    conditions:
  • condition: template
    value_template: “{{ trigger.event.data[‘Data’][‘LocalNumber’] == ‘2’ }}”
    enabled: true
    actions: