Home

Awesome

Home Assistant Dahua Integration

The Dahua Home Assistant integration allows you to integrate your Dahua cameras, doorbells, NVRs, DVRs in Home Assistant. It's also confirmed to work with some Lorex cameras and Amcrest devices.

Supports motion events, alarm events (and others), enabling/disabling motion detection, switches for infrared, illuminator (white light), security lights (red/blue flashers), sirens, doorbell button press events, and more.

Also exposes several services to enable/disable motion detection or set the text overlay on the video.

NOTE: Using the switch to turn on/off the infrared light will disable the "auto" mode. Use the service to enable auto mode again (or the camera UI).

Why not use the Amcrest integration already provided by Home Assistant? The Amcrest integration is missing features that this integration provides and I want an integration that is branded as Dahua. Amcrest are rebranded Dahua cams. With this integration living outside of HA, it can be developed faster and released more often. HA has release schedules and rigerous review processes which I'm not ready for while developing this integration. Once this integration is mature I'd like to move it into HA directly.

Installation

If you want live-streaming, make sure to add the following to your config.yaml:

ffmpeg:

See ffmpeg and stream.

HACS install

To install with HACS:

  1. Click on HACS in the Home Assistant menu
  2. Click on Integrations
  3. Click the EXPLORE & ADD REPOSITORIES button
  4. Search for Dahua
  5. Click the INSTALL THIS REPOSITORY IN HACS button
  6. Restart Home Assistant
  7. Configure the camera by going to Configurations -> Integrations -> ADD INTERATIONS button, search for Dahua and configure the camera.

Manual install

To manually install:

# Download a copy of this repository
$ wget https://github.com/rroller/dahua/archive/dahua-main.zip

# Unzip the archive
$ unzip dahua-main.zip

# Move the dahua directory into your custom_components directory in your Home Assistant install
$ mv dahua-main/custom_components/dahua <home-assistant-install-directory>/config/custom_components/

:warning: After executing one of the above installation methods, restart Home Assistant. Also clear your browser cache before proceeding to the next step, as the integration may not be visible otherwise.

Setup

  1. Now the integration is added to HACS and available in the normal HA integration installation, so...
  2. In the HA left menu, click Configuration
  3. Click Integrations
  4. Click ADD INTEGRATION
  5. Type Dahua and select it
  6. Enter the details:
    1. Username: Your camera's username
    2. Password: Your camera's password
    3. Address: Your camera's address, typically just the IP address
    4. Port: Your camera's HTTP port. Default is 80
    5. RTSP Port: Your camera's RTSP port, default is 554. Used to live stream your camera in HA
    6. Events: The integration will keep a connection open to the camera to capture motion events, alarm events, etc. You can select which events you want to monitor and report in HA. If no events are selected then the connection will no be created. If you want a specific event that's not listed here open an issue and I'll add it.

NOTE: All streams will be added, even if not enabled in the camera. Just remove the ones you don't want.

Dahua Setup

Known supported cameras

This integration should word with most Dahua cameras and doorbells. It has been tested with very old and very new Dahua cameras.

Doorbells will have a binary sensor that captures the doorbell pressed event.

These devices are confirmed as working:

Dahua cameras

Series2 Megapixels4 Megapixels5 Megapixels8 Megapixels
Consumer Series
IPC-A26
1-Series
IPC-HFW1230SIPC-HFW1435S-W
IPC-HDBW1230E-S2IPC-HFW1435S-W-S2
2-/3-Series
IPC-HDW2831T-ZS-S2IPC-HDW3549HP-AS-PVIPC-HDW3849HP-AS-PV
4-/5-Series
IPC-HDW4231EM-ASEIPC-HFW4433F-ZSAIPC-HDW5831R-ZE
IPC-HDBW4231F-ASIPC-HDBW5421E-Z
IPC-HDW4233C-AIPC-T5442T-ZE
IPC-HDBW4239R-ASE
IPC-HDBW4239RP-ASE
Panoramic Series
IPC-EW5531-AS

Other brand cameras

Brand2 Megapixels4 Megapixels5 Megapixels8 Megapixels
IMOU
IMOU IPC-A26Z / Ranger Pro Z
IMOU IPC-C26E-V2 <sup>*</sup>
IMOU IPC-K22A / Cube PoE-322A
Lorex
Lorex E891AB
Lorex LNB8005-C
Lorex LNE8964AB

<sup>*</sup> partial support

Doorbell cameras

