Setting up NVR-based Reolink cameras

Summary: Is there a way to setup NVR-based Reolink cameras with the IP Camera Binding to handle camera-based motion detection events (i.e., without FFMPEG)?

Desired configuration: The Reolink motion detection is pretty good; however, the builtin push notifications are excessive and don’t provide a thumbnail of the motion frame for easy spot checking. So, I’d like to pipe the Reolink motion detection events into Openhab and use a rule to manage the frequency of push notifications and include a still (of gif) of the motion event. I’d prefer not to use FFMPEG as I’m currently running Openhab on a RaspberryPi 3 and am already pushing the limits on its capabilities.

**Details **
I’ve been digging for a while now and can’t seem to setup the IpCamera binding quite the way I’d like. Here is the hardware that I have.

  • Reolink RLN8-410 NVR
  • Reolink RLC-810A cameras
  • Reolink RLC-820A cameras
    I’ve seen in the primary IP Camera community thread and some of the other threads that people have been able to successfully setup Reolink cameras via the ONVIF option. However, I believe these are cameras directly hooked up to the network, rather than through an NVR. It also isn’t clear to me if camera-based motion detection events is possible.

I’ve found documentation regarding the Reolink API here and here. I’ve been able to hard code the snapshot URL thus far and that seems to work: http:///api.cgi?cmd=Snap&channel=0&rs=ABCDEFG&user=&password=. There is also a GetMdState command that provides the status on motion detection for a particular camera channel on the NVR: http:///api.cgi?cmd=GetMdState&channel=0&rs=ABCDEFG&user=&password=. Is there a way to integrate this into the current IP Camera binding?

Thoughts? Thanks!

As you mention, this works for others when talking directly to the camera and its possible your NVR is blocking this. NVRs usually create a private network for the cameras and usually that is the desired effect, to isolate them from the rest of the network to improve security. Hikvision make a range of NVRs that allow you to directly talk to each camera on separate ports whilst they are behind the NVR, not sure if Reolink have that feature, but its not a common feature in other brands and why people consider using Hikvision over others. Also a reason why some like to roll their own NVR with their own hardware and software.

There are other ways to do this, one of them is if the camera supports FTP uploads when motion occurs is the ‘ftp upload’ binding. It can throw a motion switch when the ftp site gets the upload from the camera.

Great news that it has an API and that you have tested it to work. I took a quick look and it does not look very hard to add this to the binding. Are you able to add it? The documentation is lacking IMHO as it does not fully explain the token creation and renewing process, nor what the channel numbers are…
ie does channel=0 work on a stand alone camera? what does it show when on the NVR? Is channel 1 the first or second channel on the NVR as its common to start counting at 0 and not 1.

Thanks for all of the input.

As you mention, this works for others when talking directly to the camera and its possible your NVR is blocking this. NVRs usually create a private network for the cameras and usually that is the desired effect, to isolate them from the rest of the network to improve security.

I’m reasonably certain that is the case here (and is why I went with the NVR setup). The only way to communicate with the cameras appears to be through the CGI API.

There are other ways to do this, one of them is if the camera supports FTP uploads when motion occurs is the ‘ftp upload’ binding. It can throw a motion switch when the ftp site gets the upload from the camera.

I’ll have to look into this more and there appears to be an FTP uploads option when motion occurs https://support.reolink.com/hc/en-us/articles/360004083873. This is probably the easiest solution for now. I’ll look into this a little more and report back.

Great news that it has an API and that you have tested it to work. I took a quick look and it does not look very hard to add this to the binding. Are you able to add it?

I’ll poke around into the binding and see if I can figure out how to add something. I haven’t done any binding work in openhab, and it has been a while since I coded in Java, so it might take me a little while to piece something together.

The documentation is lacking IMHO as it does not fully explain the token creation and renewing process

Agreed. It does appear that Reolink is trying to improve this, but it is still rather cryptic and lacking at times. The token doesn’t appear to be required. I’ve been able to interact with the cameras by sending a username and password in the URL. This isn’t ideal from a security standpoint, but works for now.

