BMW ConnectedDrive component

I’ve tried functions a few times. Not sure if there’s a limit?

having left if all day without trying to interact, I see errors in just trying to get the latest data:

2018-12-20 07:53:12 DEBUG (SyncWorker_2) [homeassistant.components.bmw_connected_drive] Updating vehicle state for account 220d, notifying 12 listeners
2018-12-20 07:58:12 DEBUG (SyncWorker_5) [homeassistant.components.bmw_connected_drive] Updating vehicle state for account 220d, notifying 12 listeners
2018-12-20 07:58:12 ERROR (SyncWorker_5) [bimmer_connected.account] Unknown status code 401, expected 200
2018-12-20 07:58:12 ERROR (SyncWorker_5) [bimmer_connected.account] {"error":"invalid_token","error_description":"The access token provided is expired, revoked, malformed, or invalid for other reasons."}
2018-12-20 07:58:12 ERROR (SyncWorker_5) [homeassistant.components.bmw_connected_drive] Error updating the vehicle state.
2018-12-20 07:58:12 ERROR (SyncWorker_5) [homeassistant.components.bmw_connected_drive] Unknown status code 401, expected 200
Traceback (most recent call last):
  File "/usr/src/app/homeassistant/components/bmw_connected_drive/__init__.py", line 151, in update
    self.account.update_vehicle_states()
  File "/usr/local/lib/python3.6/site-packages/bimmer_connected/account.py", line 213, in update_vehicle_states
    car.update_state()
  File "/usr/local/lib/python3.6/site-packages/bimmer_connected/vehicle.py", line 72, in update_state
    self.state.update_data()
  File "/usr/local/lib/python3.6/site-packages/bimmer_connected/state.py", line 99, in update_data
    params=params)
  File "/usr/local/lib/python3.6/site-packages/bimmer_connected/account.py", line 134, in send_request
    raise IOError(msg)
OSError: Unknown status code 401, expected 200
2018-12-20 08:03:12 DEBUG (SyncWorker_0) [homeassistant.components.bmw_connected_drive] Updating vehicle state for account 220d, notifying 12 listeners

Any idea how I can debug this further?
Flashing and lock/unlock still isn’t working :frowning:

For me it does change the temperature reading from C to F so this doesn’t help unfortunately. Anyway we can get the Units working correctly for people in regions where we using C for temp but want miles for distance ? Just using the global HA config of imperial doesn’t help

1 Like

I see some errors in the log every now and then as well, that’s nothing strange as it seems the API is not always available.

You can debug by running the Python script which you can find here.
Just share the results as a Github issue on that site. The data get’s anonymized automatically, so no worries :slight_smile:
It helps us to find the issue and we can make some additional test cases with the data from your car.

The unit system from HA is used is agreed in this PR. So currently no other options available.

You mean errors in the log? Or do you also see that sensors get updated with incorrect data?
I do see some more errors in the log then when we started with the component, but don’t see strange data for the sensors. At most that the data doesn’t get updated every 5 minutes due to the API not being available.

was this component never translated to german?
it shows only the original value
image

You mean the names of the entity? These get a default name per entity in English, but you can rename these to anything you want yourselves. Just click on the entity and then on the cog.

thanks
I thought I have seen them already in german.

Yes. By someone who renamed them locally :slight_smile:

I am trying to get the bmw connectedDrive component working but am running into some errors.
I have the logs below (I hope they formatted correctly)
I have 2 BMWs, both work just fine on the connected App for iPhone

