BMW ConnectedDrive component

I have configured the Component according to the documentation (but removed name). However this is what I am seeing:

Log Details (ERROR)
Wed Feb 28 2018 13:02:26 GMT+0100 (W. Europe Standard Time)
Error during setup of component bmw_connected_drive
Traceback (most recent call last):
File “/usr/lib/python3.6/site-packages/homeassistant/setup.py”, line 148, in _async_setup_component
component.setup, hass, processed_config)
File “/usr/lib/python3.6/asyncio/futures.py”, line 332, in iter
yield self # This tells Task to wait for completion.
File “/usr/lib/python3.6/asyncio/tasks.py”, line 250, in _wakeup
future.result()
File “/usr/lib/python3.6/asyncio/futures.py”, line 245, in result
raise self._exception
File “/usr/lib/python3.6/concurrent/futures/thread.py”, line 56, in run
result = self.fn(*self.args, **self.kwargs)
File “/usr/lib/python3.6/site-packages/homeassistant/components/bmw_connected_drive.py”, line 52, in setup
bimmer = BMWConnectedDriveAccount(username, password, country, name)
File “/usr/lib/python3.6/site-packages/homeassistant/components/bmw_connected_drive.py”, line 83, in init
self.account = ConnectedDriveAccount(username, password, country)
File “/usr/lib/python3.6/site-packages/bimmer_connected/account.py”, line 52, in init
self._get_vehicles()
File “/usr/lib/python3.6/site-packages/bimmer_connected/account.py”, line 158, in _get_vehicles
self._get_oauth_token()
File “/usr/lib/python3.6/site-packages/bimmer_connected/account.py”, line 83, in _get_oauth_token
self._oauth_token = url_with_token[‘access_token’][0]
KeyError: ‘access_token’

This is my configuration:
bmw_connected_drive:
mycar:
username: [email protected]
password: mySecretPass
country: Sweden

What shall I do to troubleshoot?

@silfa718 Try both before and after login, I guess.

@ChristianKuehnel I think the API is located at https://b2vapi.bmwgroup.us but the problem is my account can’t seem to get a OAuth access token from customer.bmwgroup.com or wherever the OAuth server is. Maybe there is a different server for Canada and the USA that we need to be looking for?

2018-02-27 23:46:57 ERROR (MainThread) [homeassistant.setup] Error during setup of component bmw_connected_drive
Traceback (most recent call last):
  File "/srv/homeassistant/homeassistant/lib/python3.5/site-packages/homeassistant/setup.py", line 148, in _async_setup_component
component.setup, hass, processed_config)
  File "/usr/lib/python3.5/asyncio/futures.py", line 361, in __iter__
yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 296, in _wakeup
future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 274, in result
raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/homeassistant/lib/python3.5/site-packages/homeassistant/components/bmw_connected_drive.py", line 52, in setup
bimmer = BMWConnectedDriveAccount(username, password, country, name)
  File "/srv/homeassistant/homeassistant/lib/python3.5/site-packages/homeassistant/components/bmw_connected_drive.py", line 83, in __init__
self.account = ConnectedDriveAccount(username, password, country)
  File "/srv/homeassistant/homeassistant/lib/python3.5/site-packages/bimmer_connected/account.py", line 52, in __init__
self._get_vehicles()
  File "/srv/homeassistant/homeassistant/lib/python3.5/site-packages/bimmer_connected/account.py", line 158, in _get_vehicles
self._get_oauth_token()
  File "/srv/homeassistant/homeassistant/lib/python3.5/site-packages/bimmer_connected/account.py", line 83, in _get_oauth_token
self._oauth_token = url_with_token['access_token'][0]
KeyError: 'access_token'

I’m having a problem with configuration.yaml. Fails!!

Testing configuration at /config
ERROR:homeassistant.config:Invalid config for [bmw_connected_drive]: [name] is an invalid option for [bmw_connected_drive]. Check: bmw_connected_drive->bmw_connected_drive->mycar->name. (See /config/configuration.yaml, line 66). Please check the docs at https://home-assistant.io/components/bmw_connected_drive/
ERROR:homeassistant.setup:Setup failed for bmw_connected_drive: Invalid config.
Failed config
bmw_connected_drive:
mycar: [source /config/configuration.yaml:67]
country: USA
name: XXXX <------- This is the problem. Not liasted on the USA Site
password: my password
username: my username

Where do I find the “name:” It is not listed anywhere on https://connecteddrive.bmwusa.com

It has alll my other data…

Thanks

You don’t need the “name” part just leave it out.

