BMW ConnectedDrive component

I get an error:

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

and the mypayload variable was set to: https://www.bmw-connecteddrive.com/app/default/static/external-dispatch.html?error=access_denied

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.

I’ve got nearly the same error:

…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.

in function:

def get_car_data(self):
map_car_data = 0

and

def get_car_navigation(self):
map_car_navigation = 0

result:

pi@homeberry:~/bmwcd/bmwcd $ python3 bmwcdapi.py -p
...running bmwcdapi.py
400
400
400
400

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 www.bmw-connecteddrive.[countrycode].
I will have a look at the customer.bmwgroup.com url to see if my car is registered there.

Edit: I go to https://www.bmw-connecteddrive.nl and when pressing the Login button that forwards me to https://customer.bmwgroup.com 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 = "www.bmw-connecteddrive.de"

image

doesn’t matter if I’m using " oder ’ - same error

any way to get more output than the 404 reply so i can specify whats going on there?

I have checked this with @irnqnet offline and it’s showing data (partly) when using
bmwcdapi.py -p.

Will do some extra checks what is causing the 404 in the script and release an updated version.

In the meanwhile of I have changed the script on Github so it contains some more information on what data to enter in the fields including some examples, where you have to replace the None parts with your data as shown in the examples in those lines.

# ----=================================================----
# 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"
# ----=================================================----

Useful hints right now:

the values for username, password, VIN and URL have to be included in " " or ’ ’

For registering my car in the german version of the BMW connected app I have to use the last 7 digits of my VIN. To use this script it is necessary to use the whole VIN (in my case 17 digits)

This is how the Volvo On Call looks like:

1 Like

Thanks for posting the script. Here’s the output.

...running bmwcdapi.py
--------------START CAR DATA--------------
DCS_CCH_Activation: None
DCS_CCH_Ongoing : None
gps_lat: 50.000000
gps_lng: 8.000000
head_unit: EntryNav
head_unit_pu_software: 11/15
lastUpdateReason: Error
unitOfCombustionConsumption: l/100km
unitOfElectricConsumption: kWh/100km
unitOfEnergy: kWh
unitOfLength: km
vehicle_tracking: 1
--------------END CAR DATA--------------
--------------START CAR NAV--------------
auxPowerEcoPro: 1.0
auxPowerEcoProPlus: 1.0
auxPowerRegular: 1.0
isoCountryCode: DEU
latitude: 50.000000
longitude: 8.000000
pendingUpdate: False
soc: 0.0
socMax: 17.84
vehicleTracking: True
--------------END CAR NAV--------------
--------------START CAR EFFICIENCY--------------
characteristicList: [{'characteristic': 'CONSUMPTION', 'quantity': 0}, {'characteristic': 'DRIVING_MODE', 'quantity': 0}, {'characteristic': 'CHARGING_BEHAVIOUR', 'quantity': 0}, {'characteristic': 'ELECTRIC_DRIVING', 'quantity': 0}]
efficiencyQuotient: 0
lastTripList: []
lifeTimeList: []
modelType: PHEV
--------------END CAR EFFICIENCY--------------
--------------START CAR SERVICEPARTNER--------------
businessFax: ...

The only useful information I get is the position. Which is nice. But for me the mileage and fuel-stats would be way more interesting. :-/
For reference (since we can’t change what data the API delivers), the exact type of my XY:

  • Model: X1 sDrive18d
  • E-Code: F48
  • Production Code: HT71
  • Manufactured late 2016

I wonder why there is such a difference between so similar (even same model) cars.

Got the same car, at least 2017 model. But the information you will get as result of the script depends on the connected drive subscription you have. Do you have the remote services subscribed in your account?

That are the subscriptions in my account:

result of the script:

...running bmwcdapi.py
--------------START CAR DATA--------------
DCS_CCH_Activation: None
DCS_CCH_Ongoing : None
beRemainingRangeFuel: 762.0
beRemainingRangeFuelKm: 762.0
beRemainingRangeFuelMile: 473.0
check_control_messages: 
condition_based_services: 00001,OK,2019-09,26000;00100,OK,2021-09,60000;00003,OK,2020-09,;00032,OK,2020-11,
door_driver_front: CLOSED
door_driver_rear: CLOSED
door_lock_state: SECURED
door_passenger_front: CLOSED
door_passenger_rear: CLOSED
gps_lat: 51.xxxx
gps_lng: 6.xxxx
head_unit: EntryEvo
head_unit_pu_software: 07/17
heading: 298
hood_state: CLOSED
kombi_current_remaining_range_fuel: 762
lastUpdateReason: VEHCSHUTDOWN_SECURED
lights_parking: OFF
lsc_trigger: VEHCSHUTDOWN_SECURED
mileage: 3872
remaining_fuel: 51
trunk_state: CLOSED
unitOfCombustionConsumption: l/100km
unitOfElectricConsumption: kWh/100km
unitOfEnergy: kWh
unitOfLength: km
updateTime: 20.01.2018 17:38:35 UTC
updateTime_converted: 20.01.2018 18:38
updateTime_converted_date: 20.01.2018
updateTime_converted_time: 18:38
updateTime_converted_timestamp: 1516473515000
vehicle_tracking: 1
window_driver_front: CLOSED
window_driver_rear: CLOSED
window_passenger_front: CLOSED
window_passenger_rear: CLOSED
--------------END CAR DATA--------------
--------------START CAR EFFICIENCY--------------
characteristicList: [{'characteristic': 'CONSUMPTION', 'quantity': 0}, {'characteristic': 'DRIVING_MODE', 'quantity': 0}, {'characteristic': 'CHARGING_BEHAVIOUR', 'quantity': 0}, {'characteristic': 'ELECTRIC_DRIVING', 'quantity': 0}]
efficiencyQuotient: 0
lastTripList: []
lifeTimeList: []
modelType: PHEV
--------------END CAR EFFICIENCY--------------
--------------START CAR SERVICEPARTNER--------------
businessFax: +49 xxxxxxxx
businessPartnerId: xxxxxxxxx
businessPhone: +49 xxxxxxxx
city: xxxxxxx
country: DE
countryIsoCode: DE
dealerName: xxxxxxxxxxxxxxxxxxxxxx
email: info@xxxxxxxxxxxx
lastChangeDate: 2018-01-20T21:12:29.000+01
partnerNumber: xxxxxxxxxx
portfolioCodes: B1,MI
portfolioNames: BMW Cars,MINI
street: xxxxxxxxxxxxxxxxx
subsidiaryNumber: 1
url: xxxxxxxxxxxxxxxxxxxx
zipCode: xxxxxx
--------------END CAR SERVICEPARTNER--------------
1 Like

These are my services:

I think it may be the BMW Connected+ that’s causing the trouble. Unfortunately, when I try to order the service it says my car is not compatible. Maybe mine has some older hardware installed. :frowning:

Mh might be, but I can’t imagine. Are you able to see more details using the BMW connected app?

https://play.google.com/store/apps/details?id=de.bmw.connected

No, these details are missing there as well. I knew that. I just hoped getting those numbers via this script could do more than the app.

What I have done now is that I have requested the CarData Archive. This seems to take a while. But maybe it has the interesting data as well. Which is rather useless, but nice to know.

I can confirm that I also have Connected+ available for my X1 2017 model. Probably something that changed with the new model which launched in June/July last year.

I did the same this afternoon. Maybe that data get’s visible in the CAR EFFICIENCY part, but we indeed have to wait for an email which will be send when the data is available.