home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
72.71k stars 30.45k forks source link

Reolink camera not triggering motion entity #87520

Closed dbiczo closed 1 year ago

dbiczo commented 1 year ago

The problem

Binary sensor entity is not updated by push or polling when motion is detected by reolink rlc-520 camera.

What version of Home Assistant Core has the issue?

2023.2.2

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Reolink IP NVR/camera

Link to integration documentation on our website

https://www.home-assistant.io/integrations/reolink

Diagnostics information

home-assistant_reolink_2023-02-06T04-08-30.921Z.log

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

Camera has latest available firmware v3.0.0.136_20121112. Camera has push enabled and is on same local network 192.168.200.48 as home assistant. Home assistant has local network set as http://192.168.200.4:8123 and has webhooks enabled.

home-assistant[bot] commented 1 year ago

Hey there @starkillerog, mind taking a look at this issue as it has been labeled with an integration (reolink) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `reolink` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Change the title of the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign reolink` Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


reolink documentation reolink source (message by IssueLinks)

andriej commented 1 year ago

@starkillerOG I was about to open new issue but on this one it's the same, logs look similiar and model (RLC-520) is the same:

IP Camera: RLC-520
software: v3.0.0.136_20121112 (latest available)
model: IPC_51516M5M

home-assistant_reolink_2023-02-06T16-27-53.307Z.log

You'll see a lot of with Find&Replace, but I don't think it does matter. I have not removed single line connected with reolink integration

Local URL in HA is set to: http://192.168.<REDACTED>.200:8123 and working flawlessly on local connections.

it seems it's directly connected with RLC-520 that we both have and it's not directly connected with #87043 as we have local HTTP set and working (and can be seen in logs that cameras picks it up)

vmonkey commented 1 year ago

I have a similar problem with rlc410. No triggered motion visible in HA.

Afraskai commented 1 year ago

Hello just for your Information, I have the same effects with RLC-542WA.

Thank you for providing this integration!!

andriej commented 1 year ago

@vmonkey and @Afraskai it would be more helpful to provide debug log I guess, as it may differ between models. Provide:

cam model and firmware URL configured under settings->system->network->Home Assistant URL->local network Please first post those and then enable debug logging for the reolink integration, reboot HomeAssistant, let it fully start again and wait 3 minutes, disable debug logging and post the debug log in the issue (than I can see if I can spot something else is wrong). You can redact all sensitive information and only reolink logs are relevant (the rest can be taken out).

starkillerOG commented 1 year ago

@dbiczo @andriej thanks for sharing the debug logs, they are very insightfull. I see multiple problems with the rlc-520 that I can and will fix. It is a discontinued camera with quite old firmware, that is why it is giving a few problems, but I think I can work around most of it.

Is it correct that the RLC-520 only supports motion detection, no AI people, vehicle, pet, etc detection?

The good thing: I do see the motion detection push events comming in, so I can defenitely make it work. The strange thing, it appears to be ignoring the pollings of the motion state. Specifically, it is unclear to me if the RLC-520 does or does not support the GetMdState command.

Could one of you try the following python script: Fill in the IP, username and password, you can run this from any PC (windows) on the same network as the camera. Install reolink-aio library using pip install --upgrade reolink-aio

import logging
import asyncio
from reolink_aio import api

_LOGGER = logging.getLogger(__name__)
logging.basicConfig(level="INFO")

IP = '192.168.1.FILL_THIS_IN'
username = 'FILL_THIS_IN'
password = 'FILL_THIS_IN'

async def asyncio_demo(loop):
    host = api.Host(host=IP, username=username, password=password, protocol="rtsp")

    await host.get_host_data()
    await host.get_states()
    body = [{"cmd": "GetMdState", "action": 0, "param": {"channel": 0}}]
    print(await host.send(body))
    body = [{"cmd": "GetMdState", "action": 0}]
    print(await host.send(body))

if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    loop.run_until_complete(asyncio_demo(loop))
andriej commented 1 year ago

Is it correct that the RLC-520 only supports motion detection, no AI people, vehicle, pet, etc detection?

I can confirm that, it only detects motion without further details

regarding the script, here's the output (ran twice):

$ python3 test.py
[{'cmd': 'GetMdState', 'code': 0, 'value': {'state': 0}}]
[{'cmd': 'GetMdState', 'code': 1, 'error': {'detail': 'param error', 'rspCode': -4}}]
ERROR:asyncio:Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7f894ece65e0>
ERROR:asyncio:Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x7f894ece3c40>, 53.713745754)]']
connector: <aiohttp.connector.TCPConnector object at 0x7f894ed51850>
$ python3 test.py
[{'cmd': 'GetMdState', 'code': 0, 'value': {'state': 0}}]
[{'cmd': 'GetMdState', 'code': 1, 'error': {'detail': 'param error', 'rspCode': -4}}]
ERROR:asyncio:Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7f84e9c8e040>
ERROR:asyncio:Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x7f84e9c8ac40>, 148.362841254)]']
connector: <aiohttp.connector.TCPConnector object at 0x7f84e9cf8a60>
starkillerOG commented 1 year ago

@andriej that is perfect, thank you very much. I now have everything I need to fix the RLC-520 support.

Just need some time to work on it, hopefully tonight.

If you appreciate the reolink integration and want to support its development, please consider sponsering the upstream library.

dbiczo commented 1 year ago

Yes, the RLC-520 camera only does motion and not car person detection. I believe polling and push were working in HACS Reolink IP camera integration. Thanks for putting in the effort to make this integration part of core HA.

$ python3 test.py test.py:25: DeprecationWarning: There is no current event loop loop = asyncio.get_event_loop() [{'cmd': 'GetMdState', 'code': 0, 'value': {'state': 0}}] [{'cmd': 'GetMdState', 'code': 1, 'error': {'detail': 'param error', 'rspCode': -4}}] ERROR:asyncio:Unclosed client session client_session: <aiohttp.client.ClientSession object at 0x7f8eed6a28c0> ERROR:asyncio:Unclosed connector connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x7f8eed6976a0>, 512066.715358685)]'] connector: <aiohttp.connector.TCPConnector object at 0x7f8eed6a1ab0>

Afraskai commented 1 year ago

Hello @starkillerOG and @andriej,

here is my log - hope this helps!

home-assistant_reolink_2023-02-07T13-03-16.183Z_redacted.log

"exactType" : "WIFI_SOLO_IPC", "firmVer" : "v3.1.0.764_21121718", "frameworkVer" : 1, "hardVer" : "IPC_523D95MP", "model" : "RLC-542WA",

starkillerOG commented 1 year ago

@andriej @dbiczo I just released version 0.4.0 of the upstream library. The HomeAssistant version bump is here: https://github.com/home-assistant/core/pull/87733 This schould fix all problems on the RLC-520

If you want you can try out the linked PR, otherwise you will need to wait a few days for HomeAssistant 2023.2.4 to be released.

If you appreciate the reolink integration and want to support its development, please consider sponsering the upstream library.

starkillerOG commented 1 year ago

@Afraskai I did not see any ONVIF events comming in in your log. Did you cause motion events on the camera (waving in front of te camera) while you took the debug log?

The issues on your camera could potentially be fixed with version 0.4.0 of the upstream lib, but to be sure I need to see the incoming ONVIF events.