Script to access the BMW ConnectedDrive portal via OH

Anyone figured the meaning of the soc_hv_percent reading? I graphed it for a couple of weeks and it is close to the displayed soc (chargingLevelHv), but is rarely the same. Most of the time it is a bit higher, but can be lower too.

My script stopped working a few days ago:

 python3 bmwcdapi.py
...running bmwcdapi.py
Traceback (most recent call last):
  File "bmwcdapi.py", line 327, in <module>
    main()
  File "bmwcdapi.py", line 291, in main
    c = ConnectedDrive()
  File "bmwcdapi.py", line 69, in __init__
    self.generateCredentials()
  File "bmwcdapi.py", line 105, in generateCredentials
    self.accessToken=myPayLoad['access_token']
KeyError: 'access_token'

I see no one else is complaining. A problem with the US server?

@peter_juenger
can you offer any suggestion? I understand that my token expired and the script can’t get a new one, but i have no idea what to do about it.

@stopeject
Hi, I’m sorry but there’s nothing I can do about it now.
From similar scripts for other smarthome solutuions the same problem is reported from users in North America.
Seems that BMW has changed something in authorization mechanism.

Thanks Peter. BMW will probably apply the change to other servers and someone will reverse the new protocol.

The script came back online by itself about a week ago. But it doesn’t pull the battery condition data- socMax anymore. Anyone outside of North America still see socMax?

Here (in Germany) is everything as before, socMax is provided.

I’ve read that BMW US / Canada has rolled back the change that prohibited access of ConnectedDrive.

For my BMW 530d F11 2015 the script is working properly, the running bmwcdapi.py is delivering a set of data. But unfortunately no update on the data since weeks! Just like being a cache problem…Any idea how to solve this status (after several opanhab2 reboots)? Thanks.

I am trying to log all the trips on my i3 (start_position, end_position, distance, start_time, end_time and KWh_spent). Do you think it is possible using this solution?

Thx

It should be possible if you’re familiar with openHAB.
Probably the polling time has to be lowered somewhat to ensure that you get the end of a trip and the begin of a new one.

I can’t get this to work at all. Is the service no longer available? Tried pinging and connecting by browser to the server (b2vapi.bmwgroup.com), but it can’t be accessed.

I’m in Europe by the way.

The script works here (Germany) without issues.
It seems that b2vapi.bmwgroup.com doesn’t respond to pings.
If you use a browser, remember to use https (https://b2vapi.bmwgroup.com/)

Strange. This is the error message that I get. I’ve also tried running the script directly from the console, with the same output. Can you see what is wrong?

2019-09-29 23:06:43.504 [INFO ] [ipse.smarthome.model.script.bmwcdapi] - climate

2019-09-29 23:06:45.277 [INFO ] [ipse.smarthome.model.script.bmwcdapi] - …running bmwcdapi.py

Traceback (most recent call last):

File “/usr/lib/python3/dist-packages/urllib3/connectionpool.py”, line 600, in urlopen

chunked=chunked)

File “/usr/lib/python3/dist-packages/urllib3/connectionpool.py”, line 343, in _make_request

self._validate_conn(conn)

File “/usr/lib/python3/dist-packages/urllib3/connectionpool.py”, line 841, in _validate_conn

conn.connect()

File “/usr/lib/python3/dist-packages/urllib3/connection.py”, line 344, in connect

ssl_context=context)

File “/usr/lib/python3/dist-packages/urllib3/util/ssl_.py”, line 344, in ssl_wrap_socket

return context.wrap_socket(sock, server_hostname=server_hostname)

File “/usr/lib/python3.7/ssl.py”, line 412, in wrap_socket

session=session

File “/usr/lib/python3.7/ssl.py”, line 853, in _create

self.do_handshake()

File “/usr/lib/python3.7/ssl.py”, line 1117, in do_handshake

self._sslobj.do_handshake()

ssl.SSLError: [SSL: UNSUPPORTED_PROTOCOL] unsupported protocol (_ssl.c:1056)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File “/usr/lib/python3/dist-packages/requests/adapters.py”, line 449, in send

timeout=timeout

File “/usr/lib/python3/dist-packages/urllib3/connectionpool.py”, line 638, in urlopen

_stacktrace=sys.exc_info()[2])

File “/usr/lib/python3/dist-packages/urllib3/util/retry.py”, line 398, in increment

raise MaxRetryError(_pool, url, error or ResponseError(cause))

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)’)))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File “/etc/openhab2/scripts/bmwcdapi.py”, line 332, in

main()

File “/etc/openhab2/scripts/bmwcdapi.py”, line 296, in main

c = ConnectedDrive()

File “/etc/openhab2/scripts/bmwcdapi.py”, line 69, in init

self.generateCredentials()

File “/etc/openhab2/scripts/bmwcdapi.py”, line 100, in generateCredentials

r = requests.post(url, data=data, headers=headers,allow_redirects=False)

File “/usr/lib/python3/dist-packages/requests/api.py”, line 116, in post

return request('post', url, data=data, json=json, **kwargs)

File “/usr/lib/python3/dist-packages/requests/api.py”, line 60, in request

return session.request(method=method, url=url, **kwargs)

File “/usr/lib/python3/dist-packages/requests/sessions.py”, line 533, in request

resp = self.send(prep, **send_kwargs)

File “/usr/lib/python3/dist-packages/requests/sessions.py”, line 646, in send

r = adapter.send(request, **kwargs)

File “/usr/lib/python3/dist-packages/requests/adapters.py”, line 514, in send

raise SSLError(e, request=request)

requests.exceptions.SSLError: 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)’)))

Is it possible to send messages to car with this script?

@mariusc
For me it seems that your host system doesn’t support the needed TLS protocol for the bmw webservice and tries to use SSL instead.
I’d suggest updating the host system.

@e36Alex
It is possible with the command "–sendmesg "

Today i wanted to try out the scipt, but there is something going wrong:
I don’t drive a BMWi, but a G31.

20:32:43.451 [INFO ] [smarthome.event.ItemStateChangedEvent] - Bmw_ForceUpdate changed from NULL to ON
20:32:43.470 [INFO ] [lipse.smarthome.model.script.bmwcdapi] - forced connectedDrive API call
20:32:43.575 [INFO ] [lipse.smarthome.model.script.bmwcdapi] - Traceback (most recent call last):
  File "/etc/openhab2/scripts/bmwcdapi.py", line 23, in <module>
    import requests
ImportError: No module named 'requests'

For me it seems that your requests library is missing.
Try “sudo pip install requests”

thanks for your fast reply!
i tried the command an requests was installed, but i still get the same error message.

Depending on your OS and the installed python-versions another guess:

sudo pip3 install requests

1 Like