IpCamera: New IP Camera Binding

Hello, any chance people with Dahua cameras who confirmed this is working for them will also post firmware version from their cameras? This is still not working for me on Dahua IPC-HDBW4231F-AS with firmware V2.800.0000008.0.R
I set the log level to TRACE on the binding, but I’m not seeing reply from camera and for example for line crossing enable / disable I’m not seeing request from openhab to camera neither.

I cleaned cache and TMP folder after binding upgrade, so I would like to know if this should be somehow related to firmware version.

Thanks!

My guess is, this is a communication issue… Make sure you got the IP correct.

That could be explained if you made a typo error on the channel linking. The binding would never get the command if the link was not made correctly. Check in paper ui under the control tab if the control does not show up it means it is not linked

@pastynko
Edit:
Two things on further Thought. I believe it is a typo otherwise you would see the request go out from the binding to the camera, but the following may help u narrow it down.

  1. See readme on the special apiAccess channel. You can use that to test if the correct api call triggers the camera to change settings.

  2. There is an issue in my Amcrest camera (which appears to be dahua firmware) turning normal motion on and off. Rolling back firmware solved it for me. There are a number of people on the home assistant forum also complaining of this. If this is the cause then contact your camera support.

Hello,

I created things and items files manually and now it seems to be working, sort of. What I want is Cross Line Detection, but this part is not working for me. I’ve looked into your github repository and to my noob eyes it looks like there is missing call to enable / disable LineCrossingDetection. I’ve created a fork of your git and added the call there but I was unable to compile the jar file so far (trying for first time and Java is not something I’m familiar with :smiley:)

Any chance you can have a look?
I found out the request to enable LineCrossingDetection for my camera (Dahua IPC-HDBW4231F-AS) should be IPADDRESS/cgi-bin/configManager.cgi?action=setConfig&VideoAnalyseRule[0][1].Enable=true
Also to get the config, I have to use IPADDRESS/cgi-bin/configManager.cgi?action=getConfig&name=VideoAnalyseRule[0][1] because when I try the url from your binding IPADDRESS/cgi-bin/configManager.cgi?action=getConfig&name=CrossLineDetection[0] I get Error Bad Request

I will let you know if I will succeed. Thanks for your help so far.

Your easy fix is the api access Chanel.
If you want to build it try using ‘mvn clean compile package’ to skip the checks that cause it to fail.
I will take a look at the code tomorrow so if you test what does work from api access channel or any browser I can look at including it.

Looks like I compiled the jar somehow and I’m able to enable / disable CrossLineDetection now. I need to test it little bit more, hopefully tomorrow. Btw, I can send you Dahua HTTP API v2.76 (latest I was able to find), which will probably help you more than me :smiley:

Thanks for reporting, looks like I forgot to paste some code across when I was making it easier to read.

Can you test this url in a browser please and post the output it gives or send via PM? This is used to make sure the control is displayed correctly On vs off when openhab starts up…

/cgi-bin/configManager.cgi?action=getConfig&name=VideoAnalyseRule

I think it is little bit too long, so I will PM it to you

@matt1
If you like to, you can add Hikvision DS-2CD2T46G1-4I/SL as a working camera. Two of them are running properly for months now with all recent versions of your binding.

I love your binding. Thanks for putting so much work into it.

2 Likes

Hi, I tested your updated code and it is partly working. I’ve got 4 cameras, first request for each camera is working (enable linecrossing or disable / enable motion), when I try second request, the binding does nothing. Let me explain:
I hit switch to enable motionDetection -> I can see in the log TRACE … the request, but I don’t see any reply from camera in the TRACE log (in a browser the camera reply with OK, or bad request if the request isn’t correct…)
I hit the same switch again to disable motionDetection -> nothing in the log from the binding

I can do this for each camera…
Any idea what could be wrong or what to look for?

Maybe problem with me, compiling the jar?

So, I have been using this binding for quite some time now, for motion events. I have Dahuas and Hikvisions, and different types of motion work just great. (Mostly using line, area and motion).

However, would like to enhance this now, to also store (atleast) one picture of the actual motion event, and present it in basic UI.
I have my test Dahua set-up as follows;

POLL_CAMERA_MS=10000,
SERVER_PORT=50004,
IMAGE_UPDATE_EVENTS=2,
UPDATE_IMAGE=true,