nor what the channel numbers are… ie does channel=0 work on a stand alone camera? what does it show when on the NVR? Is channel 1 the first or second channel on the NVR as its common to start counting at 0 and not 1.

The channel number is just the port that the camera is hooked up to on the NVR. I’ve seen references to NVR channel in the IP documentation, but it doesn’t appear when I try to define the thing through the UI.

If your keen to take it on, I can do 80% of the work needed in a few hours saving you from needing to learn how the binding works. What I can not do easily is test since I do not have any Reolink here. What you should do is take a look at how FOSCAM has been implemented, as they use a polling method where the binding has to keep asking the camera over and over if any events have occurred. Foscam also uses the user/pass in plain text in the GET requests.

See this file here to see if your java comes easily when reading this:

openhab-addons/FoscamHandler.java at main · openhab/openhab-addons (github.com)

Only some of the brands have that show up, Its easy to create a new thing type called reolink and have the ability to specify a nvr channel in the setup for the thing. That’s the sort of thing I can do in a few minutes to save you learning. I created the binding in a way that allows most of what is done for a brand to be in a single file to make it easy for people to read and fix bugs without knowing the full binding and it makes it easier for me to maintain.

If your keen to take it on, I can do 80% of the work needed in a few hours saving you from needing to learn how the binding works.

I’m willing to take it on. The FOSCAM code seems pretty straight forward (although those are often famous last words). Seems like we can keep most of the structure and just update the CGI syntax and result parsing. I’ll start working through the developers guide. While I’m working on that, do you want to take an initial stab the new Reolink handler class? I can then use that as a base line to troubleshoot/debug.

hi, i’m using Reolink too. Camera, not NVR.
per onvif I get only the motion detection signal.
Somewhere in the internet i found a list for the api commands and i use the http binding for polling a person alarm state.

IPofCam/api.cgi?cmd=GetAiState&channel=0&user=aaaa&password=aaa
JSONPATH:$.[0].value.people.alarm_state

Reolink E1 Outdoor cam api output:

[
   {
      "cmd" : "GetAiState",
      "code" : 0,
      "value" : {
         "channel" : 0,
         "face" : {
            "alarm_state" : 0,
            "support" : 0
         },
         "people" : {
            "alarm_state" : 0,
            "support" : 1
         },
         "vehicle" : {
            "alarm_state" : 0,
            "support" : 1
         }
      }
   }
]

Maybe this is helping you…
Greets

1 Like

Thanks for the info. I hadn’t thought to look into using the HTTP binding. I think I’m going to continue to pursue the IP Camera Binding option right now as I’m interested in some of its built in features, but might use this as a fall back.

At what rate do you have to poll to make sure you don’t miss an event?

Every 3 seconds.
It’s enough for me…
I use both… Ptz preset is working fine with ipcamera binding… And the snapshot and video stream…
I use the http binding just for person detection.

For anyone that comes across this thread, I can confirm that you can use the HTTP Binding to poll the AI state with an NVR system. To access different cameras on the NVR, you simply need to change the channel reference accordingly: IPofCam/api.cgi?cmd=GetAiState&channel=0&user=aaaa&password=aaa. I should note that, you need to have the firmware v3.0.0.148_21101146 or above installed on your NVR. Prior to that, the AI option doesn’t work through the API.

One of the downsides of this approach, is that you username and password are stored in raw format within the Thing definition. There is likely a way around this, but I haven’t delved too deep into it.

@DieterK has added that functionality to the IP Camera binding and we are just waiting for a PR to be done, you can read his post here on it…

Onvif camera error message - Add-ons / Bindings - openHAB Community

It is far better to use the ONVIF methods as they are event based and the events get pushed to the binding, where how your doing it with the http binding is polling and not as good as event based methods. If you place the binding into DEBUG level logging it will tell you if the camera is reporting events that the binding does not have implemented and if you post this info, it can be added very easily.

