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.

@gr4z

Maybe this is related to the vehicle. In my last vehicle, I had to push the “update position” icon in the BMW connected drive portal. Only then it would update the position after waiting for some time.

Only the later generations of the head units seem to upload the position automatically after parking the car.

Which model, year and head unit do you have?

I have a 2016 F36 (440i Gran Coupe). It only has ID4 so I wonder if that is the problem, perhaps you need ID5 or 6 for this to work properly? Damn BMW for superseding its software so quick!

Yes you need ID5.

Grrr, damn you BMW. No upgrade path either except to buy another car!

Yeah, I ran status.py from the canada branch, and it couldn’t get an access token.

However, I captured the packets that the BMW Remote app sends out when performing first time login, and it seems to get it’s access token from b2vapi.bmwgroup.us/webapi/oauth/token , then gets vehicle information from b2vapi.bmwgroup.us/webapi/v1/user/vehicles with the access token that it just received.

So essentially AUTH_URL for Canada might be b2vapi.bmwgroup.us/webapi/oauth/token

VEHICLE_SPECS_URL or LIST_VEHICLES_URL would be b2vapi.bmwgroup.us/webapi/v1/user/vehicles (I can’t tell, I only have one car)

I haven’t gotten around to trying any remote services yet, but will try to find out what the REMOTE_SERVICE_URL is soon. :slight_smile:

To try these URLs I would just have to put them into bimmer_connected/const.py right?

Update: I tried it, it doesn’t work. I think it’s because the Canadian site sends the access token back as a JSON in the response, which I think removes the need to use 'redirect_uri': 'https://www.bmw-connecteddrive.com/app/default/static/external-dispatch.html', and self._oauth_token = url_with_token['access_token'][0]

Below is the first packet sent/recieved by the BMW Remote app on first startup, after the login button is pressed.

So I will apologize in advance if I am doing something wrong but I am running hassio 0.64.3 and I cannot for the life of me get the BMW connected component to work. Basically if I have the configuration in this format:

bmw_connected_drive:
name:
username: xxxxx
password: xxxxx
country: USA

Then I can check the configuration and restart homeassistant just fine but I get an “invalid config” “The following components and platforms could not be set up:” “bmw-connected-drive” “please check your config”

Looking through this thread it seems like I should remove the “name:” line from my config file possibly? If I do that I cannot restart homeassistant and I cannot successfully check the configuration.

I’m not sure what else to do? Any assistance would be greatly appreciated!

This is not working for USA and Canada yet due to a different login method on the BMW ConnectedDrive site for these countries. Christian is working on a method for Canada which is currently tested by coolTNT. So hopefully this is something that can be added.

ignore this post :smiley:
Reading the post BMW ConnectedDrive component helped :wink:

I believe our method might work for USA too, once we figure it out…

The Canadian API URLs end with .us , so I think they might be for USA as well.

@coolTNT

I just implemented a very basic script with all the ingredients I’ve understood from your data so far. You can run it with basic_canada.py <username> <password>. This script does not depend on any other libraries, so you can tweak it and fiddle around until it works. No need to worry about the architecture and other countries.

There is also a basic_germany.py which is working for my account. So you can also have a look there to get some inspiration.

The script will basically retrieve the token and the get the list of vehicles in your account form the server.

If you can make that script work, I can then try to integrate it with the existing code.

https://github.com/ChristianKuehnel/bimmer_connected/blob/canada/basic_canada.py

its a bug in the documentation, see:

Hey @ChristianKuehnel , I’ve managed to get basic_canada.py to return the vehicle information from my account, and I’ve created a pull request on GitHub with my changes. (I’m lawtancool on GitHub :slight_smile: )

I’m not super familiar with how GitHub works, so apologies if I didn’t do it right…

1 Like

maybe someone can help me and tell me what the error messages mean.
i’m running hass 0.64.3 and tried the custom_component.

all i can see is DOOR and WINDOW state, which both show as closed.

here’s the excerpt of my log:

2018-03-06 12:43:58 ERROR (Recorder) [homeassistant.core] Error doing job: Future exception was never retrieved
Traceback (most recent call last):
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/homeassistant/.homeassistant/custom_components/bmw_connected_drive.py", line 98, in update
    listener()
  File "/home/homeassistant/.homeassistant/custom_components/binary_sensor/bmw_connected_drive.py", line 105, in update
    self._state = bool(vehicle_state.door_lock_state.value
  File "/srv/homeassistant/lib/python3.5/site-packages/bimmer_connected/state.py", line 196, in door_lock_state
    return LockState(self._attributes['door_lock_state'])
KeyError: 'door_lock_state'



2018-03-06 12:28:57 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/lib/python3.5/asyncio/tasks.py", line 241, in _step
    result = coro.throw(exc)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity_platform.py", line 266, in _async_add_entity
    yield from entity.async_added_to_hass()
  File "/home/homeassistant/.homeassistant/custom_components/lock/bmw_connected_drive.py", line 108, in async_added_to_hass
    yield from self.hass.async_add_job(self.update)
  File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, 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 "/home/homeassistant/.homeassistant/custom_components/lock/bmw_connected_drive.py", line 96, in update
    self._state = (STATE_LOCKED if vehicle_state.door_lock_state.value
  File "/srv/homeassistant/lib/python3.5/site-packages/bimmer_connected/state.py", line 196, in door_lock_state
    return LockState(self._attributes['door_lock_state'])
KeyError: 'door_lock_state'

and then i get a lot of these every 30s:

2018-03-06 12:28:56 ERROR (MainThread) [bimmer_connected.state] No data available!
2018-03-06 12:28:56 ERROR (MainThread) [bimmer_connected.state] No data available!
2018-03-06 12:28:56 ERROR (MainThread) [bimmer_connected.state] No data available!
2018-03-06 12:28:56 ERROR (MainThread) [bimmer_connected.state] No data available!
2018-03-06 12:28:56 ERROR (MainThread) [bimmer_connected.state] No data available!
2018-03-06 12:28:56 ERROR (MainThread) [bimmer_connected.state] No data available!
2018-03-06 12:28:56 ERROR (MainThread) [bimmer_connected.state] No data available!
2018-03-06 12:28:56 ERROR (MainThread) [bimmer_connected.state] No data available!
2018-03-06 12:28:56 ERROR (MainThread) [bimmer_connected.state] No data available!

edit: i just realised i got that info as well:

image

image

edit2: i tried “switching” the horn, and it showed up in my “bmw app’s log”. :slight_smile:

i checked the data receveived for accuracy, and unfortunately i have no idea where the data comes from (or from what time/date).
the actual mileage is 65tkm not 58tkm as shown.
the remaining gas is around 20%, so for sure not 65l which would be about FULL.
also doors/windows status i not updated. i left the door unlocked with open windows for 20min, but they stayed “locked” all the time.
what DOES work though is active control of horn/light and climate which imho is much more important for me, but still …

Hi @iz3man please check the post below to see if you have a compatible version of the iDrive software.
Based on your mileage I guess your version is a bit too old and thus will not show actual data :neutral_face:

Regarding the custom component, can you check if you are using the latest version which uses the v0.4.1 of the library and which should handle these errors correctly.

Thanks gerard33. I remember that issue. I once asked how to find out the idrive version, but can’t remember that i ever saw an answer.
The car is a 5er 2016 model. Latest software if that helps.

Tried this today having upgraded to 0.65 and it’s great :slight_smile: I’ve got location, mileage, fuel level and range (2016 340i in the UK).

Looking forward to having the lock status etc. but will wait for that stuff to be official so I don’t need to mess with custom stuff.

Anyone know how to change the fuel level units from mpg to L?