BMW ConnectedDrive component

Edit: BMW ConnectedDrive is available in Home Assistant 0.64.
Check this post for further explanation.

I came across this URL today which contains a Python script to access the BMW ConnectedDrive which is used for Openhab. This is really awesome :slight_smile:

All you need is your username, password and vehicle identification number (VIN) to get access to the data of your car.
In other projects I saw there was an API key and secret needed which is difficult to get, but for this script that’s not necessary.

I have changed the Python script a bit for testing purposes so it works as a standalone script. See the working example with some data of my car in the screenshot below.
The original script is developed for the BMW i3, but it’s working for my BMW X1 as well.

Edit: check this post with instructions where to download the Python script I have made. It also contains the explanation what you need to add in it so you can run it from CLI.

I also found this link which has info on the url which contains a json with 36 urls to rendered images of your car. All you need is the VIN for this.

I will dive into this to see if I can make a custom component based on the Volvo On Call component.
Once a first version is available I will post it here. Please allow me some time for it as I am quite busy and I am not a developer so it will take me a lot of trial and error :roll_eyes:



Great! Keep us posted. Really want this to work. I have one Volvo and one BMW.

That makes you an ideal tester :wink:
Do you already use the Volvo On Call component? And which type of BMW you have?

There is also a PR for Mercedes me done from which I can reuse quite some code, so that will be helping me a lot.

Would you mind sharing your current modified script that you have used for the screenshot? I’m curious if it works with my X1 as well. When using the App im limited to (un)locking the doors, locateing the car and controlling the climate. Would be neat if I could get the milage and fuel like you can.

HELL YES! Thank you. BTW- I have a BMW i3 so I can test once you have something ready.

I’m looking forward for your progress! Currently I’ve got an BMW X1 (2017 model) and using the BMW connected android app for connected drive services.

| parameter long         | parameter short | Description                                                 |
| ---------------------- | ----------------|-------------------------------------------------------------|
|--help                  | -h              | show commandline help                                       |
|--printall              | -p              | print all values, usefull for debuging or just for exploring|

When I try to call the -p i receive the following error:

[email protected]:~/bmwcdapi $ python3 -p
Traceback (most recent call last):
  File "", line 263, in <module>
  File "", line 234, in main
    c = ConnectedDrive()
  File "", line 43, in __init__
    self.bmwUsername = self.ohGetValue("Bmw_Username").json()["label"]
  File "/usr/local/lib/python3.6/site-packages/requests/", line 892, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/local/lib/python3.6/json/", line 354, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.6/json/", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/lib/python3.6/json/", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Hi Gerard,

I am using the VOC component for our Volvo V60 Twin Engine (would also be nice to get more info on battery and charging for that). The BMW is a BMW M2 Model Year 2017. With Connected Drive.
Tell me what to do and I can gladly be your guinea pig. :slight_smile:

You can download the script at
Script is still very messy and under a lot of development, but ready for some test on the CLI.

The request module needs to be available on your server (sudo pip install requests).

In the script add the information where it now states None, this starts at line 58. Place the information between quotes as shown in the examples.

# ----=================================================----
# Enter the data below to be able to login
# Your BMW ConnectedDrive username
USERNAME = None             # "[email protected]"

# Your BMW ConnectedDrive password
PASSWORD = None             # "your_password"

# 17!! chars Vehicle Identification Number (VIN) of the car, can be found in the app or on BMW ConnectedDrive online
VIN = None                  # "vin_code"

# This is the URL you use to login to BMW ConnectedDrive, e.g. or
URL = None                  # ""

Then you are able to run it with:
./ -p

Curious to hear if you have more information available than in the app.
Be aware that the output contains your gps data, so edit that before copying any data over here :face_with_monocle:

@irqnet, you can’t run the script from the link in my first post as that is intended to be used with Openhab.
But you can use my script from this post.

@JesseWebDotCom, could you also run this script and send me the output (remove gps data)?
I would like to see how the i3 specific data (charging etc.) is shown, so I know how to put that in some sensors.

1 Like

I just realize I really need a test drive in your M2 before I can add this component to Home Assistant :wink:
That’s a really nice car!

Can you send me some screenshots on how the Volvo stuff (sensors etc) are shown in Home Assistant? I can use that as inspiration for how to show the BMW ConnectedDrive data.

1 Like

Been waiting for a post like this, I have a 2017 4 GC, I’ll download the script and have a play, happy to help with testing!

I get an error:

Traceback (most recent call last):
  File "/Users/me/PycharmProjects/untitled/", line 375, in <module>
  File "/Users/me/PycharmProjects/untitled/", line 342, in main
    c = ConnectedDrive()
  File "/Users/me/PycharmProjects/untitled/", line 84, in __init__
  File "/Users/me/PycharmProjects/untitled/", line 125, in generate_credentials
    tokenType = (
AttributeError: 'NoneType' object has no attribute 'group'

Process finished with exit code 1

and the mypayload variable was set to:

Well, I got further. It looks like I have a account where I can see my car, its status, and everything and separately I have a where I have no cars listed. It looks like this code lists cars from the second account and then would get the details from the first. Because it can’t find my car, I now get:

UnboundLocalError: local variable 'map_car_data' referenced before assignment
<Response [404]>

I’ll try and call BMW tomorrow to see if they can merge the accounts or minimally ensure my car is on the second account.

I’ve got nearly the same error:

Traceback (most recent call last):
File “”, line 345, in
File “”, line 333, in main
execStatusCode = c.get_car_data()
File “”, line 163, in get_car_data
return map_car_data
UnboundLocalError: local variable ‘map_car_data’ referenced before assignment

It looks like the variables map_car_data and map_car_navigation where not defined before return in the specified functions.

I’ve tested that by adding two lines in the script.

in function:

def get_car_data(self):
map_car_data = 0


def get_car_navigation(self):
map_car_navigation = 0


[email protected]:~/bmwcd/bmwcd $ python3 -p

It seems that is a return of the http request… 400 bad request?

I indeed noticed that the url for USA differs from other countries, where it is[countrycode].
I will have a look at the url to see if my car is registered there.

Edit: I go to and when pressing the Login button that forwards me to where I can enter my credentials.

Which url did you use in the script?
And have you used the 17 digits VIN code, because the short code of 5 digits doesn’t work?

In the meanwhile I have made some data from BMW ConnectedDrive available in Home Assistant :slight_smile:

Still a lot of work to do, but here some screenshots.

Device tracker

Binary sensor

Ah i will check that. Using the german URL with .de ending but using the short VIN Code like in the BMW App. Have to grab my papers out of the car to check the full number.

The full VIN is shown on the bottom of the BMW ConnectedDrive app (at least in the Dutch version).

And the url shoud not contain https:// in front of it, should be just like the example I have put in the comments in the script at that line.

I will add some code in the script to check for this.

Changing the VIN to the full number causes an 404 return of the script, and yes I’m using the URL without https or http.

Did you put all these fields within quotes in the script? So like this example:
URL = ""