fwestenberg / reolink_dev

Home Assistant Reolink addon
MIT License
550 stars 102 forks source link

Motion Sensors do not work - Usually Unavailable #348

Open Fannangir opened 2 years ago

Fannangir commented 2 years ago

Hi,

Can't get the sensors to operate. Connected via RLN16-410 NVR with the latest firmware 3.0.0.148. Cameras are RLC-810A and RLC-820A with the latest firmware 3.0.0.494. Have set internal URL, and enabled ONVIF on the NVR.

In the log I can see the following: Logger: reolink.subscription_manager Source: /usr/local/lib/python3.9/site-packages/reolink/subscription_manager.py:103 First occurred: 18:57:00 (126 occurrences) Last logged: 19:02:00

Subscription process ended with wrong HTTP status: 400: Bad Request

And the following: Logger: custom_components.reolink_dev.base Source: custom_components/reolink_dev/base.py:376 Integration: Reolink IP camera (documentation, issues) First occurred: 18:57:00 (42 occurrences) Last logged: 19:02:00

Host 192.168.1.248 error renewing the Reolink subscription

Occasionally, I can see some data from the sensors, but these are mostly unavailable.

What I could be missing? What additional information/log can I provide?

Thanks.

cpainchaud commented 2 years ago

Please provide full logs, this is just a summary

Fannangir commented 2 years ago

Could you please instruct me how to do it?

ShlomiPorush commented 2 years ago

