Dahua IP camera component

Like what? IVS motion events work great for me.

I’m using the Amcrest component now instead of ffMpeg and it’s working really well for my Dahua Starlights, especially with real-time streaming and PTZ with presets capability. It is being actively supported and new PR’s to better support motion sensing are coming soon. From what I can tell by comparing the Dahua and Amcrest documentation - the API’s are identical.

Anyone else trying this, it might be helpful to post your results here.

EDIT: The Amcrest component currently does not support NVR’s - only direct IPC camera connections, but this was an accepted feature request that could possibly be implemented.

1 Like

Do you get IVS events from your Dahua starlights with the Amcrest component?

I haven’t set up tripwire or other advanced IVS events yet. Motion sensing is working now, but significant improvements related to sensors should land in the next HA release (.92).

The python-Amcrest API code (which this component depends on) only lists VideoMotion, VideoLoss, and VideoBlind detection events as parameters in its documentation. I’m not sure if that means it doesn’t support other IVS events like tripwire or it just wasn’t documented.

I know you have a lot of experience with Dahua and IVS detection via HA custom scripts and MQTT. You might want to check out the Amcrest custom_component now or wait a few days for .92 to see if it can detect IVS events or not.

Ok. I’m going to stick to my setup. It works great and is super stable.

@GaryOkie @johnnyletrois

Hi guys. The Amcrest HTTP API spec mentions “standard codes defined in DHIIF”, and lists a bunch of them, including VideoMotion, CrossLineDetection (tripwire), etc. In theory the event_channels_happened method in the amcrest package can take any of these codes, but so far it’s only been using ‘VideoMotion’, which the HA amcrest component uses for its motion detection sensor. If other codes could be useful, I’d be happy to add support for them. I’d need someone else to test, though, since I don’t think either of the Amcrest models I have support them.

Also, right now the event is polled. But the API also supports a subscribe method. I’m not sure how to use that, but at some point I may look into it. I mention this because the poll method (i.e., using the “Get channels event happened” API) notes that not all codes are supported by that method, and recommends using the subscribe method. So that might ultimately be needed, unless you know the polling method works with these other codes.

BTW, I have no idea what “DHIIF” refers to. I googled it and came up empty.

Many thanks for the research Phil! Component support for the advanced intelligent eventCodes would indeed be very useful. I will do my best to help you test them.

I would think subscribing to events would be preferable to polling in any case. I really hope you do get a chance to look into this further. If it helps, there is code that exists now that I am pretty sure is using the subscribe method.

@johnnyletrois leveraged code that was found on ipcamtalk forum to link it to HA via MQTT (instead of BlueIris). Another HA user, @Sawey leveraged Johnny3’s code to create an HA Dahua-event component.

I tried to make it work with HASSIO but could not manage to get pyCurl to install. So here I am, enjoying your enhanced Amcrest component and hoping that a few more enhancements can really make it universal for both Dahua and Amcrest.

Hi all!
I am on the same boat of having Dahua camera’s and trying to get a setup I like in HA. The camera feeds work just fine, but I am trying to tap into the motion detection to trigger automation.

First I tried FFMPEG binary motion sensor - but the sensor was going offline constantly… I could use an automation to restart it - but I didn’t like its inconsistency.

Then I tried the Amcrest Component - everything seemed to work fine, but after some time I realized that again the motion detection was failing. This time (with the Amcrest component) it was getting a bunch of:

Trying again due to error 401 Client Error: Unauthorized for url: http://XX.XX.XX.XX:80/cgi-bin/snapshot.cgi?channel=0

Now, I have tried the custom component contrived here.
I had to use a difference fork as with update 0.92 things have changed, but luckily someone appears to have managed this:

Unfortunately, again I am having issues… It looks like I am getting the same errors the Amcrest component had.

So this makes me think there is something wrong with my camera setup - but it works for some time before this… so initially the camera allows connections, but eventually begins denying them. Is anyone knowledgeable enough to tell me what to check or what could be causing this?

