Audi MMI support

I tested setting the region in the underlying library, however, I can set it to any country and it still works for my car (europe). In China the myAudi service is probably located somewhere else. As the API is not documented and since I don’t have a chinese car, it’s hard to test it. Feel free to send me one though. :upside_down_face:

I fixed the issue with the position and added some sensors for tank level, hood and trunk state.

I’ll have to check if I can find the status of the sunroof and fix the issue with the date.

Support for locking and unlocking is gonna be difficult, as stated the API is not documented so someone will have to reverse engineer the challenge response from Audi.

Hi @arjenvr,

Thanks for your fast work! I installed the new version and see the new sensors. All of a sudden I also do not have an issue with the date anymore, not sure what resolved it. if it shows up again I will let you know.

There are a few other things however:

  • I’m still having the issue with the position. It still shows the position without decimal sign. In an effort to resolve this I removed it from known devices, but now I do not know how to get it back :face_with_raised_eyebrow:
  • My car is full electric and thus has no fuel level. Maybe there is another sensor for a drive battery?
  • I seem to have noticed that when Hassio is running for more than an hour the updates from my Audi stop coming in. I will test this further.

Hi Thomas

I had the same problem with the position, for some reason the value only updated in HA after I called the service refresh_vehicle_data to trigger the update from the vehicle.

I added more sensors for electric cars, including state of charge and remaining charge time.

I also added a sunroof sensor which returns some number reported by the API. As our cars do not have a sunroof, I cannot tell what this number means, for me it just reports 0. Maybe you can try and report back here, so that we can make the sensor return something more sensible.

Regards
Arjen

Since everyone that I see that has it working is not in the US, guessing the fact that two of us who have made git issue requests with it not working for us saying not supported in the error logs, guessing it doesnt work for us :frowning:

This is what I see when I do a manual service request with my vin.

Mon Jun 10 2019 11:22:32 GMT-0700 (Pacific Daylight Time)
Error refreshing vehicle data wauc4af49xxxxxxx
Traceback (most recent call last):
File “/config/custom_components/audiconnect/init.py”, line 158, in do_trigger_vehicle_refresh
vehicle = [v for v in connection.vehicles if v.vin == vin][0]
IndexError: list index out of range

The latest build does not seem to work for me. I get following error:

Error during setup of component audiconnect
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 153, in _async_setup_component
    hass, processed_config)
  File "/config/custom_components/audiconnect/__init__.py", line 190, in async_setup
    return await update(utcnow())
  File "/config/custom_components/audiconnect/__init__.py", line 144, in update
    discover_vehicle(vehicle)
  File "/config/custom_components/audiconnect/__init__.py", line 115, in discover_vehicle
    dashboard = Dashboard(vehicle)
  File "/config/custom_components/audiconnect/dashboard.py", line 290, in __init__
    for instrument in create_instruments()
  File "/config/custom_components/audiconnect/dashboard.py", line 291, in <listcomp>
    if instrument.setup(vehicle, **config)
  File "/config/custom_components/audiconnect/dashboard.py", line 40, in setup
    if not self.is_supported:
  File "/config/custom_components/audiconnect/dashboard.py", line 70, in is_supported
    if hasattr(self.vehicle, supported):
  File "/config/custom_components/audiconnect/audi_connect_account.py", line 454, in max_charge_current_supported
    if check and self.parseToFloat(check):
  File "/config/custom_components/audiconnect/audi_connect_account.py", line 177, in parseToFloat
    return float(val)
TypeError: float() argument must be a string or a number, not 'dict'

(Sorry for the very brief last post, I was in a hurry…)

I have tried to troubleshout the issue, but so far no luck. I’m guessing something broke with the last update as I changed nothing in there.

Rolling back to the previous version did fix it for now.

However, in that I do still have the problem that updates don’t always work.

The status is fetched correctly on startup, and it works for some time after that, but hten all of a sudden updates stop coming in. I feel it has to do either with a forced update from the app or with the car being unreachable at a certain point. I’ve not been able to pinpoint the cause.

Additionally, the service to refresh the data does not seem to work either. Basically, it does not seem to do anything and the “last updated” time is reset to sometime in 2000-something… Maybe it is because I have the Audi app active as well, I’m gonna try to setup a separate “Home Assistant” user for my car, but that’s gonna take a while…

Hope the remarks don’t put you off, I’m just trying to do my best to give as much feedback as possible; I’m already really, really happy with the component as it is but want to assist in making it even better the only way I know how: by testing.

Thomas

@arjenvr I did some more testing, below are the results:

  1. Connectivity issues: I set up a separate My Audi account for my Home Assistant. This has resolved the issues for me. Note: this only helps if you are using that user nowhere else. If you open the app or web portal with this user’s credentials, there still are issues. Secondly, I think this makes more sense as it separates users so you can revoke access for Home Assistant at any time when needed.
  2. I still get to see the 2000-1-1 date regularly. This seems to happen whenever a user-triggered (in the app / Home Assistant) update fails. For example, after hours of inactivity my e-tron stops responding.
  3. Manually triggering the update works. However, the indicated times are off. They are several minutes earlier than the actual update. The time difference does not seem to be consistent.
  4. The tracker works as expected, only showing the position when parked. Not sure what happens when the update fails (as in 2.)
  5. Your latest version still does not work for me. I keep getting the error posted before.