Same issue here. will be happy to provide any logs (don't know how to do it)

maverick62 commented 2 years ago

Hello,

i have the same problem. It never worked for me with nvr16ch last hardware and firmware with any camera.

The error i have is : [homeassistant.components.stream.worker] Error opening stream rtmp://192.168.1.101:1935/bcs/channel2_main.bcs?channel=2&stream=0&user=mycorrectuser&password=mycorrectpwd

Futhermore, this rtmp url doesn't worl on my lan with vlc.

Could you please instruct me how to do it?

Go to 'Supervisor > System >'log provider??' > Core and look for reolink line.

bigstation17 commented 2 years ago

Same. NVR16Channels. It only works with substream. Motion sensor or switches does not work.

bfeige commented 2 years ago

I have same model NVR with 810A cameras, was getting same errors as above when using version 0.34 and 0.35, switched out to master version and picked the AI sensors, now sensors are reporting clear all the time even when there is motion, am getting push notifications from NVR, no errors in home assistant log, the person sensors stay constant clear, the actual main motion sensor will sometimes register motion but not reliably

swa72 commented 2 years ago

Same issue here. will be happy to provide any logs (don't know how to do it)

See https://github.com/fwestenberg/reolink_dev/blob/master/TSHOOT.md

Fannangir commented 2 years ago

Thanks for the link. @cpainchaud, here is my log: https://controlc.com/7fe0c5e4

Hope you can find the issue :). Thanks in advance.

cpainchaud commented 2 years ago

Your NVR replies with error: 'Reolink host 192.168.1.248 (Subscription) got response status: 400. Payload: <?xml version="1.0" encoding="UTF-8"?> ....' but gives no error message so I can't tell what is wrong. How many cameras do you have ?

Fannangir commented 2 years ago

7 cameras. 4 RLC-810A, 3 RLC-820A.

Fannangir commented 2 years ago

Did someone with the 16 channels 4k NVR got the sensors working?

Is it related to the User? I can see in the NVR the option of 3 types of users (regular, admin and super admin). Is there any difference for the integration? Just guessing what might be wrong.

bfeige commented 2 years ago

I haven't tried using another login, using admin default but will do, I was able to use Rest to extract motion states

bfeige commented 2 years ago

Have tried with General Account and a created Admin neither of these work either, only log entry is "User test has authorisation level guest. Only admin users can change camera settings! Switches will not work.", test is the general user

bfeige commented 2 years ago

I can find no way to creat a Super Admin, it looks like only the built in default account has that

bfeige commented 2 years ago

As a workaround I used rest to get states i.e

binary_sensor:

This works fine for Motion haven't been able to find any AI ones being exposed Note: channel id is same channel cam is on -1.

bfeige commented 2 years ago

Upgraded to version 0.36 (was on Master), now have lost my AI and Motion Sensor States all together all saying "Unavailable", with previous master I was getting "off" most of the time but not "Unavailable", after upgrading I got the following log entries

Subscription process ended with wrong HTTP status: 400: Bad Request 7:52:56 PM – (WARNING) /usr/local/lib/python3.9/site-packages/reolink/subscription_manager.py - message first occurred at 7:43:54 PM and shows up 120 times

Host "my NVR IP" error renewing the Reolink subscription 7:52:56 PM – (ERROR) Reolink IP camera (custom integration) - message first occurred at 7:43:54 PM and shows up 40 times

Host "my NVR IP" subscription failed to its webhook, base object state will be set to NotAvailable 7:43:54 PM – (ERROR) Reolink IP camera (custom integration)

Port 80 is used, USE_HTTPS set back to False 7:43:53 PM – (WARNING) Reolink IP camera (custom integration) - message first occurred at 7:43:53 PM and shows up 3 times

I changed the connection on one of the cameras to use 443, however this didn't make any difference to the Motion states

cpainchaud commented 2 years ago

because of the number of cameras you have, subscription system is failing randomly. initial code written by @fwestenberg seems to register to the hook once per camera while Reolink doesn't allow this (God I want to slap them) and they merge all triggers into same webhook. The fix won't be easy and I do lack time to write it this week.

bfeige commented 2 years ago

No problems I am using the following workaround in my configuration.yaml

binary_sensor:

replace people with vehicle/pet for the others, as I'm using via the NVR then I need to specify channel this is equal to the NVR channel -1, just need to duplicate for each channel and AI being used.

night-hood commented 2 years ago

excuse me, how do you do it? I have RLN8-410 and when requested http://192.168.1.26/api.cgi?cmd=GetAiState&channel=00&user=hass&password=paaaasssswwwwoooorddd I get the response [ { "cmd" : "Unknown", "code" : 1, "error" : { "detail" : "not support", "rspcode" : -9 } } ] on any channel

bfeige commented 2 years ago

check the NVR Hardware version (cog, system,info) and confirm your NVR hardware version support access to the AI sensors, H3MB18 may need Firmware upgrade N2MB02 & N3MB01 support it but H3MB02, H3MB16 do not. basically any that have the new interface.

MacL3an commented 2 years ago

I seem to have the same problem with the motion sensor. My setup has been working from time to time, but has never been stable. A while it seemed to be working ok with motion callbacks, but then the main problem was that the "clear" notification never arrived. With the current version it seems to have trouble to get any kind of callbacks. The setup is described in this old ticket (but now running version 0.38 of this integration and NVR firmware v3.0.0.148_21100909).

I just tried enabling the debug logs and this seems to the most interesting logs:

2021-11-20 22:09:03 DEBUG (MainThread) [reolink.subscription_manager] Reolink host 10.0.1.15 (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="http://www.w3.org/2003/05/soap-envelope">
<soap:Header><wsse:Security soap:mustUnderstand="true" 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">
<wsse:UsernameToken wsu:Id="UsernameToken-a5a1c11e-7d7b-40f5-a38e-ea1bef572450">
<wsse:Username>hass</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">lDmEqK1PlQ1cUzO7sYiuMKX1eS0=</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">P29Pb6ryTf62sNjO/lQmMw==</wsse:Nonce>
<wsu:Created>2021-11-20T21:09:03.000Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soap:Header>
<soap:Body>
<b:Subscribe>
<b:ConsumerReference>
<add:Address>http://10.0.1.8:8123/api/webhook/b0cc68f1dc70ac9019c4e24255f7028bfaf091abd53a8258fd4414e176bc6351</add:Address>
</b:ConsumerReference>
<b:InitialTerminationTime>PT15M</b:InitialTerminationTime>
</b:Subscribe>
</soap:Body>
</soap:Envelope>
2021-11-20 22:09:03 DEBUG (MainThread) [reolink.subscription_manager] Reolink host 10.0.1.15 (Subscription) got response status: 400. Payload: <?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:Header><wsa5:To SOAP-ENV:mustUnderstand="1">None</wsa5:To><wsa5:Action SOAP-ENV:mustUnderstand="1">http://docs.oasis-open.org/wsn/bw-2/SubscriptionManager/UnsubscribeRequest</wsa5:Action></SOAP-ENV:Header><SOAP-ENV:Body><SOAP-ENV:Fault><SOAP-ENV:Code><SOAP-ENV:Value>SOAP-ENV:Sender</SOAP-ENV:Value></SOAP-ENV:Code><SOAP-ENV:Reason><SOAP-ENV:Text xml:lang="en"/></SOAP-ENV:Reason></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>
2021-11-20 22:09:03 WARNING (MainThread) [reolink.subscription_manager] Subscription process ended with wrong HTTP status: 400: Bad Request
2021-11-20 22:09:03 ERROR (MainThread) [custom_components.reolink_dev.base] Host 10.0.1.15 error renewing the Reolink subscription

I have an ongoing support ticket with Reolink regarding the missing "clear" callbacks and they asked if I could provide Wireshark captures, but since I'm running HA on a RasberryPi I'm thinking that will be kind of tricky? Anyone running HA on an ordinary computer that could provide these?

bfeige commented 2 years ago

Have decided to move away from this integration, not the integrations fault as I'm sure they will eventually fix the AI sensors webhook subscription issue, I am moving away as the streams are 10 sec behind actual (and regualry freeze), instead am using rest (as above) for the sensors and rtsp for the streams as combining with webrtc card I can get pretty close to realtime streams that don't freeze, combining this with condition cards gives me a display that shows my cameras 4 at a time and then changes to full screen on person/vehicle motion, I setup a couple of helpers to use as triggers to change which 4 are shown at a time that way the 8 cameras I have all get shown over a time period and switch to full screen on motion, I cast this to my google hub max and use a button at bottom of screen combined with helper to switch between control dashboard view and camera view works pretty well but ocassionally drops out on the hub just need to rerun script to cast again if it does, will eventually combine all this into a tablet instead as casting to hub means I cannot send it anything else like tts without the cast dropping.

Fannangir commented 2 years ago

@bfeige , I have implemented your proposal. Works great. Just kept the cameras as a generic platform to be able to play in Homekit. One point, the pet option gives an error, people and vehicle work. Could you please verify whether pet is correct? Thanks.

spf13 commented 2 years ago

@bfeige or @Fannangir can you share the configuration you used as you described? Sounds like it's the way to go.

Fannangir commented 2 years ago

@spf13, refer to some examples. Replace {IP-Address}, {User-Name}, {Password} and {Name} fields to meet your NVR/Cameras settings and desired cameras/sensors names.

camera:

Reolink High Quality Stream

Reolink Low Quality Stream (Sub Stream)

binary_sensor:

Reolink Motion Sensor

Reolink AI Person Sensor

Reolink AI Vehicle Sensor

DIYtechie commented 2 years ago

I'm having the same issue. Also connected via RLN16-410 NVR with the latest firmware 3.0.0.148. Cameras are RLC-520A with the latest firmware 3.0.0.494. Have set internal URL.

(Don't know how to check if Onviff is enabled or disabled, but haven't seen any option to turn it on or off either)

rfporter commented 2 years ago

Same issue. Motion constantly reported as clear. Reolink RLN8-410-E hw version H3MB16 fw version 2.0.0.274.

** In my case, this issue was resolved by setting the internal and external URLs of home assistant to static IP addresses.

Fannangir commented 2 years ago

@DIYtechie , onviff setting is seen only if you connect an external monitor to the NVR. It is not exposed via web interface.

night-hood commented 2 years ago

Same issue. Motion constantly reported as clear. Reolink RLN8-410-E hw version H3MB16 fw version 2.0.0.274.

** In my case, this issue was resolved by setting the internal and external URLs of home assistant to static IP addresses.

I read about this solution, but tell me, where exactly do I need to set the ip?

DIYtechie commented 2 years ago

@DIYtechie , onviff setting is seen only if you connect an external monitor to the NVR. It is not exposed via web interface.

Thanks. I noticed that in the ReadME, but cannot find it in the NVR menu (on the screen connected via HDMI)?

DIYtechie commented 2 years ago

@spf13, refer to some examples. Replace {IP-Address}, {User-Name}, {Password} and {Name} fields to meet your NVR/Cameras settings and desired cameras/sensors names.

Thank you so much @spf13 . This solution works great. Didn't have to change a thing in my Reolink settings

timknowlden commented 2 years ago

@spf13, refer to some examples. Replace {IP-Address}, {User-Name}, {Password} and {Name} fields to meet your NVR/Cameras settings and desired cameras/sensors names.

camera:

Reolink High Quality Stream

Reolink Low Quality Stream (Sub Stream)

binary_sensor:

Reolink Motion Sensor

Reolink AI Person Sensor

Reolink AI Vehicle Sensor

Thanks for providing this, the motion sensor works for motion detected, but does not switch off, do i need to do this manually in a script?

UberWagen commented 2 years ago

FWIW, I found this digging around on reddit from Reolink support regarding a question about not passing vehicle and person detections. Going to try this over the weekend.

Hi, yes, if you have the old hardware NVR, please add the camera to the App/Client as a standalone camera to use its person/vehicle detection features.

Please connect the camera to the same router as the NVR(not directly plugged into the NVR), then add it to the App/Client as a standalone camera. The camera would also be added to the NVR for recording via LAN.

gavyb commented 2 years ago

Same issue. Motion constantly reported as clear. Reolink RLN8-410-E hw version H3MB16 fw version 2.0.0.274.

** In my case, this issue was resolved by setting the internal and external URLs of home assistant to static IP addresses.

Hi @rfporter, can you share your config with me as I have the same NVR and for the life of me cannot get them to work consistently with motion and all 4 cameras configured in HA. I have tried the REST approach but get the following from the LOG: 2022-01-06 08:26:41 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'value' when rendering '{{ value_json[0].value.state }}'

The following is the response received from the URL below (minus the user/password!):

[ { "cmd" : "GetMdState", "code" : 0, "value" : { "state" : 0 } } ]

The binary sensor is configured thus:

  - platform: rest
    name: camera_1_motion
    # resource: !secret Camera1_Rest
    resource: http://192.168.*.*/cgi-bin/api.cgi?cmd=GetMdState&amp;channel=00&amp;rs=wuuPhkmUCeI9WG7C&amp;user=***&amp;password=***
    method: GET
    value_template: '{{ value_json[0].value.state }}'
    scan_interval: 2
    device_class: motion

P.S. My HA and my NVR both have fixed IP addresses...

gavyb commented 2 years ago

as a result of the above, the REST based motion sensors are not working for me. Does anyone know why this is not working?

To reiterate, I am getting the following messages (every 2 seconds for each of my 4 cameras!):

2022-01-06 08:58:14 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'value' when rendering '{{ value_json[0].value.state }}'

The binary_sensor is defined as follows:

  - platform: rest
    name: camera_1_motion
    # resource: !secret Camera1_Rest
    resource: http://192.168.*.*/cgi-bin/api.cgi?cmd=GetMdState&channel=00&rs=wuuPhkmUCeI9WG7C&user=***&password=***
    method: GET
    value_template: '{{ value_json[0].value.state }}'
    scan_interval: 2
    device_class: motion

(IP address and user/password are redacted)

and when you hit that URL from a browser it returns:

[ { "cmd" : "GetMdState", "code" : 0, "value" : { "state" : 0 } } ]

Can anyone assist with this issue - is the value_template incorrect?

Thanks.

Skoteh90 commented 2 years ago

Hey Peeps,

I got Motion, Person, Vehicle detection working for my cameras.

I updated the firmware of my cameras (Reolink 820A, Reolink 510WA) to version v3.0.0.494 (The property names are different on different firmwares.)

I downloaded the CGI/API file here, https://support.reolink.com/hc/en-us/articles/900000625763-What-is-CGI-API

Found that, http://192.168.X.XXX/api.cgi?cmd=GetMdState&channel=0&user=admin&password=xxxx will get the motion detection state. And, http://192.168.X.XXX/api.cgi?cmd=GetAiState&channel=0&user=admin&password=xxxx will get the ai states.

Plugged that into my Postman app as a GET request The cameras returned, [ { "cmd" : "GetMdState", "code" : 0, "value" : { "state" : 0 } } ]

[ { "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 } } } ]

So now I know what values to grab in my home assistant configuration.yaml,

I added

Reolink 820A

sensor:

- platform: rest name: Reolink 820A Motion resource_template: http://192.168.X.XXX/api.cgi?cmd=GetMdState&channel=0&user=admin&password=XXX method: GET scan_interval: 2 value_template: "{{ value_json[0].value.state>0 }}"

- platform: rest name: Reolink 820A Motion - Person resource_template: http://192.168.X.XXX/api.cgi?cmd=GetAiState&channel=0&user=admin&password=XXX method: GET scan_interval: 2 value_template: "{{ value_json[0].value.people.alarm_state>0 }}"

- platform: rest name: Reolink 820A Motion - Vehicle resource_template: http://192.168.X.XXX/api.cgi?cmd=GetAiState&channel=0&user=admin&password=XXX method: GET scan_interval: 2 value_template: "{{ value_json[0].value.vehicle.alarm_state>0 }}"

Reolink 510WA

- platform: rest name: Reolink 510WA Motion resource_template: http://192.168.X.XXX/api.cgi?cmd=GetMdState&channel=0&user=admin&password=XXX method: GET scan_interval: 2 value_template: "{{ value_json[0].value.state>0 }}"

- platform: rest name: Reolink 510WA Motion - Person resource_template: http://192.168.X.XXX/api.cgi?cmd=GetAiState&channel=0&user=admin&password=XXX method: GET scan_interval: 2 value_template: "{{ value_json[0].value.people.alarm_state>0 }}"

- platform: rest name: Reolink 510WA Motion - Vehicle resource_template: http://192.168.X.XXX/api.cgi?cmd=GetAiState&channel=0&user=admin&password=XXX method: GET scan_interval: 2 value_template: "{{ value_json[0].value.vehicle.alarm_state>0 }}"

cpainchaud commented 2 years ago

@Fannangir v0.47 is out and the following was added in https://github.com/fwestenberg/reolink_dev/blob/master/TSHOOT.md: You can re-configure default timer called "Motion states update fallback delay (seconds)" for a specific camera, it defaults to 30 seconds but you can go down to 2-5 seconds. Because it will hammer your camera's API every X seconds, it may have CPU/RAM/stability impacts on your camera.