I feel like I am close to having a working setup… but am missing something small that is causing the camera to reject logins from HA when it tries to check for motion…

Any/all help is welcome… Thanks!

DeadEnd

In my searching, I may have found an alternative route that.
I just found and started using this tonight, so no significant amount of time has been spent to see if it will have the same issue… but in Node-Red I found a palette for Dahua:

This appears to work with motion detection:

image

I just added a switch node after that interprets what is seen by the sensor node and directs what to do next. So I setup the switch on the msg.topic and use the above two as on and off triggers.

So far it is working, but only been up for 10-15 minutes.
We’ll see if it runs into the same 401 error that the previous attempts led to… hopefully this stays working!

Cheers!
DeadEnd

FWIW, that error is misleading. It is incorrectly reporting an authorization error because retrying was implemented incorrectly for a camera that uses Digest Authentication. A fix is in the works and will hopefully be released before too long.

Also, the amcrest component does not use the same mechanism for event monitoring. (Maybe it should, but as of now it doesn’t.) Rather it polls for motion detection status and provides the current status in a binary_sensor. But given the polling frequency and the minimum “on time” for motion detection, the binary_sensor will never miss an event.

@pnbruckner
Thank you for the reply!
I’ll have to double check (if I can find where) but I believe my camera is using basic authentication, not digest. I haven’t changed it from the default though - I don’t even know if I can!

I believe the problem is on the camera side though… I have now tried Amcrest Component, ffmpeg binary motion sensor, and Dahua palette in Node-Red. All seem to do the same thing. They work for a number of hours, and then stop updating.

In Home assistant I get errors: ffmpeg stops, and I have to restart it - Amcrest starts throwing communications error and failed to update, etc.

In Node-Red I haven’t been able to find any error log (I just started using it). The node says it is connected, but I get no messages from the node even when I am walking around in front of the camera. I have confirmed in the camera log that events are being generated too (just to be sure).

Last night I found a firmware update for the camera (current is August 2018, new is December 2018). The changes listed and discussion sound like a lot of things have been fixed. I am hoping that I’ll be lucky enough that this fixes my camera issues.

For anyone with a popular IPC-HDW5231R-ZE or variant might get some improvement out of this.

The authentication config setting for the amcrest component, as the doc mentions, only applies when stream_source is set to mjpeg, and even that isn’t used when using the new stream component. For everything else, the authentication is figured out when it first connects to the camera. First it tries Basic Authentication, and if that doesn’t work, then it tries Digest Authentication. In an upcoming release you’ll be able to see this happening in the log if you enable debug.

If you see consistent errors for anything except the snapshot command, then there definitely is something wrong. After you get the new firmware loaded, and if you try it again with the HA amcrest component, and still have issues, I’d like to see if we can get to the bottom of them. Let me know.

I absolutely will!
I’m happy to help - I just don’t have the DEV experience to do to much on my own yet.

I did find an even newer firmware that may fix some more (who knows). The IPCAMTalk disucssion sounds like it is safe to upload, so I am going to use a March 2019 firmware instead of the December 2018… hopefully there’s improvement.

Thanks!
DeadEnd

Well, I got the new firmware installed and everything set back up.
I re-added the Amcrest component for the camera and its binary motion sensor.

Currently I am seeing this:

Trying again due to error 400 Client Error: Bad Request for url: http://xx.xx.xx.xx:80/cgi-bin/snapshot.cgi?channel=0

Since it is for the snapshot, I think it is actually the TensorFlow component trying to get the snapshot from the camera. Tensorflow hasn’t updated its value since the firmware upgrade.

I did try loading this address in a browser and get the same bad request.
BUT if I change the channel from =0 to =1 I get the snapshot.

I don’t know if that was part of the firmware change - but it use to work, so I assume it is.
Seems odd to have changed the channel of the camera though… not sure what would cause this, or if it is some setting I can change on the camera setup.

