robinostlund / homeassistant-volkswagencarnet

Volkswagen Carnet Component for home assistant
GNU General Public License v3.0
340 stars 63 forks source link

[BUG] ClientResponseError: 429, message='Too Many Requests' #660

Open aphotrax opened 2 months ago

aphotrax commented 2 months ago

Before you post a new issue - you must first check the following (and check the boxes with an "X" below)

Environment

Describe the bug

The issue has been there pretty much since I've started using the addon. When arriving home everything works as expected but after a while it stops connecting to my car. This happens the quickest when "often" changing MaxCharging setting based on solar production. When checking the logs it's confirmed I'm being rate-limited. Though I can't find any information about the limits applicable to avoid this. Currently it shouldn't send more then one request every +/-15 minutes to increase/decrease. And maybe sometimes one more for full stop or start. So that already feels pretty "slow".

Traceback/Error

Logger: homeassistant.components.websocket_api.http.connection
Source: components/websocket_api/commands.py:245
integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 12:15:12 (6 occurrences)
Last logged: 14:35:53

[140450388285840] Unexpected exception
[140450388292896] Unexpected exception
[140450402280080] Unexpected exception
[140449620424688] Unexpected exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/volkswagencarnet/vw_connection.py", line 834, in setCharging
    response_raw = await self.post(
                   ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/volkswagencarnet/vw_connection.py", line 521, in post
    return await self.post(
           ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/volkswagencarnet/vw_connection.py", line 521, in post
    return await self.post(
           ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/volkswagencarnet/vw_connection.py", line 521, in post
    return await self.post(
           ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/volkswagencarnet/vw_connection.py", line 510, in post
    return await self._request(
           ^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/volkswagencarnet/vw_connection.py", line 466, in _request
    raise httperror from None
  File "/usr/local/lib/python3.12/site-packages/volkswagencarnet/vw_connection.py", line 408, in _request
    response.raise_for_status()
  File "/usr/local/lib/python3.12/site-packages/aiohttp/client_reqrep.py", line 1093, in raise_for_status
    raise ClientResponseError(
aiohttp.client_exceptions.ClientResponseError: 429, message='Too Many Requests', url='https://emea.bff.cariad.digital/vehicle/v1/vehicles/WVWZZZ3C5RE020753/charging/start'

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

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 245, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2761, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2804, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 996, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1068, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/config/custom_components/volkswagencarnet/switch.py", line 77, in async_turn_on
    await self.instrument.turn_on()
  File "/usr/local/lib/python3.12/site-packages/volkswagencarnet/vw_dashboard.py", line 852, in turn_on
    await self.vehicle.set_charger("start")
  File "/usr/local/lib/python3.12/site-packages/volkswagencarnet/vw_vehicle.py", line 308, in set_charger
    response = await self._connection.setCharging(self.vin, (action == "start"))
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/volkswagencarnet/vw_connection.py", line 841, in setCharging
    raise Exception("Unknown error during setCharging") from e  # pylint: disable=broad-exception-raised
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Exception: Unknown error during setCharging
github-actions[bot] commented 1 month ago

This issue is stale because it has been open for 30 days with no activity.

tokroth commented 1 month ago

I have the same issue.

To try to resolve I have done this: Throttled down the HASS configuration to 15 min sensor update interval (was 5 min) and also removed VW api connection from Tibber (my power company, using their service for smart charging). This is not optimal, but if need be…

The only things that ABSOLUTELY must work for me is a data refresh at 05.00 am in the morning to be able to force charging robot in case smart charging failed and secondly start heater 10 min before calendar departure in the morning if cold outside.

Do we have any knowledge on what the rate limit in the VW api is? And how to ensure it is not reached….?

github-actions[bot] commented 1 week ago

This issue is stale because it has been open for 30 days with no activity.

AlexJacu commented 1 week ago

Please note that VW allow max of 480 request per day, that is an interval of 5 Min. To allow you to use also VW App additional to HA, you should set an interval of at least every 6 min. to be under the day's request limit.

tokroth commented 1 week ago

Thanx! Just to confirm. I set it to every 10 min and have not had a single problem since! happy!

aphotrax commented 1 week ago

Ah but that's probably exactly what I'm looking for. Just changed it to 10 minutes as well. Good to know the limits now and that they are daily not hourly. Thanks

magicus commented 3 days ago

Suggested fix to document this in https://github.com/robinostlund/homeassistant-volkswagencarnet/pull/680