@azureshammer Let me know when your able to compile the code and create a jar. I think the best way forward would be to use ONVIF if the dvr channel is 0, and for numbers above this, it could switch to polling so people get the best of both worlds. But this requires someone to test that actually has a camera. I would not be surprised if the API polling has added benefits and extra features. For example with Dahua and Hikvision if you get a Line Crossed alarm, the API can tell you which direction the line was crossed so you know if someone if walking towards or away from your home.

Hi Skinah,

good news!

Reolink managed to fix the issue and i was able to positivly verify the behaviour (i.e. camera is stable now).

Up to now there’s no offical build yet, i received the new FW via email.

I raised a question on when they plan to release new FW, will share any update as soon as available.

Not so good, i’m bit behind on what i stated earlier, i.e. sharing the changes at the weekend …

Will do my very best to come up with those next weekend.

Best regards,

Dieter

1 Like

I don’t know anything about reolink but I have noticed that there is a working solution for home assistant, might give you some ideas on how to integrate it.

Hi there, I’m using a Reolink E1 outdoor (no NVR) and I would be happy to provide a debug log. Unfortunaly I’m currently stuck with OH 3.0.2 as I need to fix a backup issue. Let me know if this (OH 3.0.2) isn’t an issue.

I tried the debug log.
I reinitializied the Thing and walked in Front of the cam…

2022-07-08 19:10:42.086 [DEBUG] [amera.internal.onvif.OnvifConnection] - Cameras  UTC dateTime is:2022-7-8T17:10:43
2022-07-08 19:10:42.087 [DEBUG] [amera.internal.onvif.OnvifConnection] - Openhabs UTC dateTime is:2022-07-08T17:10:42.086Z
2022-07-08 19:10:42.185 [DEBUG] [amera.internal.onvif.OnvifConnection] - deviceXAddr:http://192.168.0.178:8000/onvif/device_service
2022-07-08 19:10:42.186 [DEBUG] [amera.internal.onvif.OnvifConnection] - eventsXAddr:http://192.168.0.178:8000/onvif/event_service
2022-07-08 19:10:42.186 [DEBUG] [amera.internal.onvif.OnvifConnection] - mediaXAddr:http://192.168.0.178:8000/onvif/media_service
2022-07-08 19:10:42.186 [DEBUG] [amera.internal.onvif.OnvifConnection] - ptzXAddr:http://192.168.0.178:8000/onvif/ptz_service
2022-07-08 19:10:42.345 [DEBUG] [amera.internal.onvif.OnvifConnection] - GetStreamUri:rtsp://192.168.0.178:554/
2022-07-08 19:10:42.555 [DEBUG] [amera.internal.onvif.OnvifConnection] - GetSnapshotUri:/cgi-bin/api.cgi?cmd=onvifSnapPic&channel=0
2022-07-08 19:10:42.608 [DEBUG] [amera.internal.onvif.OnvifConnection] - ptzNodeToken=000
2022-07-08 19:10:42.678 [DEBUG] [amera.internal.onvif.OnvifConnection] - subscriptionXAddr=http://192.168.0.178:8000/onvif/PullSubManager?Idx=00_1
2022-07-08 19:10:42.700 [DEBUG] [amera.internal.onvif.OnvifConnection] - Processing new PTZ location now
2022-07-08 19:10:42.700 [WARN ] [amera.internal.onvif.OnvifConnection] - Binding could not determin the cameras current PTZ location. Not all cameras respond to GetStatus requests.
2022-07-08 19:10:42.753 [DEBUG] [amera.internal.onvif.OnvifConnection] - ptzConfigToken=000
2022-07-08 19:10:43.985 [DEBUG] [amera.internal.servlet.CameraServlet] - Now there are 0 autofps.mjpeg streams open.
2022-07-08 19:10:43.985 [DEBUG] [amera.internal.servlet.CameraServlet] - All autofps.mjpeg streams have stopped.
2022-07-08 19:10:56.436 [DEBUG] [amera.internal.onvif.OnvifConnection] - Onvif Event Topic:RuleEngine/CellMotionDetector/Motion, Data:IsMotion, Value:true
2022-07-08 19:10:56.512 [DEBUG] [amera.internal.onvif.OnvifConnection] - Onvif Event Topic:RuleEngine/CellMotionDetector/Motion, Data:IsMotion, Value:true
2022-07-08 19:10:56.591 [DEBUG] [amera.internal.onvif.OnvifConnection] - Onvif Event Topic:RuleEngine/CellMotionDetector/Motion, Data:IsMotion, Value:true
2022-07-08 19:10:56.661 [DEBUG] [amera.internal.onvif.OnvifConnection] - Onvif Event Topic:RuleEngine/CellMotionDetector/Motion, Data:IsMotion, Value:true
2022-07-08 19:10:56.741 [DEBUG] [amera.internal.onvif.OnvifConnection] - Onvif Event Topic:RuleEngine/CellMotionDetector/Motion, Data:IsMotion, Value:true
2022-07-08 19:10:56.791 [DEBUG] [amera.internal.onvif.OnvifConnection] - Onvif Event Topic:RuleEngine/CellMotionDetector/Motion, Data:IsMotion, Value:true
2022-07-08 19:10:56.841 [DEBUG] [amera.internal.onvif.OnvifConnection] - Onvif Event Topic:RuleEngine/CellMotionDetector/Motion, Data:IsMotion, Value:true
etc
. 
. 
. 