Once I get this straightened out, I will see if any other errors return.

Any feedback is always welcome!
DeadEnd

I hade same problem because new firmware use channel 1 instead of 0.
If you choose resolution: low it will use channel 1 instead of channel 0.
###############################
amcrest:

  • host: !secret laundry_cam_ip
    username: !secret nvr_username
    password: !secret nvr_passsword
    name: Laundry
    resolution: low

the comments in snapshot.py are (and have been) misleading regarding the channel parameter. It actually selects from the video streams. 0 is the Main Stream, and 1 is the Sub Stream. In HA it is controlled by the resolution configuration variable. The value of high corresponds to channel 0, and the value of low corresponds to channel 1. So, if you need channel 1, then you should set resolution to low in your amcrest configuration.
https://github.com/home-assistant/home-assistant/pull/22949#issuecomment-485488616

1 Like

@DeadEnd @JLeandroFreitas

Regarding the channel parameter of the snapshot command, it does indeed select the video channel number. It is supposed to start from 1, but it seems in some (maybe older???) firmware versions channel 0 seems to be equivalent to 1. It does not select between the main and extra streams. And, yes, the comments in snapshot.py are misleading. I have it on my list of changes to make to fix that.

But more important than the comments are what the code currently does, both in the amcrest package and in the HA amcrest component. Currently the resolution setting is used to send a 0 or a 1 as the channel number. But what I believe it should do is to not send the channel parameter at all (so that the camera firmware can default to the correct channel number.) Therefore, what I plan to do is to change the snapshot command in the amcrest package, and the async_camera_image method in the HA amcrest component, so that the snapshot command is sent without the ?channel=N parameter. Could you check for me, if you use http://IP:PORT/cgi-bin/snapshot.cgi in a browser, does it work? It works for me with my Amcrest cameras.

From the Amcrest HTTP Protocol API Specifications:

Yes, this does get a snapshot (after entering credentials) on my Dahua camera.

1 Like

@DeadEnd or anyone with a dahua.

I have a Dahua z12e model and am brand new to home assistant but learning fast. I was on the ipcamtalk forum and follow it closely. In fact have you seen this topic? Dahua Starlight Varifocal Bullet Z5 7-35mm (IPC-HFW5231E-Z5) | Page 12 | IP Cam Talk

Specifically post #228 and #231.
Video from post #228

Are you trying to do something like that using HA? That is what I want to do. Use IVS to trigger event in HA and use on board speaker through camera to play an mp3 after each tripwire event. Still investigating how this can be accomplished. Go3team does it with openhab which I looked into but its support for my devices was limited at best, where HA has everything up and running in a day except for my dahua camera and my onvif cameras. I see that you have been trying to find support for the dahua integration, and have tried a number of them (amazing there are so many to pick from). But which have you found supports the most features for your ZE model? I’m assuming you have the z5e or the z12e, or is there a plain ze model? In either case I think whatever you settled on should work the same for me, so i would be glad to hear your take.

I have been trying to get my still images to show on the lovalace interface but its not working like it does through the a browser. Any idea what i’m missing there?

I’ve just been using the Amcrest component. It captures the tripwire easy enough, then I do automation in Node-Red. There is a Dahua pallet in Node-Red but when I tested it my automation stopped working after a short time - seems like it stopped communicating with the camera.

HA does have a bit of delay compared to the Node-Red pallet, but it has been much more reliable.

As far as sending sound files back, I don’t think the integration has anything for it (but would have to check to be sure). If you look up the docs for it though, you might be able to find a URL to post to that could do it.

Quick google uncovered this:

Post #3 has a link to Dahua HTTP API.
Reading down through it I found this on page 94:

So it appears if you post to that address you might be able to play audio… but just a guess… never tried it :slight_smile:.

Good Luck!
DeadEnd