I read in the oh log, that the image is pulled from the camera on motion, but item image channel is not updated. Should it not do this? Or do I have to do this from a rule? Obviously this is why my picture in basic ui is never updated.
I have read the docs many times now, and I suspect it is too many options for me… :slight_smile: Most examples seems to be about having the image update continuously, something that I’m not interested in.
Not even sure if I should use the image channel for this purpose, but I think I should.

I do not have each camera in my sitemap, only the camera group.
Group item=gCameras

And for this test cam, items;

Image  FrontCamImage            "Framsidekamera"               (gCameras)                {channel="ipcamera:DAHUA:frontside_cam:image"}
    Switch FrontCamUpdateImage      "Framsida Ta ny bild"          (gCameras)                {channel="ipcamera:DAHUA:frontside_cam:updateImageNow"}
    Switch FrontCamCrossing         "Framsida linje"               (gPersist,gCameras)       {channel="ipcamera:DAHUA:frontside_cam:lineCrossingAlarm"}
    Switch FrontCamMotion           "Framsidekamera rörelse"       (gPersist,gCameras)       {channel="ipcamera:DAHUA:frontside_cam:motionAlarm"}
    Switch FrontCamFaceDet          "Framsidekamera ansiktesdet"   (gPersist,gCameras)       {channel="ipcamera:DAHUA:frontside_cam:faceDetected"}
    Switch FrontCamIntrusion        "Framsidekamera område"        (gPersist,gCameras)       {channel="ipcamera:DAHUA:frontside_cam:fieldDetectionAlarm"}
    String FrontsideCamLastEvt      "Framsidekamera senaste"       (gCameras)                {channel="ipcamera:DAHUA:frontside_cam:lastMotionType"}
    Dimmer FrontsideCamIR           "Framsidekamera IR ljus"       (gCameras)                {channel="ipcamera:DAHUA:frontside_cam:enableLED"}
    DateTime FrontsideCamLastMotion "Framsidekamera tidpunkt [%1$tH:%1$tM %1$tY-%1$tm-%1$td]"  (gCameras)
    Switch FrontsideCamMotionEnable "Framsidekamera rörelsedetektering" (gCameras)           {channel="ipcamera:DAHUA:frontside_cam:enableMotionAlarm"}

What am I doing wrong?
Sorry for the very basic question, but I think I have turned blind to the solution now…

Hi, would you mind sharing model number and firmware version of your Dahua cameras?

Thanks!

Model number IPC HFW4433F-ZSA, China version. Don’t know the fw version, but they are about 8 month old. I never dare to update China versions…

Also, as I have been studying ipcam-binding logs for a while now, both my Hik’s (different models and fw), spams the log with these messages;

17:13:18.215 [TRACE] [ding.ipcamera.handler.IpCameraHandler] - DefaultHttpContent(data: PooledSlicedByteBuf(ridx: 0, widx: 562, cap: 562/562, unwrapped: PooledUnsafeDirectByteBuf(ridx: 562, widx: 562, cap: 8192)), decoderResult: success)
17:13:18.216 [TRACE] [ding.ipcamera.handler.IpCameraHandler] - HTTP Result back from camera is  :--boundary
Content-Type: application/xml; charset="UTF-8"
Content-Length: 479

<EventNotificationAlert version="2.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
<ipAddress>10.1.200.19</ipAddress>
<portNo>80</portNo>
<protocol>HTTP</protocol>
<macAddress>bc:ad:28:3b:88:73</macAddress>
<channelID>1</channelID>
<dateTime>2020-05-14T17:24:28+01:00</dateTime>
<activePostCount>0</activePostCount>
<eventType>videoloss</eventType>
<eventState>inactive</eventState>
<eventDescription>videoloss alarm</eventDescription>
</EventNotificationAlert>
:

About 5 every second from one of the cameras. The other one seems to send less frequent.

I looked in the camera settings if it is possible to disable video loss alarms, but I can’t find a setting that I connect with this event.

Could it be that this needs to be ack’d from the binding somehow? If I reboot the cameras while binding/oh is running, they stop with this for a while, but if I e.g. restart ipcamera binding, it seems to come back.
Not a very big deal unless one is studying the log, I guess.