Just only the CellMotion Event.
In the http binding I saw person alarm…
Do I need to link an item? Or are all onvif Events logged? I have linked only cellmotion alarm to an item.
Maybe trace log?

NO, the logs will show any event that the camera sends exactly as you have shown. This means the camera has to recognize a person to send the event and for it to show up in the logs. Some cameras are slow and not reliable at detecting a person so give it some more time standing in front of the camera without wearing a cap/hat.

Great but that will be using the API method and not using ONVIF method. The ONVIF method is better as it is using the PUSH method, whereas the API is using the POLLING method. If you camera can only send it via the API (perhaps that is the case or you have an older firmware) then that is another reason to implement the API into the IP Camera binding which is very easy to do and sounds like we have a few users that are keen to look at it.

That would be great if you can contribute those soon as I will hold off making any changes until yours are made so that we can prevent any merge conflicts that may happen.

Hi Skinah,

unfortunately i’m struggling getting access to the repo, something seems to be wrong with the token.

To make it short, attached below the changes i made compared to the 3.2 release version.

Sorry for inconvinience!

Best regards,

Dieter

diff --git a/bundles/org.openhab.binding.ipcamera/pom.xml b/bundles/org.openhab.binding.ipcamera/pom.xml
index 432be60edb…606031fa4c 100644
— a/bundles/org.openhab.binding.ipcamera/pom.xml
+++ b/bundles/org.openhab.binding.ipcamera/pom.xml
@@ -1,4 +1,6 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>

hi, me again.
I wanted to try the Onvif Events with “Onvif Device Manager”.
I was not able to get a subscription for the Onvif Events , “400 Bad Request”.
After a reboot of the Cam I got a connection with Onvif Device Manger.
But there are also no Person Alarms… Just CellMotionAlarm… damn
I tried Trace Log from the Ipcambinding and found the following:

