core: BMW Connected Drive - 403 Quota Exceeded

The problem

I’m suddenly getting a lot of these:

2022-12-02 12:48:25.497 ERROR (MainThread) [homeassistant.components.bmw_connected_drive.coordinator] Error fetching bmw_connected_drive-XXX@YYY.ZZ data: Error communicating with BMW API: Client error '403 Quota Exceeded' for url 'https://cocoapi.bmwgroup.com/eadrax-vcs/v2/vehicles/VIN-redacted/state' 

When this happens, all related entities become unknown (of course). The car can be «lost» for hours, or just minutes, the reappears (for hours or just minutes). Started about 20 h ago.

What version of Home Assistant Core has the issue?

2022.11.4 and 2022.11.5

What was the last working version of Home Assistant Core?

2022.11.4

What type of installation are you running?

Home Assistant OS

Integration causing the issue

BMW Connected Drive

Link to integration documentation on our website

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

Diagnostics information

Not available

Example YAML snippet

No response

Anything in the logs that might be useful for us?

See above

Additional information

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 4
  • Comments: 42 (14 by maintainers)

Most upvoted comments

Since I’m not having issues, I’m going to share my config:

I have three automations and automatic polling disabled. I detect if the car is charging using a power meter, but you can use the car charging status (enable the disabled conditions and disable the enabled ones):

1 - Refresh while charging:

alias: 330e Refresh From Cloud While Charging
description: ""
trigger:
  - platform: time_pattern
    minutes: /5
condition:
  - condition: state
    entity_id: sensor.330e_charging_status
    state: CHARGING
    enabled: false
  - condition: numeric_state
    entity_id: sensor.330e_charger_power
    above: 1000
action:
  - service: homeassistant.update_entity
    data: {}
    target:
      entity_id: sensor.330e_charging_level_hv
mode: single

2 - Refresh while not charging:

alias: 330e Refresh From Cloud While Not Charging
description: ""
trigger:
  - platform: time_pattern
    minutes: /20
condition:
  - condition: state
    entity_id: binary_sensor.330e_charging_status
    state: "off"
    enabled: false
  - condition: numeric_state
    entity_id: sensor.330e_charger_power
    below: 900
action:
  - service: homeassistant.update_entity
    data: {}
    target:
      entity_id: sensor.330e_charging_level_hv
mode: single

3 - Reload when unavailable for over 15 minutes because a sensor update sometimes wouldn’t work after service outage:

alias: 330e Reload Integration.
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.330e_charging_end_time
    to: unavailable
    for:
      hours: 0
      minutes: 15
      seconds: 0
condition: []
action:
  - service: homeassistant.reload_config_entry
    data: {}
    target:
      device_id: 801b792cf2ed4af31d2bee9c2d731957
mode: single

Hope it helps

Looks like they have lowered the quota again. Mine started doing this again last night. Last time this happened 5 minutes seemed to be ok now it’s more like 10 mins. BMW devs suck

If I’m not mistaken, we’re exploiting an API that BMW has set up for the benefits of their customers using the MyBMW app (correct me if I’m wrong). The infrastructure required to provide this service requires investments by BMW.

Some customers like me are paying about £120 a year for ConnectedDrive Professional services. This is where it becomes irksome.

Good point 😉

Annoying as it may be, that we cannot request updates from the API as often as we like, let’s look at it from BMW’s perspective:

If I’m not mistaken, we’re exploiting an API that BMW has set up for the benefits of their customers using the MyBMW app (correct me if I’m wrong). The infrastructure required to provide this service requires investments by BMW.

BMW has decided to provide another API for which they charge the users (https://bmw-cardata.bmwgroup.com/thirdparty/public/car-data/technical-configuration/api-documentation). If everyone instead of paying for the use of that commercial API, exploits the MyBMW app API, they lose income and have to invest more in the MyBMW app API.

Looking at it this way, I can’t really blame BMW for limiting the number of API calls per day. Even the commercial API has a limit, although that limit is 100 requests per minute.

I am now updating my BMW entities like this:

  • Every half hour generally
  • Every 10 minutes when charging
  • I make single calls whenever I plug the car into the charger (my charger has an open API that the supplier encourages people to use, so I get instant (push) notification from the charger when the car is plugged in).
  • I make single calls every 10 minutes if BMW entities are unavailable

I am counting the calls, and so far today (since midnight UTC) I have 63 calls. I will probably end up at about 75 or so before midnight UTC. I could probably limit it even more, without losing the functions I’m after (I mainly use the BMW data to control smart charging during less expensive electricity hours and to start climatizing the car before departure).

So, if the quota stays at 120 per day (which has been suggested), I should be fine. 😄

Just in case it short-circuits someone else’s search and debugging, the solution mentioned above and in #78792 seems to have resolved the BMW API rate limit contention issues. Here’s what I did:

  1. Disable automatic polling for the BMW Connected Drive integration

    Settings -> Devices & Services -> BMW Connected Drive 3-dot menu -> System Options -> Enable polling for updates.

  2. Create a new automation, something similar to the following:

alias: BMW Connected Drive Integration Updates
trigger:
  - platform: time_pattern
    minutes: /15
action:
  - service: homeassistant.update_entity
    target:
      entity_id: sensor.330e_xdrive_charging_status
mode: single

Note: Per @RuiSSousa’s comment on #78792:

# updating 1 sensor causes all of them to be updated

Note: 15 minutes should be good if you don’t care much about manual refreshes, but I’ve just implemented this workaround today so we’ll see how it stands up to the test of time.

:upvote: “HA Enhancement: Integration-specific polling interval configuration option”

The educated guess is that the cap is 120 requests/day (i.e. 10 hours of requests every 5 minutes). My guess is that this is on a per-endpoint basis, so two cars should be counted seperately (however I’m not sure of this).

So 24 hours/120 requests = 12,5 minutes between the requests. However I would not go down that far, as we sometimes request additional vehicle refreshs (i.e. after service execution).

You might want to create an automation that adjusts the timing manually, e.g. every 30 minutes by default but every 10 minutes while the car is charging (or whatever you’re interested in).

Happy to get your feedback what works and what is too much (please try it out!) and let me know so we can adjust the defaults and write some help to the documentation.