Script to access the BMW ConnectedDrive portal via OH

Thanks for posting your results.

Another thing that might be odd right now is that I’ve assumed that the distance unit would be km and not miles.

AWESOME!!!
Works for me as well!! U DA MAN :wink:

And yes, will need to update distance according to the region :slight_smile:

Tried it again few hours later and got this:

root@S:/volume1/@appstore/openHAB/conf/scripts# /volume1/@appstore/python3/bin/python3 bmwcdapi.py --printall
...running bmwcdapi.py
Traceback (most recent call last):
  File "bmwcdapi.py", line 310, in <module>
    main()
  File "bmwcdapi.py", line 274, in main
    c = ConnectedDrive()
  File "bmwcdapi.py", line 57, in __init__
    if((self.tokenExpires == 'NULL') or (int(time.time()) >= int(self.tokenExpires))):
ValueError: invalid literal for int() with base 10: 'FVdGnHM36CxFYtPTdSRajFw8525IA5z7XAVXujPlqNwCLzBE'

@stopeject
Thanks for pointing that out :slight_smile:

Should be fixed now.

Yes, working again!
I will probably need to wait a couple of hours until the token expires to be completely sure.
Thank you, Peter.

@xsherlock, can you please share how you configured the SOC chart.

Sure, it is made in grafana, you need to install grafana/influx combo first. There is a megathread on that issue but the instructions from the first post work.

Then it is just adding two queries for SOC and daili trip.
The SOC chart in attached screenshot is cut as I was on the long holidays and did not drive the car.

1 Like

Thank you, I started working on it, but it seems like an uphill battle for an openhab newbie.

You can set up nice looking charts in HABPanel (it comes with openHAB) within minutes.
Of course these charts are limited compared with grafana, but I think for the first it is sufficient.

It took me a bit of trial and error to install Influxdb and Grafana, but I got there eventually and everything is working albeit in a rough form. Very cool. I wish I knew about this earlier. I’ve never seen it discussed on the i3 forum or Facebook group.

Hi Peter,
Do you know if it‘s possible to get informations about the navigation?
I would like to get the information about which address i‘m heading to and what‘s the ETA.
Do you know if this is possible?

Kind regards
Michael

Hi Michael,

Have you seen this? Google Maps with traffic.

Regards,

Garry

Yes but it´s not exactly what i want.

My plan:

  • Starting the car and choosing my home address
  • oH will receive an information about the navigation address and ETA
  • My wife get´s a message that i´m on my way home and what´s the current ETA
  • 15min before arrvival, send another ETA

The mentioned solution would still need an trigger to know that i´m heading home.
It shouldn´t be a problem to use the solution for more dynamic addresses when opening the API from an rule.
But i still wouldn´t know when the car is started and the navigation is set to my home address.
I don´t have an static way between a workplace and home.

There was a IFTTT integration of some BMW models between 2013 and 2015 with BMW labs.
As my car is from 2017 this doesn´t work any more and it was a bad integration anyway.
You need to have the BMW labs widget opened in splitscreen all the time for the IFTTT triggers to work.

kind regards
Michael

Sounds like a very sensible plan. All of this is available in the Waze app, but that’s only for reference and not a solution. My car is a 2012 model and doesn’t provide very much information at all, which is a shame as I enjoy playing around with these kind of ideas.

As BMW don’t offer a publicly accessible API it makes things even more difficult and you’ll have to almost reverse engineer what is available via the ConnectedDrive platform. My car allows me to send a desired destination from both the web portal and the App. But I can’t view that data using the script, which is frustrating to say the least.

So your solution needs both your present location and SatNav selected destination. It does look like the script can obtain GPS location, so your halfway there. Feeding your present location and home location into the GoogleMaps script, I shared, should give you an approximate travel time. Then you can set a timer minus 15 minutes that triggers notification 15 minutes from home. I would go one stage further and setup a voice announcement, using Sonos, if someone is home. But that’s just me. If your car provides the GPS location via the script then maybe you could poll every 10 minutes to see if that GPS location has changed. If the assumption your always going to be travelling home then you may get a part solution working.

Thanks for your help.
The script already gives me the current position and i´ve got some things integrated with Alexa.
Like asking where´s the car and Alexa answers with the current position (transformed to an address with OSM) or “in the garage”.
The script executes every 10 minutes and gives me the current data.
So you´re right, halfway done :slight_smile:

I know that Waze or Glympse offer some similiar function, but they´re not automated.
I would like to have the automation :wink:

The question is: Does the ConnectDrive portal offers the current SatNav destination?
How could i find this information?

As you can send destinations to the car and they are picked up by the SatNav I would assume that information is accessible to a degree. Where that information is I’m not sure, may be this is something that @peter_juenger can help with.

An alternative could be to use tasker if your using an Andriod phone. That way could setup a script that uses the restAPI for OH to update your destination when the phone connects to the cars bluetooth. Again there are limits to how you can get that to work. I’ve used tasker in the past and it was pretty powerful then, so as time moves on I’m sure it’s improved further. Sadly if your using a iPhone then your out of luck.

Keep us all posted on your progress. I’m sure other will also find this of interest.

@Bredmich:
nice idea, but I think it’s not possible with the script for now, at least not with my head unit (NBT).
The script can only query data that is present on the connected Drive Portal, either visible or invisible (as SocMax, which is used for some calculations)

My car have the Nbt2 unit and is from 11/2017.
How could i check if the Connected Drive Portal has this information?
Is there some kind of standard query to get all available informations?

Thanks!

@Bredmich
You could call bmwcdapi.py from commandline with the parameter -p (or --print).
That will give you all information which is received from the services that are implemented (efficiency, dynamic, navigation).

It is know that there are some more services (remote_execution, remote_chargingprofile, remote_history, servicepartner, service, specs, store, map_download) but I’m not getting any information from them at all or the information is more or less useless (e.g. servicepartner).

If you want to try some of these with the -p parameter just copy something like

    r = requests.get(VEHICLE_API+'/YOURSERVICEHERE/v1/'+self.bmwVin, headers=headers,allow_redirects=True)
    if (r.status_code== 200):
        if(self.printall==True):
            for k, v in r.json().items():
                print(k, v)

with correct indentation at the end of the method “queryData”.

1 Like

Works very well. Thanks for your efforts!