Let me know if you need any other info,

Thomas

Hi rangerzhou

In the underlying AudiAPI library the field X-Country-Id in the headers is fixed to DE. Could you try to set it to CN and try if it works? It at the top of the file audiapi/API.py (BASE_HEADERS).

Arjen

Hi thomas-be

Thanks for all the testing. Don’t worry it doesn’t put me off, I’m glad you help since my time for such projects is limited.

The connectivity issues where caused by the token expiring. To detect this I’d have to parse the exception from the underlying lib. As this is not very reliable I decided to simply login to the audi server every time HA triggers the update (shouldn’t be done every minute anyway). That should solve most issues you were having.

Note that manually triggering the update requests new data from the car, whereas the normal updating simply retrieves the data from the audi servers. The last update time reflects the last time the audi servers communicated with the car. The car seems to automatically upload new data upon certain events, such as parking, making the manual update unnecessary in most cases (at least for me).

Arjen

Hi @arjenvr,

I’ll keep up my testing then :slight_smile:.

Any idea why your latest version won’t work for me? I think you fixed a number of things, but I can’t test it 'cause it won’t load.

Thomas

I just updated today, does this version still not work?

@arjenvr It works!

The new sensors are reporting, some thoughts:

  • I can’t test the “plug connected” and “charge time sensors” right now as my car won’t be charging tonight.
  • The mapping of the sunroof sensor is as follows (for my tilt/slide roof):
    • 3 = closed
    • 2 = open (tilt or slide)
  • Two more cosmetic suggestions:
    • I would give the “last updated” parameter the mdi: update icon,
    • For the parking lights I would also use a lightbulb icon.
  • I also tested the update service and that does indeed trigger an update from the car.
  • Maybe consider combining some sensors: you could for example combine both “doors” sensors to show open / closed / locked in 1 sensor instead of two.

I’ll keep an eye on the component in the coming days and let you know if I see any issues.

Thomas

@arjenvr, here are some further results:

  • Plug connected sensor: works. Actually is useful to see if the car is connected and able to start a planned charge. Also here it may make sense to combine this sensor with the “charging” status sensor: disconnected / connected / charging. Similar to the “Battery State” sensor for iPhones in HA.
  • Charge time sensor also works, but two things:
    • Time is unformatted (in minutes)
    • When the car is not charging it shows the value “65535.0”. Better would be if it showed “n/a” or something similar.
  • “Last updated” still acts funny. Sometimes it shows the correct date, sometimes it shows 2000-01-01. Unless there is a reason to keep it like this, I would suggest not to update it if the value you get from Audi Connect is 2000-01-01.
  • For some reason the tracker no longer works since the update. The car is not shown on the map, and is permanently in “Away” status (even when I’m home). I know it does not update while driving, but it was parked all day and I did receive updates from the other sensors.
    EDIT: I got tracking to work again, had to remove the entry from the “known devices” file.

Thomas

I just updated and I’m getting this in my logs, seems to go a bit farther than before, I asked a question about this not working in the US also in github and havent heard back.

@arjenvr
I just found this integration by chance and instantly jumped into installing it and testing. What awesome work you did! Thanks so much!
As for the tests; everything works fine for my '17 Audi Q5. All the data I receive in hassio are reflecting info from myAudi application!
The only issue I observed is the same as reported by @thomas-be regarding last update. If not trigered manually it reports some funny date from the past. After manual trigering it shows date and time accuratelly. Funny, it also triggers update to myAudi app, so it shows last update date/time the same as triggered from hassio.
Perhaps this might be something to consider; give us an potion to stop automatic data triggering from integration entirely (e.g. to set scan_interval: null) and let users have script within hassio to trigger data refresh at given intervals. Or use it as default from your code instead of pulling data from Audi server?
I’d also second @thomas-be suggestion to combine doors and trunk sensors into one, to have open/closed/locked status… if possible for binary sensors :slight_smile: Otherwise it should be probably achievable in hassio using templating… for someone skilled enough :slight_smile:

Best regards,
Mirek

It would not be a binary sensor anymore, but there are plenty of examples of this (for example charging state). Templating is an option, but I find it adds complexity to a configuration.

Thomas

(PS. I also updated my previous post to show that I fixed the tracking issue)

Installed this and i get all sensors just fine :slight_smile: But the location is not synced. I was checking on the new myaudi webpage & app, and also there my location is missing. It was previously available in the MMI App and the MMI Webpage.

I just called Audi Customer Service to find out how to get it back, and they told me that they removed this service. It is now only available if you order a specific new service package (when configuring the car) that enables location data. The Customer agent also said that the previous location was not actually taken by the Cars internal GPS but through the Phones GPS.

That may be right, here it is called the “Technology pack” I think, I have it on my car. In that case it actually does use the location from the car GPS, but only when the car is parked in motion it does not send updates.

Thomas

I think what he told me is wrong anyway… i remember checking my location with the MMI app when it was picked up by the service. So my Phone was not even in the car. With the new app, i can also still see my parking location, but only on the map. But i still do not get a device_tracker nor can i see it online on the webpage.

Hi arjenvr
Sorry for replay later, The modification is useless, and the same error occurs, there may be more places to change, such as URLs and so on.

Error logging into Audi API
API error: invalid_grant
expectedTenant:zh-CN

Setup failed for audiconnect: Component failed to initialize.