Script to access the BMW ConnectedDrive portal via OH

thanks! i had to install phython3 instead of 2.7 at first - now it works fine!

Hi Peter,

i just had time to play around with the script again.
I tried to add the lines for every listed service but the script stops at some of them

service, specs:

Traceback (most recent call last):
  File "bmwcdapi.py", line 315, in <module>
    main()
  File "bmwcdapi.py", line 305, in main
    execStatusCode = c.queryData()
  File "bmwcdapi.py", line 158, in queryData
    for k, v in map.items():
AttributeError: 'list' object has no attribute 'items'

And none of the other services shows relevant informations.
Sometimes the script collects less informations…
In 2 out of 5 tests some of the informations that are normaly present were missing.
Like the door_passenger_front value.

Would´ve nice to get the current navigation destination and build something with it.

kind regards
Michael

Continuing the discussion from Script to access the BMW ConnectedDrive portal via OH:

Hello,

i don´get the script going to work. i have a line while the script is running:

urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host=‘b2vapi.bmwgroup.com’, port=443): Max retries exceeded with url: /gcdm/oauth/token (Caused by SSLError(SSLError(1, ‘[SSL: UNSUPPORTED_PROTOCOL] unsupported protocol (_ssl.c:1056)’)))

don´t know what to do :confused:

May somebody has an idea?

Thx a lot

@Daniel_Bohne
That sounds to me like same problem as described here .

For me it seems that your host system doesn’t support the needed TLS protocol (-version) for the bmw webservice.

On what base system are you running openhab?
Is your system up-to-date?

Hi @peter_juenger,

great work with this script but I have now an problem with the call of the services (like light, horn etc.).
It doesn’t work anymore. I’m receiving the status code 403 (Forbidden) in line 241 (request.post). The usual informations about the car are stll working, so the communication itself seems to be ok.
Any ideas?
Greetings

Btw. I think you should add an return statemant in this if case. Else the execStatusCode will be overwritten with that one from line 260 and you will get the wrong StatusCode. (I had this problem…)

Hi @Markinus,

you’re absolutly right. I can reproduce the problem by myself, the 403 error as well as not catching the error code.
Thanks for pointing it out, I’ll look into it.
BMW seems to change a lot of stuff at connected drive recently.
Does calling services work properly with the original ConnectedDrive app?

Hi,

yes, the BMW app works without any problems.

Greetings

Apparently, the BMW Connected Drive Portal supports only connections via TLS v1.0. After changing in /etc/ssl/openssl.cnf MinProtocol from TLSv1.2 to TLSv1.0 the script works like a charm!

Regards,
Christian

1 Like

@christianw: Thanks for working that out. Besides that I think that only TLS 1.0 is a shame nowadays.

Did anyone manage to fix the issues with the new way of BMW’s authentication?
The HomeAssistant guys have fixed it, but unfortunately my Python knowledge is not that good to patch up the OH script… Anyone wanna try?

SOLVED:
I’ve tried and it seems like I succeeded. My OpenHAB items have updated after running the script I have slightly modified. (based on https://github.com/bimmerconnected/bimmer_connected/releases/tag/0.7.0)
Just rename it to .py and run :slight_smile:
Enjoy!

bmwcdapi.py.txt (13.5 KB)

I’ve pushed a fix to the repo based on the bimmer_connected lib.
Authentication should work again now, at least for “the rest of the world”.

@Jagohu: Nice, but there’s a small flaw in your changes. The server b2vapi.bmwgroup.com for the requests has to be leaved unchanged. Only the URL for the authentication has to be customer.bmwgroup.com.

Thank you very much! I didn’t mean to interfere with your work, I just thought you did not plan to maintain it anymore and tried to somewhat fix it with the new API requirements - but it’s much better, that you did it properly! Thank you for all your efforts!

i used the new script, but it doesnt work. my items didnt get an update.
in the logs i got the following entries:

14:55:49.310 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Bmw_ForceUpdate' received command ON
14:55:49.321 [INFO ] [smarthome.event.ItemStateChangedEvent] - Bmw_ForceUpdate changed from NULL to ON
14:55:49.426 [INFO ] [lipse.smarthome.model.script.bmwcdapi] - forced connectedDrive API call
14:55:49.539 [INFO ] [lipse.smarthome.model.script.bmwcdapi] - Traceback (most recent call last):
  File "/etc/openhab2/scripts/bmwcdapi.py", line 31, in <module>
    import requests
ImportError: No module named 'requests'

@e36Alex:
You need to install the “request” module for python 3.x.
Depending on your distro that would be something like

sudo pip install requests

Thanks for that!

Now i dont get an error message into the logs, but still items are not updated:

16:51:52.604 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Bmw_ForceUpdate' received command ON
16:51:52.608 [INFO ] [lipse.smarthome.model.script.bmwcdapi] - forced connectedDrive API call
16:51:53.416 [INFO ] [lipse.smarthome.model.script.bmwcdapi] - ...running bmwcdapi.py

@e36Alex:
Try running the script with parameter -p

/etc/openhab2/scripts/bmwcdapi.py -p

If it prints the values, then your setup is faulty somewhere.

thanks, i get the same result…

root@192.168.178.11:~# /etc/openhab2/scripts/bmwcdapi.py -p
...running bmwcdapi.py

as region i added the following item - does it have the right value for europe/germany?

String Bmw_Region "rest_of_world"

Hello,

First, I want to thanks you for this binding. Very good job.
I got my new car, and already connect it to my openhab successfully.

But … I cannot used the actions. Light, horn, lock/unlock doesn’t works. I got a 503 result when trying to do actions… (so, action exit with error 70)

Did I miss something ? Is it working for others ?

I am in Europe, car is a new Serie 3. Python is 3.7. Getting info works fine.

Any ideas ?

Thanks,

Frederic

@ifred:
Sending commands to the car is broken right now. It’s on my todo list since several weeks.

Currently I’m into selling my i3 and I’m not shure wheter my next car will be another i3 (fantastic car btw.) or something else.

So I’ll take a quick look into it today to see if I can spot the problem. After selling the car I’m afraid I can no longer be helpful in this.

@ifred:
It seems that the URL for sending commands has changed from …/remoteservices/v1/… to …/remoteservices/rsapi/v1/…

With a little luck it will be sufficient to change the URLs.
Will try it tonight.