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