Sending ONVIF request:Unsubscribe
2022-07-09 19:35:14.156 [TRACE] [amera.internal.onvif.OnvifConnection] - Onvif reply is:<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsdd="http://schemas.xmlsoap.org/ws/2005/04/discovery" xmlns:wsa5="http://www.w3.org/2005/08/addressing" xmlns:xmime="http://tempuri.org/xmime.xsd" xmlns:xmime5="http://www.w3.org/2005/05/xmlmime" xmlns:xop="http://www.w3.org/2004/08/xop/include" xmlns:wsrfbf="http://docs.oasis-open.org/wsrf/bf-2" xmlns:tt="http://www.onvif.org/ver10/schema" xmlns:wstop="http://docs.oasis-open.org/wsn/t-1" xmlns:wsrfr="http://docs.oasis-open.org/wsrf/r-2" xmlns:ns1="http://www.onvif.org/ver10/actionengine/wsdl" xmlns:tev="http://www.onvif.org/ver10/events/wsdl" xmlns:ns10="http://www.onvif.org/ver10/events/wsdl/PullPointBinding" xmlns:ns11="http://www.onvif.org/ver10/events/wsdl/CreatePullPointBinding" xmlns:ns12="http://www.onvif.org/ver10/events/wsdl/PausableSubscriptionManagerBinding" xmlns:ns13="http://www.onvif.org/ver10/network/wsdl/RemoteDiscoveryBinding" xmlns:ns14="http://www.onvif.org/ver10/network/wsdl/DiscoveryLookupBinding" xmlns:tdn="http://www.onvif.org/ver10/network/wsdl" xmlns:ns3="http://www.onvif.org/ver20/analytics/wsdl/RuleEngineBinding" xmlns:ns4="http://www.onvif.org/ver20/analytics/wsdl/AnalyticsEngineBinding" xmlns:tan="http://www.onvif.org/ver20/analytics/wsdl" xmlns:ns5="http://www.onvif.org/ver10/events/wsdl/PullPointSubscriptionBinding" xmlns:ns6="http://www.onvif.org/ver10/events/wsdl/EventBinding" xmlns:ns7="http://www.onvif.org/ver10/events/wsdl/SubscriptionManagerBinding" xmlns:ns8="http://www.onvif.org/ver10/events/wsdl/NotificationProducerBinding" xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2" xmlns:ns9="http://www.onvif.org/ver10/events/wsdl/NotificationConsumerBinding" xmlns:tad="http://www.onvif.org/ver10/analyticsdevice/wsdl" xmlns:tds="http://www.onvif.org/ver10/device/wsdl" xmlns:timg="http://www.onvif.org/ver20/imaging/wsdl" xmlns:tls="http://www.onvif.org/ver10/display/wsdl" xmlns:tmd="http://www.onvif.org/ver10/deviceIO/wsdl" xmlns:tptz="http://www.onvif.org/ver20/ptz/wsdl" xmlns:trc="http://www.onvif.org/ver10/recording/wsdl" xmlns:trp="http://www.onvif.org/ver10/replay/wsdl" xmlns:trt="http://www.onvif.org/ver10/media/wsdl" xmlns:trv="http://www.onvif.org/ver10/receiver/wsdl" xmlns:tse="http://www.onvif.org/ver10/search/wsdl" xmlns:ter="http://www.onvif.org/ver10/error" xmlns:tns1="http://www.onvif.org/ver10/topics" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><SOAP-ENV:Body><SOAP-ENV:Fault SOAP-ENV:encodingStyle="http://www.w3.org/2003/05/soap-encoding"><SOAP-ENV:Code>
<SOAP-ENV:Value>SOAP-ENV:Sender</SOAP-ENV:Value></SOAP-ENV:Code>
<SOAP-ENV:Reason><SOAP-ENV:Text xml:lang="en">Method 'Unsubscribe' not implemented: method name or namespace not recognized</SOAP-ENV:Text></SOAP-ENV:Reason></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>

2022-07-09 19:35:16.185 [DEBUG] [amera.internal.onvif.OnvifConnection] - Eventloop is shutdown:true

is it possible that the "Method ‘Unsubscribe’ not implemented: " didnt let me subscribe to the Onvif Events with ‘Onvif Device Manager’? Was it locked by the ipcamerabinding?
I hope you know what I’m talking about :blush:

@matt1 I’m out of town right now, but will compile everything and test it out when I get back in a week or so.

@matt1 So, I’ve got the code setup, compiling, and creating the jar file.

1 Like

Hi Skinah,

have you been able to merge my changes into the code?

Sorry again for just sending the diffs, i’ve been traveling till now :frowning:

Kind regards,

Dieter