fwestenberg / reolink_dev

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

Motion Sensor Unavailable after v0.19 #298

Open tiagomerinosantos opened 3 years ago

tiagomerinosantos commented 3 years ago

Hi!

I come to ask for help with this Reolink integration.

Hardware:

Software

Problem: Since I updated the integration from version v0.19 to above I can't get the motion sensors from the cameras. I already uninstalled and installed the integration again but the problem persists.

The following message appears on the logs:

Traceback (most recent call last): File "/config/custom_components/reolink_dev/sensor.py", line 134, in _update_event_range file["name"], KeyError: 'name'

Does anyone know what might be the problem?

Best Regards

cpainchaud commented 3 years ago

it sounds like yet another issue with the NVR. Before I attemps a fix, would potentially first try to edit the script?

after line 122 in sensor.py you have this:

        end = dt.datetime.combine(start.date(), dt.time.max, tzinfo=end.tzinfo)
        _, files = await self._base.send_search(start, end)
        file = files[-1] if files and len(files) > 0 else None
        if not file:
            return

Please replace with:

        end = dt.datetime.combine(start.date(), dt.time.max, tzinfo=end.tzinfo)
        _, files = await self._base.send_search(start, end)
        file = files[-1] if files and len(files) > 0 else None
        if file is None:
            return

        if "name" not in file:
            file = files[-2] if files and len(files) > 1 else None
            if file is None:
                return
            if "name" not in file:
                _LOGGER.warning("Search query returned a file with no name at n-1: %s", str(file))
                return
tiagomerinosantos commented 3 years ago

Hi @cpainchaud

First, thanks for your time to help.

I have already made the changes you indicated, I rebooted the server and the result in the logs was as follows:

Logger: custom_components.reolink_dev.sensor Source: custom_components/reolink_dev/sensor.py:133 Integration: Reolink IP camera (documentation, issues) First occurred: 09:28:10 (3 occurrences) Last logged: 09:28:10 Search query returned a file with no name at n-1: {'EndTime': {'day': 8, 'hour': 8, 'min': 59, 'mon': 10, 'sec': 59, 'year': 2021}, 'PlaybackTime': {'day': 8, 'hour': 7, 'min': 29, 'mon': 10, 'sec': 59, 'year': 2021}, 'StartTime': {'day': 8, 'hour': 8, 'min': 29, 'mon': 10, 'sec': 59, 'year': 2021}, 'frameRate': 0, 'height': 0, 'size': '959971328', 'type': 'main', 'width': 0} Search query returned a file with no name at n-1: {'EndTime': {'day': 8, 'hour': 8, 'min': 59, 'mon': 10, 'sec': 58, 'year': 2021}, 'PlaybackTime': {'day': 8, 'hour': 7, 'min': 29, 'mon': 10, 'sec': 57, 'year': 2021}, 'StartTime': {'day': 8, 'hour': 8, 'min': 29, 'mon': 10, 'sec': 57, 'year': 2021}, 'frameRate': 0, 'height': 0, 'size': '74973184', 'type': 'sub', 'width': 0} Search query returned a file with no name at n-1: {'EndTime': {'day': 8, 'hour': 8, 'min': 59, 'mon': 10, 'sec': 57, 'year': 2021}, 'PlaybackTime': {'day': 8, 'hour': 7, 'min': 29, 'mon': 10, 'sec': 56, 'year': 2021}, 'StartTime': {'day': 8, 'hour': 8, 'min': 29, 'mon': 10, 'sec': 56, 'year': 2021}, 'frameRate': 0, 'height': 0, 'size': '74973184', 'type': 'sub', 'width': 0}

Best Regards

cpainchaud commented 3 years ago

at least now it is not crashing (so integration should behave better) but it's strange that the API returns no file name : this filename is important to extract a screenshot. It feels like a bug from Reolink software

leroyloren commented 3 years ago

https://github.com/fwestenberg/reolink_dev/issues/265#issuecomment-938470300

cpainchaud commented 3 years ago

@fwestenberg can you please comment on what the filename is used for? and why it would be absent from the API reply?

fwestenberg commented 3 years ago

To be honest I don't. This part of the integration (media browsing) was created by @xannor. https://github.com/fwestenberg/reolink_dev/issues/170

tiagomerinosantos commented 3 years ago

I also have these errors in the logs, I don't know if they could be related.

Logger: custom_components.reolink_dev.base Source: custom_components/reolink_dev/base.py:360 Integration: Reolink IP camera (documentation, issues) First occurred: 10:20:49 (3 occurrences) Last logged: 10:20:49 Host X.X.X.X error renewing the Reolink subscription