New build 2020-05-16 has these changes which include BREAKING CHANGES.

  • Channel controlMotionAlarm is now changed to ffmpegMotionControl the operation is the same so just do a find and replace and everything will work the same. If you were not using the ffmpeg motion detection you wont notice the change.
  • ffmpegMotionControl should now work on all brands of cameras hence the renaming to prevent confusion with cameras built in motion alarm controls. Idea is that if you want a particular sensitivity on your cameras motion to stop and start recordings, you can use a secondary motion detection that is more sensitive to skip the order of the cameras in a group view.
  • ffmpeg motion detection was broken in builds for the past few weeks, this version fixes and improves the feature.
  • Bug fixes for the image channel @vespaman these should help you.

Try using IMAGE_UPDATE_EVENTS=2, UPDATE_IMAGE=false,

Currently if you turn on the update image channel now to ON it will update the image every poll period, If you have the channel OFF it will only update it on the start of a motion event. If using ffmpeg to generate the snapshots the control needs to be on.

Also I would recommend looking at the GIF feature, you could trigger this when motion occurs and then display the GIF in your Habpanel or sitemap. A picture that moves and keeps looping showing the last motion.

Thank you @matt1 the last version works just out of the box! I’ll take a look at the GIF way now, as per your recommendation (did not want to make things even more complicated before getting the basics to work)!

Cheers,
Micael

Glad it works and u find it useful.
Regarding your other post the video loss messages are normal can not be turned off and are simply how the camera tells devices that there are no alarms at all occurring. You can use debug log mode to watch what occurs without getting the replies back from the camera.

1 Like

@matt1 I installed the binding a week ago and it runs perfect on multiple cameras. Have played with GIF notifications to telegram and now ended up with recording 10sec MP4 files as notification.

In this process it seems that MP4 recording does not work for cameras with NO AUDIO stream. For these cameras the binding creates an empty mp4 file. I traced the error back to the use of ffmpeg option “-acodec copy” and replaced it by option “-an” in case of missing audio. Looking at the very detailed readme file (thanks for this good description!) the ffmpeg use in the binding has similar problems in the HLS part of the binding where you use “-acodec aac” as fallback solution for both cameras with/without audio stream. This works in my case as well.

Please fix this in the mp4 recording routine or allow for external setting of ffmpeg parameters as in case of the HLS routine. Hope this helps to fix the (as I understood experimental) feature of mp4 recording, it is great replacement of GIF notifications for me. Thanks a lot for all your effort!

1 Like

Thanks for the heads up that no audio cameras have issue, will look at that soon. The main hold up on finishing this feature is I wish to use the HLS stream as a source for the preroll footage so you can have footage from before the triggering event, just like the gif can do. This may mean all the footage will have to share the HLS settings so there is no glitch when the recording passes from the preroll into realtime. I will probably also add a new config to store the recordings in a separate folder so the HLS can be in volatile ram and the recordings to disk.

This is the reason it is labelled as experimental as things are likely to change, but it is useful in the meantime for people to provide feedback on how it should work. It should be reliable already as it’s using proven code and ffmpeg for the heavy lifting.

Agree with you, PREROLL would be a cool additional feature for MP4 recording! However, as this is available for GIF there are some problems with network traffic in case of preroll already. Continuously polling data from all ipcams makes network health degenerate quite soon, at least if you have more than one ipcam as in my setting. If this can be reduced by using more condensed HLS compared to the current snapshot solution, I would be in favor of this. Think of use cases with multiple cameras this preroll might become a bottleneck for the network, memory and cpu at the end.

Hence, maybe more interesting features would be to include more camera-side functionalities into the binding. Given your future work statement on onvif motion detection, maybe there is more to think of indirectly getting video files from a NVR/FTP/other server solutions on which the camera pushes the videos with low-latency motion detection instead of introducing the continuous pull-solution to overcome latency issues with openhab.

Ideal solution:
cam --push–> ftp-server --pull–> openhab (triggered by onvif motion event on the cam)

This might be preferred over continuous pull with snapshots and local/remote filesystem at the end of the pipeline:
cam --pull–> openhab --push–> filesystem

What do you think can there be a lightweight solution that uses onvif motion detection as trigger for the push of the camera or do we need costly pull solutions for preroll? At least some cameras allow pushing to ftp servers, but in general this is not true, hence maybe poll solution might cost more but at the same time fit all ipcams?