With NVR, AI events (person, pet, etc) only seem to work with first camera channel (and unreliably)
mattdm opened this issue · 7 comments
Describe the bug
I have an 8-port NVR with five cameras. Motion events seem to be returned from all cameras (although not reliably, as there are many periods of "became unavailable"). All cameras have sensors for Person, Pet, Vehicle as appropriate, but only the one on the first channel ever seems to be triggered.
And, that one that does sometimes work also misses events -- for example, the Reolink event shows events this morning at 7:01:28, 7:07:09, 7:10:47, and 10:43:17. Home Assistant only shows 7:01:35 (and off a minute and one second later). (It does not show "unavailable", although yesterday evening it was unavailable for five minutes.)
To Reproduce
Intrinsic with the setup, I guess?
Expected behavior
I'd expect AI events to work from all devices, and reliably.
Screenshots
Environment:
Home Assistant: 2023.4.2 (container)
NVR: RLN8-410 (N3MB01), firmware v3.3.0.226_23031609
Cameras:
- Front Stairs, Side Corridor: RLC-510A
- Front Door, Backyard: RLC-842A
- Front Eagle Eye: Duo 2 PoE
Additional context
With some sadness, I set up nginx to allow access to /api/webhook
over http, and set the return URL as an http one. All other paths get redirected to https.
I have debug logging on for reolink_aio.api, but of course it's a lot. I can send you whatever might be useful.
@mattdm first of all thank you very much for sponsering, that is amazing!
Do you see Webhook 'reolink_xxxxxxxxxxxx_ONVIF' called
in your debug log?
If you are okay with it, you can just post the .log file here and I can have a look.
That would confirm the camera is able to reach your HomeAssistant instance.
There is currently a bug in my code wich causes events to be lost during processing due to the camera disconnecting before the data is beeing read giving a ConnectionResetError. This PR home-assistant/core#91070 will fix that, but I am still working on it. Hopefully it will be available in HA 2023.4.3 in a few days.
@mattdm first of all thank you very much for sponsering, that is amazing!
Yeah — thanks for working on this!
Do you see
Webhook 'reolink_xxxxxxxxxxxx_ONVIF' called
in your debug log? If you are okay with it, you can just post the .log file here and I can have a look. That would confirm the camera is able to reach your HomeAssistant instance.
I don't see that.... I have this:
2023-04-10 04:11:44.489 DEBUG (MainThread) [reolink_aio.api] Host nvr.example.org:443: subscription request data:
<soap:Envelope xmlns:add="http://www.w3.org/2005/08/addressing" xmlns:b="http://docs.oasis-open.org/wsn/b-2" xmlns:soap="ht
tp://www.w3.org/2003/05/soap-envelope">
<soap:Header>
<add:Action>http://docs.oasis-open.org/wsn/bw-2/NotificationProducer/SubscribeRequest</add:Action>
<wsse:Security soap:mustUnderstand="true" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssec
urity-secext-1.0.xsd"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-#####">
<wsse:Username>admin</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#Pas
swordDigest">#####</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0
#Base64Binary">#####</wsse:Nonce>
<wsu:Created>2023-04-10T04:11:44.000Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soap:Header>
<soap:Body>
<b:Subscribe>
<b:ConsumerReference>
<add:Address>http://smart.example.org/api/webhook/reolink_ec71db5b4347_ONVIF</add:Address>
</b:ConsumerReference>
<b:InitialTerminationTime>PT15M</b:InitialTerminationTime>
</b:Subscribe>
</soap:Body>
</soap:Envelope>
(with tokens/passwords sanitized, I hope)
followed by
2023-04-10 04:11:44.535 DEBUG (MainThread) [reolink_aio.api] Host nvr.home.mkmiller.org:443: subscription got response status: 200. Payload:
(With a similar payload.)
I think I was seeing_ the Webhook line before I "fixed" the https/http thing — that's where I learned what endpoint would need to be http — but those logs have rotated out. I could dredge them up from backup if that'd be really helpful.
There is currently a bug in my code wich causes events to be lost during processing due to the camera disconnecting before the data is beeing read giving a ConnectionResetError. This PR home-assistant/core#91070 will fix that, but I am still working on it. Hopefully it will be available in HA 2023.4.3 in a few days.
The two messages you posted just mean you subscribed succesfully to the ONVIF WS base notification, but that does not mean that the cam can actually reach your HomeAssistant instance.
You will have to turn on debug logging, make some movement in front of the cam, and then look if you see the Webhook 'reolink_xxxxxxxxxxxx_ONVIF' called
.
If you are not seeing that line, you most likely have a network configuration issue which does not let the camera connect to HomeAssistant.
What is the local HA URL you configured in settings->network ?
You will have to turn on debug logging, make some movement in front of the cam, and then look if you see the
Webhook 'reolink_xxxxxxxxxxxx_ONVIF' called
.
If you are not seeing that line, you most likely have a network configuration issue which does not let the camera connect to HomeAssistant.
Is the webhook line coming from the reolink integration or something else? I turned on debug output selectively.
I am seeing this (from the camera that mostly works), at the time when a person was detected:
2023-04-10 18:44:40.076 DEBUG (MainThread) [reolink_aio.api.data] ONVIF event callback from 'NVR' received payload:
(with a bunch of XML)
followed by:
2023-04-10 18:44:40.076 INFO (MainThread) [reolink_aio.api] Reolink NVR ONVIF event channel 1, Motion: False
2023-04-10 18:44:40.076 INFO (MainThread) [reolink_aio.api] Reolink NVR ONVIF event channel 1, MotionAlarm: False
2023-04-10 18:44:40.076 DEBUG (MainThread) [reolink_aio.api] NVR/nvr.example.org:443::send() HTTP Request params =
{'token': '######'}
2023-04-10 18:44:40.076 DEBUG (MainThread) [reolink_aio.api] NVR/nvr.example.org:443::send() HTTP Request body = [{'cmd': 'GetEvents', 'action': 0, 'param': {'channel': 0}}, {'cmd': 'GetEvents', 'action': 0, 'param': {'channel': 1}}, {'cmd': 'GetEvents', 'action': 0, 'param': {'channel': 2}}, {'cmd': 'GetEvents', 'action': 0, 'param': {'channel': 3}}, {'cmd': 'GetEvents', 'action': 0, 'param': {'channel': 4}}]
2023-04-10 18:44:40.347 DEBUG (MainThread) [reolink_aio.api] NVR/nvr.example.org:443::send() HTTP Response status = 200, content-type = (text/html).
2023-04-10 18:44:40.347 DEBUG (MainThread) [reolink_aio.api.data] NVR/nvr.example.org:443::send() HTTP Response data:
... and then a bunch of JSON which looks to correspond to all of the cameras....
@mattdm alright, that means your ONVIF pushes are comming in fine.
So the issue you are facing is almost certainly resolved once PR home-assistant/core#91070 makes it into a patch release, to know for sure I would need to have a look at your full debug log.
(looking for occasions in which you do see the reolink_xxxxxxxxxxxx_ONVIF' called
line, but are missing the subsequent ONVIF event callback from 'NVR' received payload
line).
I will let you know when the patch release including this fix is available.
Cool -- if that doesn't fix it, I'll send you more logs :)
HomeAssistant 2023.4.5 is now available and includes the ONVIF push fix.
Please let me know if it is now working for you on 2023.4.5.
I will close this issue, if it still does not work for you, please create a new issue.