the documentation is broken, a patch is on the way…
https://github.com/home-assistant/home-assistant.github.io/pull/4769

@coolTNT

What I did for the German website:
I used the developer console from Google Chrome and observed me logging into the connected drive site. And there is one URL where the browser sends the username/password and get the “access_token” back in the header of the response.

What I would need are examples of:

  • the url that the login request is sent to
  • an example of the request header (to see if the format is the same)
  • an example of the response header (to see if the format is the same)

I can’t analyze that as I can’t create a Canadian Connected Drive account without a Canadian vehicle…

Thanks for the very fast reply… I did see that in the documentation and left the name: but got the error.

Thanks for adding this!!! It will be very handy…

The proper example of the config file is:

bmw_connected_drive:
  some_random_name:
    username: USERNAME_BMW_CONNECTED_DRIVE
    password: PASSWORD_BMW_CONNECTED_DRIVE
    country: COUNTRY_BMW_CONNECTED_DRIVE

The problem here is that obviously the US and Canadian Connected Drive portals are using a different URL to login via username/password. So i need someone with such an account to figure out the parameters (see my comment above: BMW ConnectedDrive component)

I’ll take a look

The url that the login request is sent to:

Request URL:https://crm.bmw.ca/en-CA/ConnectedDrive/Account
Request Method:POST
Status Code:302 Found
Remote Address:170.34.127.29:443
Referrer Policy:no-referrer-when-downgrade

Request header:

Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Accept-Encoding:gzip, deflate, br
Accept-Language:en-US,en-CA;q=0.9,en;q=0.8
Cache-Control:no-cache
Connection:keep-alive
Content-Length:226
Content-Type:application/x-www-form-urlencoded
Cookie:_ceir=1; _ceir=1; _ga=GA1.2.1358790589.1519157268; mbox=PC#5f453cbf5afe489c8e1a00cba67ceabe.28_36#1521138783|check#true#1519929243|session#0773a9326d19454988d8bf3811a24a24#1519931043; bmwdtm_hq_vs=1519929182; AMCVS_B52D1CFE5330949C0A490D45%40AdobeOrg=1; AMCV_B52D1CFE5330949C0A490D45%40AdobeOrg=1406116232%7CMCIDTS%7C17592%7CMCMID%7C82524880656740560990890069398466268113%7CMCAAMLH-1520533982%7C9%7CMCAAMB-1520533982%7CRKhpRz8krg2tLO6pguXWp5olkAcUniQYPHaMWWgdJ3xzPWQmdj0y%7CMCOPTOUT-1519936382s%7CNONE%7CMCAID%7CNONE%7CvVersion%7C2.5.0; s_cc=true; ASP.NET_SessionId=yzun3h1j02w2yohodym0ytu1; __RequestVerificationToken=SDHbxv7X7KYwJEGcgLsE4rWhZe0IouMtds-6WcdHHK9CuSZAkqcpUPQOIBzUHvdXs8Mz6WauX4kFIWfhhBMonOQr5CMiknK_x5BuCPIfluz-ACYqeDBRLIBbbiALis1CcaaJ9A2; content-bmwca.bmwgroup.net=3579912874.16927.0000; _gid=GA1.2.46712706.1519929328; CDSESSION=d93a5cc7-60f0-4b0c-837a-403918714e4e; _gat=1; _ceg.s=p4xefu; _ceg.u=p4xefu
Host:crm.bmw.ca
Origin:https://crm.bmw.ca
Pragma:no-cache
Referer:https://crm.bmw.ca/en-CA/ConnectedDrive/Account
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36

Response header:

Access-Control-Allow-Origin:*
Cache-Control:private
Connection:Keep-Alive
Content-Length:138
Content-Type:text/html; charset=utf-8
Date:Thu, 01 Mar 2018 19:07:28 GMT
Keep-Alive:timeout=15, max=100
Location:/en-CA/ConnectedDrive
p3p:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"
Server:Microsoft-IIS/7.5
Set-Cookie:CDSESSION=2b3f7cde-737d-405a-b7d2-7514ebe1d919; expires=Fri, 02-Mar-2018 07:07:28 GMT; path=/
Set-Cookie:CDSESSION=61b0f69d-b6f0-4b46-96ba-638b2812699f; expires=Fri, 02-Mar-2018 07:07:28 GMT; path=/
Strict-Transport-Security:max-age=31536000
X-AspNet-Version:4.0.30319
X-AspNetMvc-Version:4.0
X-Powered-By:ASP.NET

Form data:

__RequestVerificationToken:token
LoginId:[email protected]
Password:password
RememberMe:false

This should be fixed in HA 0.64.2 which is just released.

That’s already the case :grinning:
When the door_lock_state is LOCKED or SECURED:

  • The lock (switch) has a locked icon
  • The status of the binary sensor ‘Door lock state’ is shown as Safe

When the door_lock_state is SELECTIVELOCKED or UNLOCKED:

  • The lock (switch) has an unlocked icon
  • The status of the binary sensor ‘Door lock state’ is shown as Unsafe

I see you don’t have that binary sensor in your group, but it’s already available, so you can add that.
Quickest way to find all sensors available for your car is to go to Developer tools - States and go to Filter attributes where you can enter the type of your car, in your case X1 sDrive18d.

You can add control: hidden to your BMW X1 Group so no On/Off switch is shown in the header, which will avoid you to accidentally switch on the horn, lights and climate at the same time :wink:

now we are talking business :ok_man::rofl:

No change here with 64.2, still loads of errors:

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/lib/python3.6/asyncio/tasks.py", line 180, in _step
    result = coro.send(None)
  File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 223, in async_update_ha_state
    device_attr = self.device_state_attributes
  File "/config/custom_components/switch/bmw_connected_drive.py", line 69, in device_state_attributes
    'last_update': vehicle_state.timestamp,
  File "/config/deps/lib/python3.6/site-packages/bimmer_connected/state.py", line 46, in _func_wrapper
    raise ValueError('No data available!')
ValueError: No data available!
2018-03-02 08:43:13 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/config/deps/lib/python3.6/site-packages/bimmer_connected/state.py", line 44, in _func_wrapper
    return func(self, *args, **kwargs)
  File "/config/deps/lib/python3.6/site-packages/bimmer_connected/state.py", line 91, in timestamp
    unix_time = int(self._attributes['updateTime_converted_timestamp'])
KeyError: 'updateTime_converted_timestamp'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/lib/python3.6/asyncio/tasks.py", line 180, in _step
    result = coro.send(None)
  File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 223, in async_update_ha_state
    device_attr = self.device_state_attributes
  File "/config/custom_components/switch/bmw_connected_drive.py", line 69, in device_state_attributes
    'last_update': vehicle_state.timestamp,
  File "/config/deps/lib/python3.6/site-packages/bimmer_connected/state.py", line 46, in _func_wrapper
    raise ValueError('No data available!')
ValueError: No data available!

You are using the custom component, that version is not changed yet.
Either remove the custom component so you can use the updated version in 0.64.2 or wait until I have updated the custom component.

Edit: the custom component is bumped to bimmer_connected v0.41.

OK fair enough, sorry!

My data doesn’t seem to work though.

sensor.440i_mileage	26891.0	unit_of_measurement: mls
friendly_name: 440i mileage
sensor.440i_remaining_fuel	32.0	unit_of_measurement: mpg
friendly_name: 440i remaining_fuel

This hasn’t changed since I first installed this component.

Similarly my GPS location in device_tracker is completely wrong. It’s actually my local BMW body shop!

It’s almost like the data retrieved is days or even weeks/months old.

No problem :grinning:

Can you open the BMW ConnectedDrive app and after that check if HA shows recent data?
Some older cars don’t seem to support auto refresh of the data. See this post BMW ConnectedDrive component.

2017 320d MSport in the UK and I get milage, remaining_fuel and remaining_range_fuel and GPS location on hass.io 0.95

Can you advise how to change the remaining fuel from mpg to litres? Also seem to be missing all the nice icons under hass.io - any advise

Am about to try the custom components if you need any testing done

Mmm not much different.

sensor.440i_mileage	26891.0	unit_of_measurement: mls
friendly_name: 440i mileage
sensor.440i_remaining_fuel	32.0	unit_of_measurement: mpg
friendly_name: 440i remaining_fuel

GPS has updated though!

@coolTNT
Thx for the analysis. The request and response look quite different from the one from Europe. What I’m missing is the access_token in the Location attribute. This token is then used in the authentication of the API calls. So it seems this is done differently in the Canadian site :frowning:

Location:https://www.bmw-connecteddrive.com/app/static/external-dispatch.html#state=SOME_STRING&access_token=SOME_SECRET_TOKEN&token_type=Bearer&expires_in=7199

I gave it a shot anyway and implemented it on the branch “canada”. But I would not expect it to work…
https://github.com/ChristianKuehnel/bimmer_connected/tree/canada

If you want, you can run status.py from the branch and see if it gives you the current vehicle status.