Brand2 Megapixels4 Megapixels5 Megapixels8 Megapixels
Amcrest
Amcrest AD110Amcrest AD410
Dahua
DHI-VTO2202F-P
DHI-VTO2211G-P
DHI-VTO3311Q-WP
IMOU
IMOU C26EP-V2

Known Issues

Events

Events are streamed from the device and fired on the Home Assistant event bus.

Here's example event data:

{
    "event_type": "dahua_event_received",
    "data": {
        "name": "Cam13",
        "Code": "VideoMotion",
        "action": "Start",
        "index": "0",
        "data": {
            "Id": [
                0
            ],
            "RegionName": [
                "Region1"
            ],
            "SmartMotionEnable": false
        },
        "DeviceName": "Cam13"
    },
    "origin": "LOCAL",
    "time_fired": "2021-06-30T04:00:28.605290+00:00",
    "context": {
        "id": "199542fe3f404f2a0a81031ee495bdd1",
        "parent_id": null,
        "user_id": null
    }
}

And here's how you configure and event trigger in an automation:

platform: event
event_type: dahua_event_received
event_data:
  name: Cam13
  Code: VideoMotion
  action: Start

And that's it! You can enable debug logging (See at the end of this readme) to print out events to the Home Assisant log as they fire. That can help you understand the events. Or you can HA and open Developer Tools -> Events -> and under "Listen to events" enter dahua_event_received and then click "Start Listening" and wait for events to fire (you might need to walk in front of your cam to make motion events fire, or press a button, etc)

Example Code Events

CodeDescription
BackKeyLightUnit Events, See Below States
VideoMotionmotion detection event
VideoLossvideo loss detection event
VideoBlindvideo blind detection event
AlarmLocalalarm detection event
CrossLineDetectiontripwire event
CrossRegionDetectionintrusion event
LeftDetectionabandoned object detection
TakenAwayDetectionmissing object detection
VideoAbnormalDetectionscene change event
FaceDetectionface detect event
AudioMutationintensity change
AudioAnomalyinput abnormal
VideoUnFocusdefocus detect event
WanderDetectionloitering detection event
RioterDetectionPeople Gathering event
ParkingDetectionparking detection event
MoveDetectionfast moving event
MDResultmotion detection data reporting event. The motion detect window contains 18 rows and 22 columns. The event info contains motion detect data with mask of every row
HeatImagingTempertemperature alarm event

BackKeyLight States

StateDescription
0OK, No Call/Ring
1, 2Call/Ring
4Voice message
5Call answered from VTH
6Call not answered
7VTH calling VTO
8Unlock
9Unlock failed
11Device rebooted

Services and Entities

Note for ease of use, the integration tries to determine if your device supports certain services, entities and will conditionally add them. But that's sometimes a little hard so it'll just add the entity even if your devices doesn't support. I'd rather opt into extra entities than to create a complicated flow to determine what's supported and what isn't. You can simply disable the entities you don't want. An example of this is the "door open state" for doorbells. Not all doorbells support this.

Services

