Edit: BMW ConnectedDrive is available in Home Assistant 0.64. Check this post for further explanation.
I came across this URL today https://github.com/jupe76/bmwcdapi which contains a Python script to access the BMW ConnectedDrive which is used for Openhab. This is really awesome
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
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.
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 bmwcdapi.py -p i receive the following error:
pi@homeberry:~/bmwcdapi $ python3 bmwcdapi.py -p
...running bmwcdapi.py
Traceback (most recent call last):
File "bmwcdapi.py", line 263, in <module>
main()
File "bmwcdapi.py", line 234, in main
c = ConnectedDrive()
File "bmwcdapi.py", line 43, in __init__
self.bmwUsername = self.ohGetValue("Bmw_Username").json()["label"]
File "/usr/local/lib/python3.6/site-packages/requests/models.py", line 892, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/local/lib/python3.6/json/__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "/usr/local/lib/python3.6/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/local/lib/python3.6/json/decoder.py", 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)
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.
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. www.bmw-connecteddrive.nl or www.bmw-connecteddrive.de
URL = None # "www.bmw-connecteddrive.nl"
Then you are able to run it with: ./bmwcdapi.py -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
@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.
I just realize I really need a test drive in your M2 before I can add this component to Home Assistant
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.
Traceback (most recent call last):
File "/Users/me/PycharmProjects/untitled/bmwcdapi.py", line 375, in <module>
main()
File "/Users/me/PycharmProjects/untitled/bmwcdapi.py", line 342, in main
c = ConnectedDrive()
File "/Users/me/PycharmProjects/untitled/bmwcdapi.py", line 84, in __init__
self.generate_credentials()
File "/Users/me/PycharmProjects/untitled/bmwcdapi.py", line 125, in generate_credentials
tokenType = (m.group(2))
AttributeError: 'NoneType' object has no attribute 'group'
Process finished with exit code 1
Well, I got further. It looks like I have a connecteddrive.bmwusa.com account where I can see my car, its status, and everything and separately I have a customer.bmwgroup.com 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.
…running bmwcdapi.py
400
Traceback (most recent call last):
File “bmwcdapi.py”, line 345, in
main()
File “bmwcdapi.py”, line 333, in main
execStatusCode = c.get_car_data()
File “bmwcdapi.py”, 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.
I indeed noticed that the url for USA differs from other countries, where it is www.bmw-connecteddrive.[countrycode].
I will have a look at the customer.bmwgroup.com url to see if my car is registered there.
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.