-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Motion Detection events not being received #149
Comments
Hi, thanks for catching details. The integration expects HTTP POST on port 8123 with body like: |
Thanks very much @maciej-or I will do some debugging later in the week and report back my findings. As I learn more, I will also contact HIKVision technical support to see if we can get these misbehaving firmwares modified in due course - if the firmware is the root cause of this issue. I'm hoping that there is some setting somewhere that I don't have correctly set, but that isn't revealing itself readily from the documentation I've read so far. |
I have sought assistance from HIKVision Australia on this issue as it seems that the NVR is not posting events for motion detection or any smart events. I have yet to hear back from them and will keep people updated via this issue until we have a resolution. |
What about hex dump? Did you try to decode that? I see NVRs name and serial no, maybe channel and event type are in the next bytes? You could trigger a couple of events on different cameras and compare the dumps. I theory it would be possible to listen tcp and process binary payload alongside http. |
I have not progressed with analysing the hex dump as yet for a couple of reasons. I found this specification of the ISAPI Core Protocol and have started analysing the hikvision_next code to see which of the three methods are being used for receiving and processing the alarms/events - see Chapter 12 of the protocol specification. From my analysis of the debug log files, I can't find evidence that any of the three specified methods are being used. I would have thought the method defined in section 12.3 Subscribe Alarm/Event in Arming Mode would be the most desirable method, but I could be wrong. @maciej-or can you please clarify which method you have designed the integration to use? |
Hikvision_next uses |
Thanks @maciej-or , this is great. I will see what I can learn and try to get this working - or get clear evidence of a problem with the HIKVision firmware that I can then report to HIKVision. Unfortunately, I have a lot of travel coming up, so my ability to dedicate time to this issue is going to be a challenge, but I'll do my best. |
no worries, no rush, no deadlines in this project :) |
I have made some progress with debugging the cause of this problem. I've implemented some additional debug logging and also aligned the steps to set the alarm server to explicitly align with those documented in the ISAPI Developer Guide for "Receive Alarm/Event in Listening Mode". Specifically this mean't getting the capability set of the HTTP listening server prior to setting the parameters for it by issuing a |
Create a branch from |
A quick note, perhaps this might help someone in the future. Had the same, was not receiving any triggers from the camera for events as the alarm server. Hass runs ons httpS in my case, so I re-added the camera / recorder with https:// in stead of http:// and all great now. I run a "official" signed cert on my hass instance. |
Thanks @matthijsberg In your situation, were you receiving camera feeds and did the sensors and switches for motion detection etc work when you first setup the integration with just http? |
I've been using the |
I'm not able to create a branch in your repo, but have done so in my fork and generated a pull request for you to review. It would be helpful if you could test my changes in your environment to see if you get the same I have attached my |
I was receiving the camera feeds, but not the sensor updates (that is a push config from the camera?) I had some sensors configured the old way (with config file in yaml) and those did give me updates, but when thinking about it, that seems to be a pull config? Perhaps my firewall is playing up here too? (Update: It's IP based, not port based, so this should not have caused the http vs https difference) |
@maciej-or - I have returned to your suggestion to analyse the hex dump data and have used PS: Actually, after thinking this through, This is the error I get when trying to specify https for the alarm server, but still using http for the connection to the NVR.
When I
So, it seems that I'm snookered. Suggestions welcomed. |
I am receiving sensor updates when using HTTP, but these updates all happen because Home Assistant polls the NVR, so I guess Home Assistant is the one initiating the HTTP session with the NVR. You might be onto something about HTTPS. This is not an area of detailed knowledge that I have, but perhaps Home Assistant is only accepting HTTPS sessions on it's 8123 port and when the NVR is the one attempting to initiate a session, it is trying to do so using HTTP. I'll try to do some more analysis, but am quickly running out of time. |
Afaik the plugin creates a Alarm Server (Network / Advanced / Alarm Server) entry that connects to my HASS IP and port number over either http or https. I think this indicates that the camera initiates the connection (need the correct firewall entry) and that Hass needs to accept the connection on the right port number (in my case 8123) over httpS. I run public signed (LetsEncrypt) certificates, and HASS only works over HTTPS in my case (also on my LAN). So HTTPS when first configuring this plugin. Again, not sure this is your issue, but just some pointers. Feel free to ignore. |
I think your on the money here @matthijsberg Thank you for your input, it is definitely helping me get to the bottom of my issue. I also only have HASS working over HTTPS, including on my LAN, and I use LetsEncrypt for the certificate on my HASS machine. I need to work out how to get a certificate for the NVR. I don't want any traffic from the NVR to be going directly outside my LAN. |
You don’t need one, just a valid cert on the server worked for me.
Op di 2 apr 2024 om 19:47 schreef Brad Keifer ***@***.***>
… I think your on the money here @matthijsberg
<https://github.com/matthijsberg> Thank you for your input, it is
definitely helping me get to the bottom of my issue.
I also only have HASS working over HTTPS, including on my LAN, and I use
LetsEncrypt for the certificate on my HASS machine. I need to work out how
to get a certificate for the NVR. I don't want any traffic from the NVR to
be going directly outside my LAN.
—
Reply to this email directly, view it on GitHub
<#149 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AG263BRL7HZJ3HIDELMV6F3Y3L4NVAVCNFSM6AAAAABFFTDAU6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMZSGY4DGNRZGM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Thanks @matthijsberg
If I don't use
I'm lost for ideas on how to resolve this. I recognise that I must find a way to use |
If you let integration to setup alarm server using checkbox 'Set alarm server using following address' it sets HTTP or HTTPS according to URL you pass in following input. Then alarm server should send notifications over proper protocol. |
Suffering from this exact issue. |
No it should not, and in my experience, is not that hard. Configure it as https, point it to port 8123 and go. No firewall in between? |
Here is a simple web server which accepts POST requests and dumps them in files. Maybe it will help debugging that issue. |
I have solved this issue by doing the following:
The reasons I chose to use the reverse proxy are:
So my solution is very much along the lines as proposed by @Mark7714 above. |
Brad,
This is fantastic news. I've installed the NGinx proxy manager to HA but I'm stuck on the next step using this proxy_pass directive. Also searched online on how to do this unsuccessfully. Would you mind giving me the dumb step-by-step?
Super excited to have this working after almost a year of trying.
Thanks
…-------- Original message --------
From: Brad Keifer ***@***.***>
Date: 11/7/24 10:56 am (GMT+10:00)
To: maciej-or/hikvision_next ***@***.***>
Cc: Mark Liardet ***@***.***>, Mention ***@***.***>
Subject: Re: [maciej-or/hikvision_next] Motion Detection events not being received (Issue #149)
I have solved this issue by doing the following:
1. Implemented a nginx reverse proxy to allow the NVR to communicate using http and Home Assistant to communicate using https. I set the alarm server in the Hikvision Next integration to be http://<nginx_hostname>:8124/
2. I configured nginx to listen on port 8124 and then to forward all data onto the external_url: as defined in homeassistant using the proxy_pass directive of nginx
3. I upgraded my NVR firmware to V5.03.010 build 240606
The reasons I chose to use the reverse proxy are:
1. I did not want to spend money to buy a certificate for the NVR
2. My Raspberry Pi, running Home Assistant containerised, would not accept https connections using self-signed certificates and I could not work out how to make the NVR self-signed certificate trusted by both the Raspberry Pi and the Docker image.
3. Even though I tried defining a http internal_url, my Home Assistant instance would not accept http connections via this internal_url.
So my solution is very much along the lines as proposed by @Mark7714<https://github.com/Mark7714> above.
—
Reply to this email directly, view it on GitHub<#149 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AHMVNKQOLE4LWFR7TZQEHADZLXJ5JAVCNFSM6AAAAABFFTDAU6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMRRG44DKNRQGI>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
I'd be happy to help @Mark7714 |
*NB posted those from a different account. |
I suspect you can put pure nginx configurtion into the advanced tab. Try putting this in:
Replace everything between the <> brackets (including the brackets) with the appropriate hostnames and IP addresses for your configuration. The If you have problems, please send me a screen shot of what you have entered into the Custom Nginx Configuration and also a screenshot of the |
Thanks. I have now got the redirect in place from http://<LOCAL_IP> to https://my.domain.com and it looks like its working. It also doesnt seem to trigger MFA when it goes to the /api/hikvision path. But my alarms aren't triggering. I upgraded the NVR firmare to the latest I could find. |
I've only configured and tested motion detection. Perhaps try that to see if it works? @Mark7714 if you can get to a shell in HASSIO, check the nginx access log. If you look at the configuration files (which will probably be somewhere under /etc/nginx, you might be able to see where the access log is maintained. The default is /var/logl/nginx/access.log If you can find that, it will show whether there has been exchange between the NVR and nginx. Below is an extract from my log for one motion detection event:
|
I found a tonne of these. Do they look healthy? [12/Jul/2024:18:04:01 +1000] 301 - POST http xx.xx.xx.xx "/api/hikvision" [Client HIK_NVR] [Length 162] [Gzip -] "HTTP_USER_AGENT" "-" |
I am not sure @Mark7714 I guess the good news is that this log is indicating that the nvr is sending data and it is being received by nginx. Perhaps have a look at the nginx error log to see if it gives you anything helpul. Mine is at /var/log/nginx/error.log Are you using two different port numbers? One for communication between nginx and the nvr and then 8123 between nginx and home assistant? |
I have followed the installation instructions and am not receiving motion detection events in Home Assistant. I have validated that the motion detection events are being successfully triggered by the IP cameras (because they are triggering strobe light and audio output on motion detection) and the NVR is recording the events. I have also tried a simple test of redirecting the Alarm Host Port to port 8124 and listening for data using the command "nc -kl 8124" on the raspberry pi that hosts Home Assistant. This receives a combination of binary and ascii data that seems to correspond to the beginning and the end of the motion detection event. I have attached a hex dump of that output.
Details of my devices are:
NVR: DS-7616NI-M2 / 16P
IP Cameras: DS-2CD2387G2H-LISU/SL
config_entry-hikvision_next-74c4ee8d1c755eb59af285a77b41ed7d.json
home_assistant.log
hd.txt
I am happy to assist with fixing and/or testing to resolve this issue, but am new to HIKVision devices so am on a steep learning curve, but happy to learn.
The text was updated successfully, but these errors were encountered: