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.67k stars 30.42k forks source link

ONVIF motion detection sensor stops working after a while #36336

Closed vanbalken closed 3 years ago

vanbalken commented 4 years ago

The problem

The binary_sensor, for motion detection, created by the ONVIF integration stops working after a while. After rebooting Home Assistant the sensor works again until the same issue occurs again.

Environment

Traceback/Error logs

Logger: homeassistant.core
Source: components/onvif/event.py:111
First occurred: 10:24:42 (1 occurrences)
Last logged: 10:24:42

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 936, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore  # noqa
  File "/usr/local/lib/python3.7/asyncio/base_events.py", line 962, in create_connection
    raise exceptions[0]
  File "/usr/local/lib/python3.7/asyncio/base_events.py", line 949, in create_connection
    await self.sock_connect(sock, address)
  File "/usr/local/lib/python3.7/asyncio/selector_events.py", line 473, in sock_connect
    return await fut
  File "/usr/local/lib/python3.7/asyncio/selector_events.py", line 503, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
ConnectionRefusedError: [Errno 111] Connect call failed ('192.168.1.42', 1024)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/onvif/event.py", line 124, in async_pull_messages
    await self.async_renew()
  File "/usr/src/homeassistant/homeassistant/components/onvif/event.py", line 111, in async_renew
    await self._subscription.Renew(termination_time)
  File "/usr/local/lib/python3.7/site-packages/zeep/asyncio/bindings.py", line 13, in send
    options["address"], envelope, http_headers
  File "/usr/local/lib/python3.7/site-packages/zeep/asyncio/transport.py", line 107, in post_xml
    response = await self.post(address, message, headers)
  File "/usr/local/lib/python3.7/site-packages/zeep/asyncio/transport.py", line 95, in post
    proxy=self.proxy,
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client.py", line 483, in _request
    timeout=real_timeout
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 523, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 859, in _create_connection
    req, traces, timeout)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 1004, in _create_direct_connection
    raise last_exc
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 986, in _create_direct_connection
    req=req, client_error=client_error)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 943, in _wrap_create_connection
    raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host 192.168.1.42:1024 ssl:None [Connect call failed ('192.168.1.42', 1024)]

Additional information

My camera is a TP-Link Tapo C100. I've connected the camera using the UI. Information about connecting the camera using ONVIF can be found here: https://www.tapo.com/uk/faq/70/

The ONVIF service port of the camera is 2020, but in the stacktrace I see port 1024. Could this cause the issue? Or are multiple ports used?

probot-home-assistant[bot] commented 4 years ago

onvif documentation onvif source (message by IssueLinks)

probot-home-assistant[bot] commented 4 years ago

Hey there @hunterjm, mind taking a look at this issue as its been labeled with a integration (onvif) you are listed as a codeowner for? Thanks! (message by CodeOwnersMention)

dkulchinsky commented 4 years ago

looks like this could be related to what I've discussed here https://github.com/home-assistant/core/issues/36111#issuecomment-633390203 with @hunterjm

hunterjm commented 4 years ago

This one is a little different. It looks like it's attempting to renew the subscription, but is failing before it gets a chance to. The device likely closes the connection before it can renew.

tipofthesowrd commented 4 years ago

I'm having a similar thing with my IPC Dahua 1531S cameras. Checking in Onvif device manager I can see the events, however they stopped working in HA after a day or so.

When I delete and readd the cameras it works again.

dkulchinsky commented 4 years ago

same here on my Hikvision DS-HD1, everything works great for a couple of days and then suddenly it no longer reports motion or in some cases it's stuck in "motion detected", restarting HA solves the issue.

@hunterjm I recall from another issue you mentioned you have the same door bell camera, I'm curious if you experience similar issue.

mrwsl commented 4 years ago

@vanbalken Sorry to hijack this issue but I have a similar set up like you with the c100 but I don't see the motion sensor at all. Did you do something else to get the binary_sensor?

vanbalken commented 4 years ago

@herrwusel I needed to enable the motion sensor from the mobile app, but I didn't require any additional configuration in Home Assistant I think. I haven't used my c100 with Home Assistant in a couple of months so I'm not 100% sure :)

dkulchinsky commented 4 years ago

I'm still hitting this issue on my Hikvision DS-HD1, motion events work for a couple of hours after starting HA and then they just stop reporting.

Same camera attached to my Synology (for recording) through ONVIF works just fine, had to fallback to webhook intergation from Synology to HA.

@hunterjm I recall you have the same Doorbell, does that work ok for you?

hunterjm commented 4 years ago

@dkulchinsky - Yeah, but my doorbell has no issues reporting events. I may have used HikVision's batch update tool to disable daylight savings time on it since it was reporting the wrong timestamp, which may also cause issues with re-subscribing to events?

image

dkulchinsky commented 4 years ago

ohh, that could be! so you disabled DST and manually adjust TZ?

On Thu., Oct. 15, 2020, 18:34 Jason Hunter, notifications@github.com wrote:

@dkulchinsky https://github.com/dkulchinsky - Yeah, but my doorbell has no issues reporting events. I may have used HikVision's batch update tool to disable daylight savings time on it since it was reporting the wrong timestamp, which may also cause issues with re-subscribing to events?

[image: image] https://user-images.githubusercontent.com/747670/96192864-f048d680-0f14-11eb-8cbf-4091c53269b0.png

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/home-assistant/core/issues/36336#issuecomment-709625494, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOY63PEAQIRVSROMLILDINDSK52IXANCNFSM4NPUOOJQ .

hunterjm commented 4 years ago

yes

dkulchinsky commented 4 years ago

Thanks @hunterjm, I'll try the same

dkulchinsky commented 4 years ago

@hunterjm, no luck here... I disabled DST and adjusted the TZ accordingly but events stop after some time.

I also verified the integration no longer complains about time difference.

Any other ideas?

tuimz commented 3 years ago

Just wanted to chime in that Im having the same issues with an Anpviz camera. What is interesting that I have setup Surveillance station on my Qnap nas to record on motion and that has been running flawlessly.

github-actions[bot] commented 3 years ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.