Logger: custom_components.reolink_dev.base Source: custom_components/reolink_dev/base.py:332 Integration: Reolink IP camera (documentation, issues) First occurred: 10:20:49 (1 occurrences) Last logged: 10:20:49 Host X.X.X.X subscription failed to its webhook, base object state will to NotAvailable

@leroyloren I just didn't understand why invalidates the reading of the motion sensors. But I will try downgrade to v0.22

Thanks for the help!

cpainchaud commented 3 years ago

@tiagomerinosantos : these error in the logs concern the webhooks which should trigger the motion sensor updates thus explaining why you are not getting any update.

What is model and the software version of your camera ?

leroyloren commented 3 years ago

v0.26 RLN8-410 (v3.0.0.130_21060706)

2021-10-08 11:33:40 ERROR (MainThread) [custom_components.reolink_dev.base] Host 10.75.7.250 error renewing the Reolink subscription 2021-10-08 11:33:49 ERROR (MainThread) [custom_components.reolink_dev.base] Host 10.75.7.250 subscription failed to its webhook, base object state will to NotAvailable 2021-10-08 11:33:49 ERROR (MainThread) [custom_components.reolink_dev.base] Host 10.75.7.250 error renewing the Reolink subscription 2021-10-08 11:33:49 WARNING (MainThread) [custom_components.reolink_dev.sensor] Search command provided a file record without a name: {'EndTime': {'day': 8, 'hour': 11, 'min': 33, 'mon': 10, 'sec': 43, 'year': 2021}, 'PlaybackTime': {'day': 8, 'hour': 9, 'min': 31, 'mon': 10, 'sec': 4, 'year': 2021}, 'StartTime': {'day': 8, 'hour': 11, 'min': 31, 'mon': 10, 'sec': 4, 'year': 2021}, 'frameRate': 0, 'height': 0, 'size': '115867648', 'type': 'main', 'width': 0}

cpainchaud commented 3 years ago

but what about the camera's software version @leroyloren ?

leroyloren commented 3 years ago

RLC-810A (v3.1.0.598_21091303)

cpainchaud commented 3 years ago

that software version is a beta with many issues for which I opened tickets at Reolink support but they have not answered in 2 weeks. I don't know if/how it could affect the connection through the NVR but as a matter of fact I would first try again after downgrading the camera

leroyloren commented 3 years ago

I just tried another channel on NVR with stable firmware and it behaves the same

I also tried to connect my other NVR where all cameras and NVR are on stable firmware.

And still the same, something has fundamentally changed since 0.22.

leroyloren commented 3 years ago

obrazek

tiagomerinosantos commented 3 years ago

@tiagomerinosantos : these error in the logs concern the webhooks which should trigger the motion sensor updates thus explaining why you are not getting any update.

What is model and the software version of your camera ?

Software

EDIT: I tried to update the cameras through the NVR but it says it is the most current, however the Reolink Download Center has more recent versions where the V3.0.0.250 version says:

  1. Updated Web Client version 2. Added Human/Vehicle detection area function 3. Added Human/Vehicle sensitivity function 4. Added the function of customizing detection target size 5. Added the function to turn on the light based on the scheduled time (511WA/811A) 6. Added volume adjustment function (511WA/811A/E1 Outdoor) 7. Optimized Human/Vehicle tracking function (E1 Outdoor) 8. Optimize the Home position function (E1 Outdoor)

I will try to update later manually.

leroyloren commented 3 years ago

In my case, the integration only works fine with IPC v3.0.0.494_21073002

NVR the latest firmware and IPC with beta does not work.

xannor commented 3 years ago

I'm trying to wrap my head around this issue, sorry very early morning for me. Python is not my strongest language, and relatively new to me, so it is quite possible I wrote code that is not optimal, but hopefully I can explain the intent of the last event sensor.

The last event sensor was an attempt to have a sensor similar to ring where you can know the last video event and path. This was mostly so an automation could grab a snapshot to use as a thumbnail on a new video, since motion events didnt, at the time, include any info about the video.

The timing was when when a motion event comes in, the camera was queried to get the most recent video file created, and if it is different then the last one, it means a new video was created. This was only really tested with individual cameras, as I do not have access to an NVR. And only one of those cameras is an *A series, which at the time, only had standard detection.

With all of the recent changes in detection, it is quite possible that the video and event sync, or possibly event the search api (which had very little documentation, and required a "patch" for the first *A series camera due to file name encoding) has changed.

zerocritical commented 3 years ago

I have a similar issue. Any luck with identifying the issue with motion sensors not being reported?

https://github.com/fwestenberg/reolink_dev/issues/265#issuecomment-939869705