Jan 30 18:15:48 peon hass[32033]: 2019-01-30 18:15:48 ERROR (SyncWorker_5) [bimmer_connected.account] Unknown status code 404, expected 200
Jan 30 18:15:48 peon hass[32033]: 2019-01-30 18:15:48 ERROR (SyncWorker_5) [bimmer_connected.account] {
Jan 30 18:15:48 peon hass[32033]:   "error" : {
Jan 30 18:15:48 peon hass[32033]:     "code" : 500,
Jan 30 18:15:48 peon hass[32033]:     "description" : "(SmartPhoneUtil-A-2012) Ressource not found. No status available for VIN <removed VIN for which is the correct vin>"
Jan 30 18:15:48 peon hass[32033]:   }
Jan 30 18:15:48 peon hass[32033]: }
Jan 30 18:15:48 peon hass[32033]: 2019-01-30 18:15:48 ERROR (SyncWorker_5) [homeassistant.components.bmw_connected_drive] Error updating the vehicle state.
Jan 30 18:15:48 peon hass[32033]: 2019-01-30 18:15:48 ERROR (SyncWorker_5) [homeassistant.components.bmw_connected_drive] Unknown status code 404, expected 200
Jan 30 18:15:48 peon hass[32033]: Traceback (most recent call last):
Jan 30 18:15:48 peon hass[32033]:   File "/opt/homeassistant/lib64/python3.7/site-packages/homeassistant/components/bmw_connected_drive/__init__.py", line 151, in update
Jan 30 18:15:48 peon hass[32033]:     self.account.update_vehicle_states()
Jan 30 18:15:48 peon hass[32033]:   File "/opt/homeassistant/lib64/python3.7/site-packages/bimmer_connected/account.py", line 213, in update_vehicle_states
Jan 30 18:15:48 peon hass[32033]:     car.update_state()
Jan 30 18:15:48 peon hass[32033]:   File "/opt/homeassistant/lib64/python3.7/site-packages/bimmer_connected/vehicle.py", line 72, in update_state
Jan 30 18:15:48 peon hass[32033]:     self.state.update_data()
Jan 30 18:15:48 peon hass[32033]:   File "/opt/homeassistant/lib64/python3.7/site-packages/bimmer_connected/state.py", line 99, in update_data
Jan 30 18:15:48 peon hass[32033]:     params=params)
Jan 30 18:15:48 peon hass[32033]:   File "/opt/homeassistant/lib64/python3.7/site-packages/bimmer_connected/account.py", line 134, in send_request
Jan 30 18:15:48 peon hass[32033]:     raise IOError(msg)
Jan 30 18:15:48 peon hass[32033]: OSError: Unknown status code 404, expected 200

When I try to run the fingerprint command I get this

DEBUG:bimmer_connected.account:Getting vehicle list
DEBUG:bimmer_connected.account:getting new oauth token
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): b2vapi.bmwgroup.us:443
DEBUG:urllib3.connectionpool:https://b2vapi.bmwgroup.us:443 "POST /gcdm/oauth/token HTTP/1.1" 200 None
DEBUG:bimmer_connected.account:got new token ik2lk5buir0pJmzeMsdELg21L0vBH4Mc with expiration date 2019-01-30 18:07:19.684515
DEBUG:bimmer_connected.account:Old token is still valid. Not getting a new one.
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): b2vapi.bmwgroup.us:443
DEBUG:urllib3.connectionpool:https://b2vapi.bmwgroup.us:443 "GET /webapi/v1/user/vehicles HTTP/1.1" 200 None
DEBUG:bimmer_connected.state:requesting new data from connected drive
DEBUG:bimmer_connected.account:Old token is still valid. Not getting a new one.
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): b2vapi.bmwgroup.us:443
DEBUG:urllib3.connectionpool:https://b2vapi.bmwgroup.us:443 "GET /webapi/v1/user/vehicles/<myvinhere>/status?deviceTime=2019-01-30T17%3A07%3A20&dlat=0.0&dlon=0.0 HTTP/1.1" 404 None
ERROR:bimmer_connected.account:Unknown status code 404, expected 200
ERROR:bimmer_connected.account:{
  "error" : {
    "code" : 500,
    "description" : "(SmartPhoneUtil-A-2012) Ressource not found. No status available for VIN <myvinhere>"
  }
}
Traceback (most recent call last):
  File "/usr/local/bin/bimmerconnected", line 126, in <module>
    main()
  File "/usr/local/bin/bimmerconnected", line 45, in main
    args.func(args)
  File "/usr/local/bin/bimmerconnected", line 81, in fingerprint
    account.update_vehicle_states()
  File "/usr/local/lib/python3.7/site-packages/bimmer_connected/account.py", line 213, in update_vehicle_states
    car.update_state()
  File "/usr/local/lib/python3.7/site-packages/bimmer_connected/vehicle.py", line 72, in update_state
    self.state.update_data()
  File "/usr/local/lib/python3.7/site-packages/bimmer_connected/state.py", line 99, in update_data
    params=params)
  File "/usr/local/lib/python3.7/site-packages/bimmer_connected/account.py", line 134, in send_request
    raise IOError(msg)