ServiceParametersDescription
camera.enable_motion_detectionEnables motion detection
camera.disable_motion_detectionDisabled motion detection
dahua.set_infrared_modetarget: camera.cam13_main <br /> mode: Auto, On, Off <br /> brightness: 0 - 100 inclusiveSets the infrared mode. Useful to set the mode back to Auto
dahua.set_video_profile_modetarget: camera.cam13_main <br /> mode: Day, NightSets the video profile mode to day or night
dahua.set_focus_zoomtarget: camera.cam13_main <br /> focus: The focus level, e.g.: 0.81 0 - 1 inclusive <br /> zoom: The zoom level, e.g.: 0.72 0 - 1 inclusiveSets the focus and zoom level
dahua.set_channel_titletarget: camera.cam13_main <br /> channel: The camera channel, e.g.: 0 <br /> text1: The text 1<br /> text2: The text 2Sets the channel title
dahua.set_text_overlaytarget: camera.cam13_main <br /> channel: The camera channel, e.g.: 0 <br /> group: The group, used to apply multiple of text as an overly, e.g.: 1 <br /> text1: The text 1<br /> text3: The text 3 <br /> text4: The text 4 <br /> text2: The text 2Sets the text overlay on the video
dahua.set_custom_overlaytarget: camera.cam13_main <br /> channel: The camera channel, e.g.: 0 <br /> group: The group, used to apply multiple of text as an overly, e.g.: 0 <br /> text1: The text 1<br /> text2: The text 2Sets the custom overlay on the video
dahua.enable_channel_titletarget: camera.cam13_main <br /> channel: The camera channel, e.g.: 0 <br /> enabled: True to enable, False to disableEnables or disables the channel title overlay on the video
dahua.enable_time_overlaytarget: camera.cam13_main <br /> channel: The camera channel, e.g.: 0 <br /> enabled: True to enable, False to disableEnables or disables the time overlay on the video
dahua.enable_text_overlaytarget: camera.cam13_main <br /> channel: The camera channel, e.g.: 0 <br /> group: The group, used to apply multiple of text as an overly, e.g.: 0 <br /> enabled: True to enable, False to disableEnables or disables the text overlay on the video
dahua.enable_custom_overlaytarget: camera.cam13_main <br /> channel: The camera channel, e.g.: 0 <br /> group: The group, used to apply multiple of text as an overly, e.g.: 0 <br /> enabled: True to enable, False to disableEnables or disables the custom overlay on the video
dahua.set_privacy_maskingtarget: camera.cam13_main <br /> index: The mask index, e.g.: 0 <br /> enabled: True to enable, False to disableEnables or disabled a privacy mask on the camera
dahua.set_record_modetarget: camera.cam13_main <br /> mode: Auto, On, OffSets the record mode. On is always on recording. Off is always off. Auto based on motion settings, etc.
dahua.enable_all_ivs_rulestarget: camera.cam13_main <br /> channel: The camera channel, e.g.: 0 <br /> enabled: True to enable all IVS rules, False to disable all IVS rulesEnables or disables all IVS rules
dahua.enable_ivs_ruletarget: camera.cam13_main <br /> channel: The camera channel, e.g.: 0 <br /> index: The rule index <br /> enabled`: True to enable the IVS rule, False to disable the IVS ruleEnable or disable an IVS rule
dahua.vto_open_doortarget: camera.cam13_main <br /> door_id: The door ID to open, e.g.: 1 <br /> Opens a door via a VTO
dahua.vto_cancel_calltarget: camera.cam13_main <br />Cancels a call on a VTO device (Doorbell)
dahua.set_video_in_day_night_modetarget: camera.cam13_main <br /> config_type: The config type: general, day, night <br /> mode: The mode: Auto, Color, BlackWhite. Note Auto is also known as Brightness by DahuaSet the camera's Day/Night Mode. For example, Color, BlackWhite, or Auto
dahua.reboottarget: camera.cam13_main <br />Reboots the device

Camera

This will provide a normal HA camera entity (can take snapshots, etc)

Switches

SwitchDescription
MotionEnables or disables motion detection on the camera
SirenIf the camera has a siren, will turn on the siren. Note, it seems sirens only stay on for 10 to 15 seconds before switching off
Disarming LinkageNewer firmwares have a "disarming" feature (not sure what it is, but some people use it). This allows one to turn it on/off. This is found in the UI by going to Event -> Disarming

Lights

LightDescription
InfraredTurns on/off the infrared light. Using this switch will disable the "auto" mode. If you want to enable auto mode again then use the service to enable auto. When in auto, this switch will not report the on/off state.
IlluminatorIf the camera has one, turns on/off the illuminator light (white light). Using this switch will disable the "auto" mode. If you want to enable auto mode again then use the service to enable auto. When in auto, this switch will not report the on/off state.
SecurityIf the camera has one, turns on/off the security light (red/blue flashing light). This light stays on for 10 to 15 seconds before the camera auto turns it off.

Binary Sensors

SensorDescription
MotionA sensor that turns on when the camera detects motion
Button PressedA sensor that turns on when a doorbell button is pressed
OthersA binary senor is created for evey event type selected when setting up the camera (Such as cross line, and face detection)

Local development

If you wish to work on this component, the easiest way is to follow HACS Dev Container README. In short:

Debugging

Add to your configuration.yaml:

logger:
  default: info
  logs:
    custom_components.dahua: debug

Curl/HTTP commands

# Stream events
curl -s --digest -u admin:$DAHUA_PASSWORD  "http://192.168.1.203/cgi-bin/eventManager.cgi?action=attach&codes=[All]&heartbeat=5"

# List IVS rules
http://192.168.1.203/cgi-bin/configManager.cgi?action=getConfig&name=VideoAnalyseRule

# Enable/Disable IVS rules for [0][3] ... 0 is the channel, 3 is the rule index. Use the right index as required
http://192.168.1.203/cgi-bin/configManager.cgi?action=setConfig&VideoAnalyseRule[0][3].Enable=false

# Enable/disable Audio Linkage for an IVS rule
http://192.168.1.203/cgi-bin/configManager.cgi?action=setConfig&VideoAnalyseRule[0][3].EventHandler.VoiceEnable=false

References and thanks