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
73.59k stars 30.76k forks source link

Ring integration stops working #38025

Closed donagrejja closed 1 year ago

donagrejja commented 4 years ago

The problem

The Ring integration stops reporting motion and events after a while and the only way to fix it is a restart of home assistant.

Environment

Problem-relevant configuration.yaml

No specific configuration done to the ring integration

Traceback/Error logs

Logger: homeassistant.components.ring
Source: components/ring/__init__.py:303
Integration: Ring (documentation, issues)
First occurred: July 11, 2020, 10:33:53 PM (41 occurrences)
Last logged: 2:21:56 AM

Error fetching Ring history data for device xxxx: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
Error fetching Ring history data for device xxxx: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
Error fetching Ring history data for device xxxx: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
Error fetching Ring history data for device xxxx: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))
Error fetching Ring history data for device xxxx: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

Logger: homeassistant.helpers.entity
Source: __main__.py:356
First occurred: July 11, 2020, 4:05:13 AM (1323 occurrences)
Last logged: July 20, 2020, 10:02:29 PM

Update of camera.front_door is taking over 10 seconds
Update of camera.living_room is taking over 10 seconds
Update of camera.office is taking over 10 seconds
Update of camera.front is taking over 10 seconds
Update of camera.garden is taking over 10 seconds

Logger: homeassistant.components.ring.camera
Source: components/ring/camera.py:153
Integration: Ring (documentation, issues)
First occurred: July 11, 2020, 2:40:26 PM (55 occurrences)
Last logged: July 20, 2020, 8:26:04 PM

Time out fetching recording url for camera camera.front
Time out fetching recording url for camera camera.front_door
Time out fetching recording url for camera camera.garden

Additional information

The timeouts from the logs occur even when the integration is working so i'm not sure if it's relevant. The whole integration just seems to stop and give up and doesn't even retry or recover ever and i'm forced to restart home assistant. Is there any way to reload or restart a single integration ? i'd rather not restart the whole home assistant instance due to z-wave integration firing alot of event upon restart.

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

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

donagrejja commented 4 years ago

This also happens daily in the logs:

2020-07-12 14:09:05 ERROR (MainThread) [homeassistant.helpers.entity] Update for camera.garden fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 677, in urlopen
    chunked=chunked,
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 426, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 421, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/local/lib/python3.7/http/client.py", line 1344, in getresponse
    response.begin()
  File "/usr/local/lib/python3.7/http/client.py", line 306, in begin
    version, status, reason = self._read_status()
  File "/usr/local/lib/python3.7/http/client.py", line 275, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 725, in urlopen
    method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
  File "/usr/local/lib/python3.7/site-packages/urllib3/util/retry.py", line 403, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/usr/local/lib/python3.7/site-packages/urllib3/packages/six.py", line 734, in reraise
    raise value.with_traceback(tb)
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 677, in urlopen
    chunked=chunked,
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 426, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 421, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/local/lib/python3.7/http/client.py", line 1344, in getresponse
    response.begin()
  File "/usr/local/lib/python3.7/http/client.py", line 306, in begin
    version, status, reason = self._read_status()
  File "/usr/local/lib/python3.7/http/client.py", line 275, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 272, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 463, in async_device_update
    await self.async_update()  # type: ignore
  File "/usr/src/homeassistant/homeassistant/components/ring/camera.py", line 149, in async_update
    self._device.recording_url, self._last_event["id"]
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.7/site-packages/ring_doorbell/doorbot.py", line 354, in recording_url
    req = self._ring.query(url)
  File "/usr/local/lib/python3.7/site-packages/ring_doorbell/__init__.py", line 101, in query
    timeout=timeout,
  File "/usr/local/lib/python3.7/site-packages/ring_doorbell/auth.py", line 84, in query
    req = getattr(self._oauth, method.lower())(url, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 543, in get
    return self.request('GET', url, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests_oauthlib/oauth2_session.py", line 516, in request
    method, url, headers=headers, data=data, **kwargs
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 530, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 643, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 498, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
2020-07-13 00:24:35 ERROR (MainThread) [homeassistant.helpers.entity] Update for camera.front_door fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 677, in urlopen
    chunked=chunked,
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 426, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 421, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/local/lib/python3.7/http/client.py", line 1344, in getresponse
    response.begin()
  File "/usr/local/lib/python3.7/http/client.py", line 306, in begin
    version, status, reason = self._read_status()
  File "/usr/local/lib/python3.7/http/client.py", line 275, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 725, in urlopen
    method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
  File "/usr/local/lib/python3.7/site-packages/urllib3/util/retry.py", line 403, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/usr/local/lib/python3.7/site-packages/urllib3/packages/six.py", line 734, in reraise
    raise value.with_traceback(tb)
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 677, in urlopen
    chunked=chunked,
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 426, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 421, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/local/lib/python3.7/http/client.py", line 1344, in getresponse
    response.begin()
  File "/usr/local/lib/python3.7/http/client.py", line 306, in begin
    version, status, reason = self._read_status()
  File "/usr/local/lib/python3.7/http/client.py", line 275, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 272, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 463, in async_device_update
    await self.async_update()  # type: ignore
  File "/usr/src/homeassistant/homeassistant/components/ring/camera.py", line 149, in async_update
    self._device.recording_url, self._last_event["id"]
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.7/site-packages/ring_doorbell/doorbot.py", line 354, in recording_url
    req = self._ring.query(url)
  File "/usr/local/lib/python3.7/site-packages/ring_doorbell/__init__.py", line 101, in query
    timeout=timeout,
  File "/usr/local/lib/python3.7/site-packages/ring_doorbell/auth.py", line 84, in query
    req = getattr(self._oauth, method.lower())(url, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 543, in get
    return self.request('GET', url, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests_oauthlib/oauth2_session.py", line 516, in request
    method, url, headers=headers, data=data, **kwargs
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 530, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 643, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 498, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
donagrejja commented 4 years ago

I've been digging around a bit and it seems like it's only the motion/doorbell sensors that stops working after a while (week or so, a bit random).

Looks like i still get battery percentage data properly.

This also updates for all cameras: sensor.front_last_activity | 2020-07-21T17:43:37+00:00 sensor.front_last_motion | 2020-07-21T17:43:37+00:00

The binary ring sensors are the only ones that aren't working it seems for camera motion and doorbell button.

tony563 commented 4 years ago

I have the same problem, with the Ring integration.

cdiazfer commented 4 years ago

I have the same problem. Binary sensor for ring doorbell (motion and ding) is not updating. Last activity, last motion and last ding is updating correctly.

yieldhog commented 4 years ago

After reboot, Ring devices unavailable -- only able to fix by deleting Ring integration and adding again.

Logger: homeassistant.config_entries
Source: components/ring/__init__.py:65 
First occurred: 10:48:27 AM (1 occurrences) 
Last logged: 10:48:27 AM

Error setting up entry XXXXX@XXXX.com for ring
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/urllib3/connection.py", line 159, in _new_conn
    conn = connection.create_connection(
  File "/usr/local/lib/python3.8/site-packages/urllib3/util/connection.py", line 61, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "/usr/local/lib/python3.8/socket.py", line 918, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name does not resolve

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 670, in urlopen
    httplib_response = self._make_request(
  File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 381, in _make_request
    self._validate_conn(conn)
  File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 978, in _validate_conn
    conn.connect()
  File "/usr/local/lib/python3.8/site-packages/urllib3/connection.py", line 309, in connect
    conn = self._new_conn()
  File "/usr/local/lib/python3.8/site-packages/urllib3/connection.py", line 171, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x7f33b5b1fb50>: Failed to establish a new connection: [Errno -2] Name does not resolve

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/requests/adapters.py", line 439, in send
    resp = conn.urlopen(
  File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 726, in urlopen
    retries = retries.increment(
  File "/usr/local/lib/python3.8/site-packages/urllib3/util/retry.py", line 439, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.ring.com', port=443): Max retries exceeded with url: /clients_api/session?api_version=9 (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f33b5b1fb50>: Failed to establish a new connection: [Errno -2] Name does not resolve'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 219, in async_setup
    result = await component.async_setup_entry(  # type: ignore
  File "/usr/src/homeassistant/homeassistant/components/ring/__init__.py", line 65, in async_setup_entry
    await hass.async_add_executor_job(ring.update_data)
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.8/site-packages/ring_doorbell/__init__.py", line 49, in update_data
    self.create_session()
  File "/usr/local/lib/python3.8/site-packages/ring_doorbell/__init__.py", line 57, in create_session
    self.session = self.query(
  File "/usr/local/lib/python3.8/site-packages/ring_doorbell/__init__.py", line 95, in query
    return self.auth.query(
  File "/usr/local/lib/python3.8/site-packages/ring_doorbell/auth.py", line 84, in query
    req = getattr(self._oauth, method.lower())(url, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 578, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/requests_oauthlib/oauth2_session.py", line 515, in request
    return super(OAuth2Session, self).request(
  File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 530, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 643, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='api.ring.com', port=443): Max retries exceeded with url: /clients_api/session?api_version=9 (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f33b5b1fb50>: Failed to establish a new connection: [Errno -2] Name does not resolve'))
donagrejja commented 4 years ago

That last comment might be something else. My issues have always been fixed by a reboot when the binary sensors for the ring integration stops working "after a while".

cdiazfer commented 4 years ago

Some news about this??? I can´t see binary sensor even if I restart home assistant. It is possible that with 0.114 version this problem could be resolved???

Regards!

cdiazfer commented 4 years ago

For info, now is working without doing anything....

Regards.

donagrejja commented 4 years ago

This is still an issue in the latest version of HA. The ring integration can stop after a few days and can only be woken up again by a HA restart. Same as before the binary sensors just stop updading but the device entities still update properly.

donagrejja commented 4 years ago

is there no plan on making the ring integration able to recover from "internal" issues like binary sensors not working etc ? no replies to this topic at all.

donagrejja commented 4 years ago

Now there's a new error that has surfaced with Home Assistant version 1.116.x - the effect is still that the ring integration just stops working but now it even affects the data of the sensors. So when it's unable to connect to ring it stops trying and both binary sensors and data sensors stops working. I even get low battery warnings because the battery stops getting data.

Here's something from the log.

Logger: homeassistant.components.ring Source: components/ring/init.py:210 Integration: Ring (documentation, issues) First occurred: October 27, 2020, 2:11:49 PM (20 occurrences) Last logged: 9:09:59 AM

Error fetching Ring active dings data: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response')) Error fetching Ring device data: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response')) Error fetching Ring device data: 401 Client Error: Unauthorized for url: https://api.ring.com/clients_api/ring_devices?api_version=9 Error fetching Ring active dings data: 502 Server Error: Bad Gateway for url: https://api.ring.com/clients_api/dings/active?api_version=9

Geoff571 commented 3 years ago

Same issue as the last update from @donagrejja. Seen previously on other recent versions but still present on HA 0.118.2

2020-11-21 16:23:43 WARNING (MainThread) [homeassistant.components.ring] Error fetching Ring active dings data: 504 Server Error: Gateway Time-out for url: https://api.ring.com/clients_api/dings/active?api_version=9
ChrisHardie commented 3 years ago

For anyone else experiencing the "Server Error: Bad Gateway for url" issues with the Ring integration at this moment, it looks like Ring is having a "major outage" and has had some related outages in recent days, according to their status page.

Screen Shot 2020-11-25 at 13 35 05

zraken commented 3 years ago

Any update on this? I'm using 2021.1.0 and my logs have this message every two minutes.

2021-01-07 05:55:55 WARNING (MainThread) [homeassistant.components.ring] Error fetching Ring active dings data: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

atjshop commented 3 years ago

Home Assistant 2021.1.1, many log like below:

WARNING (MainThread) [homeassistant.components.ring] Error fetching Ring active dings data: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

hughes9214 commented 3 years ago

Home Assistant 2021.1.3

Getting this same error constantly- it occurred on 2021.1.1 for me also. I’ve tried removing the integration completely, removing HA from my ring account and then setting up the integration again. The same error still persists. The log is as follows:

Logger: homeassistant.components.ring Source: components/ring/init.py:210 Integration: Ring (documentation, issues) First occurred: 3:16:38 (6 occurrences) Last logged: 3:24:38 Error fetching Ring active dings data: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

Any other suggestions would be appreciated! Thanks.

jum0n commented 3 years ago

Having similar ring issue here since 2021 update. Someone mentioned this might be due to the 2FA ring implemented?

I think this might be the wrong thread to post these "dings and history data" errors, seems more related to this one: https://github.com/home-assistant/core/issues/34713

Error fetching Ring history data for device xxxxxxxxx: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
Error fetching Ring history data for device xxxxxxxx: 401 Client Error: Unauthorized for url: https://api.ring.com/clients_api/doorbots/856712/history?api_version=9&limit=10
Flodu31 commented 3 years ago

Same problem here. Try to remove/add the integration, always an error. Ding and motion are now empty. Did ring changed their API? Florent

kcossabo commented 3 years ago

Same here. When I rebuilt the HASS the automations using the binary sensor were working on 3 stickup cameras, then they just stoped, with errors in the log;

Logger: homeassistant.components.ring Source: components/ring/init.py:302 Integration: Ring (documentation, issues) First occurred: January 22, 2021, 8:06:35 PM (5 occurrences) Last logged: 3:30:35 AM

Error fetching Ring history data for device 74e182326555: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response')) Error fetching Ring history data for device 74e182326555: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer')) Error fetching Ring history data for device 4c24989847f9: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

it seems like the API is limited to the number of or length of connection?

side-note: cool to have a URL link in the logs to get here.... very top shelf.

DTTerastar commented 3 years ago

I think Ring is rate limiting us because the integration hits their api too hard. Can a poll frequency be added to fix this?

carsontl18 commented 3 years ago

Hi All - also receiving errors in my logs :

"WARNING (MainThread) [homeassistant.components.ring] Error fetching Ring active dings data: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))"

Thayios commented 3 years ago

Dealing with this as well, I have a unique set of Ring products I'm sure most people don't use in HA: the peephole door camera x 2

Error fetching Ring active dings data: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

I feel like it's a rate limit being hit for sure.

bartvollebregt commented 3 years ago

It's kind of Ring's own fault... We have to do a request quite often to check if the doorbell has been rung. And since it's a doorbell, you want to do these requests quite often or you'll miss the person at your door.

Now they have decided that their API is being hit too often and implemented rate limiting. While instead, they could easily implement something like webhooks, websockets or even MQTT so they send out a request when the doorbell rings. This would probably also save them a lot of money cause they can downscale their current API server.

Nevertheless, I think some form of setting should be created in this integration to be able to change the frequency of the requests being made to Ring. We could change the hardcoded frequency but since Ring will probably change their rate limit in the future, I think a setting would be more useful.

The unofficial Ring Typescript API for example, has a cameraDingsPollingSeconds setting

If I understand the code correctly, it calls the update_dings method every 5 seconds currently.

cyberjunky commented 3 years ago

@bartvollebregt if the limit is per 24 hours, do less frequent polls during night time?

bartvollebregt commented 3 years ago

@bartvollebregt if the limit is per 24 hours, do less frequent polls during night time?

I'm not sure if the limit is per 24 hours. It would be a good idea to determine that first. I've tried searching but I don't think anyone figured out what the actual rate limits currently are.

I've just performed a small benchmark:

start_time = time.time()
for i in range(17280):
    print(f"--- request #{i}. Execution time: #{round((time.time() - start_time), 2)} seconds ---")
    pprint(ring.update_dings())
    time.sleep(1)

It stopped at --- request #1559. Execution time: #1733.27 seconds --- with HTTPError: 504 Server Error: Gateway Time-out for url

Which means it ran for ~29 minutes with 54 requests per minute

Interestingly enough, if I increase the delay to 100ms. I can still do 1600 requests.

I'm starting to feel that it is limited by the amount of requests you can do per Authenticated session. I'm currently trying 10k requests with 100ms delay and a re-auth every 1k requests, let's see what it does.

bartvollebregt commented 3 years ago

My assumptions above were sort of correct.

With below code I'm able to perform over 9290 requests in 1971.99 seconds before it crashes by just re-authenticating every 1000 requests:

start_time = time.time()
for i in range(10000):
    if i % 1000 == 0:
        ring = Ring(auth)

    print(f"--- request #{i}. Execution time: #{round((time.time() - start_time), 2)} seconds ---")
    pprint(ring.update_dings())
    time.sleep(0.1)
donagrejja commented 3 years ago

Reauthentication seems to be the issue indeed. After a while the integration just stops and notifications from the cameras etc stops working properly.

bartvollebregt commented 3 years ago

It seems the re-auth should be handled by the python-ring-doorbell library that is used. In the query method it checks for a TokenExpiredError and re-authenticates:

try:
    req = getattr(self._oauth, method.lower())(url, **kwargs)
except TokenExpiredError:
    self._oauth.token = self.refresh_tokens()
    req = getattr(self._oauth, method.lower())(url, **kwargs)

The problem in this case, I think, is that we aren't getting a TokenExpired Error but either a gateway timeout or just a connection closed.

1800Zeta commented 3 years ago

Just adding that I am another one with this issue. Is anyone able to look in to this? It appears that the issue has been found around the re-auth/token expiry

Thanks

p4r4n0y1ng commented 3 years ago

Same issue here. Littering logs with events like this. I would be more than happy to help with any information or anything else someone might need - please let me know and I'll do it.

biver0 commented 3 years ago

Same here. Also happy to help debug.

bigfeetneedbigboots commented 3 years ago

I'm using a Ring Video Doorbell Elite connected via CAT6 ethernet using POE. Integrated to HA with standard integration however getting (lots of) following in HA log:

Logger: homeassistant.components.ring
Source: components/ring/__init__.py:210
Integration: Ring (documentation, issues)
First occurred: 12:39:34 (10 occurrences)
Last logged: 12:56:34

Error fetching Ring active dings data: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
scyto commented 3 years ago

@bartvollebregt any further progress on debugging? anything rest of us can do to help?

--updated info-- I pip installed ring-doorbell.py 0.7.0 - didn't fix

picotrain77 commented 3 years ago

Same issue here, never really see any issues with the 3 ring cameras via UI but logs are constantly littered with the above time out, connection aborted

zhdenny commented 3 years ago

Hoping there is a fix or bypass or workaround or something about this. It is annoying.

SparkMike77 commented 3 years ago

Same issue as everyone above using the Balena build of HA on a Raspi 3, seems to be taking the whole device offline after a random time every 24-48 hours. Super irksome. Is there a way I could manually edit the integration to lower the polling rate or force a re-auth?

thebatfink commented 3 years ago

Same issues. Same errors. Failed connects, active ding errors then last ding becomes unknown.. Is this integration disowned now? Issue seems to have been present since last year (although seems even tsight,ers efforts are struggling with similar api problems).

bartvollebregt commented 3 years ago

As shown above I figured out what the error probably is. However I have zero experience with home-assistant development so I have no clue how to implement and test it.

antisane commented 3 years ago

Same issue as everyone above using the Balena build of HA on a Raspi 3, seems to be taking the whole device offline after a random time every 24-48 hours. Super irksome. Is there a way I could manually edit the integration to lower the polling rate or force a re-auth?

Has nothing to do with RPi, My HA runs on a virtual box and has all of the same problems.

lordlala commented 3 years ago

Yep, same thing happening ever since the update the other day. I'm running a Debian VM on a Macbook. This integration has been fairly solid the last few months, so not sure what happened.

KRGT-NL commented 3 years ago

I have the same since the last update, no particular reason. Is it a problem with too much API polling?

ZachPL commented 3 years ago

Just started happing to me after a recent update, camera preview shows and then very soon after breaks, had no problems with ring since my initial set up a few months ago.

I've tried reloading and readding the integration and same issue persists

JustFranky commented 3 years ago

Same issue here with core-2021.6.6:

2021-06-26 21:38:44 WARNING (MainThread) [homeassistant.helpers.entity] Update of camera.haustur is taking over 10 seconds
2021-06-26 21:41:33 WARNING (MainThread) [homeassistant.components.ring] Error fetching Ring active dings data: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
2021-06-26 21:43:33 WARNING (MainThread) [homeassistant.components.ring] Error fetching Ring active dings data: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
2021-06-26 21:45:33 WARNING (MainThread) [homeassistant.components.ring] Error fetching Ring active dings data: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
alexmace commented 3 years ago

Is the Ring integration essentially unmaintained? There's multiple issues about this problem and essentially no response from maintainers.

jum0n commented 3 years ago

I just removed the integration since I couldnt find a good use for the info in my configuration compared to the headaches of errors.

Geoff571 commented 3 years ago

I've done the same.

On Mon, 28 Jun 2021 at 17:10, jum0n @.***> wrote:

I just removed the integration since I couldnt find a good use for the info in my configuration compared to the headaches of errors.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/home-assistant/core/issues/38025#issuecomment-869815189, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIKAQ3FDBCE7H6QOBMSHTD3TVCNGZANCNFSM4PDANFJQ .

KRGT-NL commented 3 years ago

@balloob Any update, as it is assigned to you :)

f7byu3e4jn commented 3 years ago

Same issue here (core-2021.6.6). Ring was working fine for the last ~12 months. Suddenly, HA is not showing camera snapshots nor video footage anymore and there are a lot of errors in the logs. Reloading the Ring integration seems to fix things only for a few minutes. I have also tried to remove & reinstall the integration completely, but this did not solve anything.

2021-07-01 01:47:09 WARNING (MainThread) [homeassistant.components.ring] Error fetching Ring active dings data: HTTPSConnectionPool(host='api.ring.com', port=443): Max retries exceeded with url: /clients_api/dings/active?api_version=9 (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f82b49xxxxx>: Failed to establish a new connection: [Errno -3] Try again'))
2021-07-01 01:47:09 WARNING (MainThread) [homeassistant.components.ring] Time out fetching Ring active dings data
2021-07-01 01:49:33 WARNING (SyncWorker_1) [homeassistant.components.ring] Error fetching Ring history data for device 3ce1a1ade68b: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
hastarin commented 3 years ago

I've had the same problems as everyone and just sat down to take a look. Unfortunately for the most part we're at the mercy of Ring. Their lack of an official API is the main problem. Here is hoping the Matter alliance actually helps get some of these things standardized.

NOTE: Of all the errors I'm seeing currently only the 401 could be fixed in code, the rest are server side errors.

I notice the TypeScript library has changed the way it handles refresh tokens: https://github.com/dgreif/ring/wiki/Refresh-Tokens#refresh-token-expiration

If I knew enough about Python my suggestion would be to do a similar thing to that library and check the token expiry to refresh it if it's within a minute, rather than waiting until a timeout happens then refreshing.

Logger: homeassistant.components.ring
Source: components/ring/__init__.py:200
Integration: Ring (documentation, issues)
First occurred: August 25, 2021, 3:29:54 PM (272 occurrences)
Last logged: 5:59:59 AM

Error fetching Ring active dings data: 500 Server Error: Internal Server Error for url: https://api.ring.com/clients_api/dings/active?api_version=9
Error fetching Ring device data: 503 Server Error: Service Unavailable: Back-end server is at capacity for url: https://api.ring.com/clients_api/ring_devices?api_version=9
Error fetching Ring device data: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
Error fetching Ring active dings data: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
Error fetching Ring active dings data: 401 Client Error: Unauthorized for url: https://api.ring.com/clients_api/dings/active?api_version=9