OSError: Unknown status code 404, expected 200

Can you try it again? Sometimes the API is not available and then you can get this kind of errors.

Thanks for your reply! Unfortunately the same results… I tried a few weeks back and the same issue. I decided to revisit this component yesterday and ran into it again and figured I’d post.
the image function will work though, it will download an image of my X5 :slight_smile: (utilizing the bimmer_connected python script)

Hi, Any chance of adding a configuration option to specify that the car is using id4 rather than id5/6? My car is ID4 which means that the component can’t pull the majority of the metadata such as fuel level, lock status etc. Location works however this doesn’t automatically update - it only updates when requesting the location from within the app/web portal. All the services such as lock, unlock and flash work however they return errors as the status of the lock isn’t returned.
An option such as “version: id4” defaulting to “version: id5” could be used which would prevent the creation of all the sensors apart from location and remove the expectancy of status information to be supplied for the locks. This should resolve all of the errors I’m seeing & blank sensors. It would also be nice if this could result in an additional service that could be called to request the cars location data (though I’m not sure if this would be available via the API)?

I have an issue with the new HA version and the rules about entities config. I wrote it up to report it to HA but I figured maybe here was better.

With the changes to entity name restrictions we need to add some rules to replace invalid characters in Vehicle model names so they can create entities in HA that have valid names. Bimmer_connected returns “i3 (+ REX)” as the model for my car. This value goes on to be the name of the vehicle which in turn is used to create the entities for all of the sensors etc. The bmw component creates the entities as i3__REX which used to be ok but now the double underscore is no longer allowed, so I get warning messages in the front end that the entities were created as i3_REX. The issue is that once the invalid characters are removed we now have a double space which creates a double underscore that is also invalid in entity names. I tested a quick workaround in components/bmw_connected_drive/init.py line 139 I changed to
self.name = name.replace('__','_')
which worked for me. Unfortunately my python skills are limited and I can’t understand where “name” is coming from here. I thought it pulled from config file but that isn’t the case with mine. I am trying to figure out where the (+) are removed to add the update there.

can you post an english version?

Yeah, this is something that we would want to automatically detect. It’s something that is also discussed here bmw_connected_drive for cars with limited Connected Drive capabilities by ToSa27 · Pull Request #19813 · home-assistant/core · GitHub.
Let’s hope @m1n3rva can jump in and make some updates to the connected_drive library.

I will have a look at this.

I’ve been doing maintenance on my hassio on a NUC install, tracking down errors and hoping to fix them. I have one related to the BMW ConnectedDrive component for an i3. Here’s the log:

Log Details (ERROR)
Wed Feb 06 2019 15:43:19 GMT-0800 (Pacific Standard Time)

bmw_connected_drive: Error on device update!
Traceback (most recent call last):
File “/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py”, line 248, in _async_add_entity
await entity.async_device_update(warning=False)
File “/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py”, line 349, in async_device_update
await self.hass.async_add_executor_job(self.update)
File “/usr/local/lib/python3.6/concurrent/futures/thread.py”, line 56, in run
result = self.fn(*self.args, **self.kwargs)
File “/usr/local/lib/python3.6/site-packages/homeassistant/components/sensor/bmw_connected_drive.py”, line 152, in update
self._state = getattr(vehicle_state, self._attribute)
File “/usr/local/lib/python3.6/site-packages/bimmer_connected/state.py”, line 264, in getattr
return self._attributes[item]
KeyError: ‘maxFuel’

I’m not sure what this is or how to fix it. Ideas?

Is your car fully electric or does it have a range extender?

Can you try to run this script?