audiconnect / audi_connect_ha

Adds an audi connect integration to home assistant
MIT License
227 stars 98 forks source link

Q4 e-tron hardly working #207

Closed zuiker1974 closed 5 months ago

zuiker1974 commented 11 months ago

Only entities are model infomation and locking status

"Unable to obtain the vehicle longTerm tripdata of WAUZZZXYXYXYXY42: 403, message='', url=URL('https://mal-3a.prd.eu.dp.vwg-connect.com/api/bs/tripstatistics/v1/vehicles/WAUZZZXYXYXYXY42/tripdata/longTerm?type=list&from=1970-01-01T00:00:00Z&to=2023-10-14T19:27:41Z') Unable to obtain the vehicle shortTerm tripdata of WAUZZZXYXYXYXY42: 403, message='', url=URL('https://mal-3a.prd.eu.dp.vwg-connect.com/api/bs/tripstatistics/v1/vehicles/WAUZZZXYXYXYXY42/tripdata/shortTerm?type=list&from=1970-01-01T00:00:00Z&to=2023-10-14T19:37:45Z') Unable to obtain the vehicle longTerm tripdata of WAUZZZXYXYXYXY42: 403, message='', url=URL('https://mal-3a.prd.eu.dp.vwg-connect.com/api/bs/tripstatistics/v1/vehicles/WAUZZZXYXYXYXY42/tripdata/longTerm?type=list&from=1970-01-01T00:00:00Z&to=2023-10-14T19:37:45Z') Unable to obtain the vehicle shortTerm tripdata of WAUZZZXYXYXYXY42: 403, message='', url=URL('https://mal-3a.prd.eu.dp.vwg-connect.com/api/bs/tripstatistics/v1/vehicles/WAUZZZXYXYXYXY42/tripdata/shortTerm?type=list&from=1970-01-01T00:00:00Z&to=2023-10-14T19:47:49Z')"

tieskuh commented 10 months ago

I advise you to switch to this fork: https://github.com/cyr-ius/hass-audiconnect It is well maintained.

N3rdix commented 10 months ago

Doesn't seem to make a difference (see https://github.com/cyr-ius/hass-audiconnect/issues/26 and https://github.com/cyr-ius/hass-audiconnect/issues/24)

moritzwiechers commented 10 months ago

Hey, I created a fork with some adjustments to get some data for my q4 etron. I don't know python or home-assistant integrations. I don't know why the "old" endpoint won't work, but I found one that works in some way (different data structure) and put it in my fork. For me (located in germany) it is working and I added battery soc, milage and range. You can add it via a custom repository. Maybe some skilled python dev could use the informations to enhance it.

acdcnow commented 10 months ago

Hey, I created a fork with some adjustments to get some data for my q4 etron. I don't know python or home-assistant integrations. I don't know why the "old" endpoint won't work, but I found one that works in some way (different data structure) and put it in my fork. For me (located in germany) it is working and I added battery soc, milage and range. You can add it via a custom repository. Maybe some skilled python dev could use the informations to enhance it.

Hey great work, I could get as well the same data. That is a good starting point. We should be able to get the binary_sensors for doors, windows as well as the charging time and speed as well as gps locations. Hope that somebody can help here further

moritzwiechers commented 10 months ago

Hey, i added the window and door data + charging values and states + gps data. For me It works fine.

Feel free to use my fork

N3rdix commented 10 months ago

Great work @moritzwiechers so far, I will give it a try as well today. Hopefully Audi/VW won't change the API endpoints in the near future again, but at least we have a very good starting point now 👍

sixpack-de commented 10 months ago

Sounds like a stupid question, but how can I use the for w/o manually doing it? So that I would also get the updates?

N3rdix commented 10 months ago

Sounds like a stupid question, but how can I use the for w/o manually doing it? So that I would also get the updates?

You can add Moritz's Repo in HACS and then install that version of the integration. And remove the original integration first to avoid issues. In HACS click the 3 dots when you are in the ingrations screen image

sixpack-de commented 10 months ago

THANKS! and @moritzwiechers works like a charm THANKS!

zuiker1974 commented 10 months ago

This is huge improvement! Have you managed to get charging controlling work (start-stop-target%)?

jlatvala commented 10 months ago

Seems that @acdcnow 's fork is the newest. Do you @acdcnow or @moritzwiechers plan to make your fork as an "official" fork?

(I also noticed that my Q4 position doesn't always update (in @acdcnow 's fork) even for exampe mileage updates (and car is stopped and new location can be seen in Audi app) but don't want to start sending bug reports before we have kind of an "official" fork somewhere)

N3rdix commented 10 months ago

As @acdcnow 's repo is a fork of @moritzwiechers I would suggest adcdnow creates a PR to submit his changes to the upstream repo of Moritz. I appreciate the work both put into that, it's already a great improvement so far.

In my case the position updates well so far (as long as the audi services are reachable, which is sadly not always the case).

sixpack-de commented 10 months ago

I can only see "Away" as position, can I somewhere define these?

derhappy commented 10 months ago

If someone is to take over the further development I would appreciate it if you keep backwards compatibility in mind. For our E-Tron 2022 in Germany the original version by @arjenvrh is still working mostly fine (I only have minor issues which don't affect the overall function of the integration).

N3rdix commented 10 months ago

I can only see "Away" as position, can I somewhere define these?

I assume it's considering the position you maintained in the app/car as "home". In my case it shows home when I am at home. You can display the position on a map in HA as well with the GPS attributes: image

moritzwiechers commented 10 months ago

Hey, got the basic call for charging and climatisation working. I'm working on the state update after starting the actions. I would focus on lock/unlock and start/stop climatisation (some kind of preheater), start/stop charging. It is possible to set the targetSoC and also a few settings for climatisation (temperature, window heating,...) but as I mentioned, I'm not familiar with homeassistant and need to find examples to create a component with multiple inputs etc.

Will Update the repo when the basic controls are working.

Backwards compatibility is impossible for me. There is no official api description and in the last 2 years many endpoint changed and probably will in the future. Audi/VW doesn't want to make it easy for 3rd party usage of their endpoints. I'm currently recording the traffic of the myaudi app to get the right endpoints. I can just try it with my q4 etron (2023). Regarding the Integration and merging repos: The services i need to use for the q4 are totaly different compared to the original requests implemented in the Integration. I would have restructered the whole Integration if I know more about python + ha. Maybe acdcnow could integrate my changes in his/her fork. So for me It's 'just' about making the q4 (2023, maybe others) work in my fork, sorry I can't help any further.

sixpack-de commented 10 months ago

I can only see "Away" as position, can I somewhere define these?

I assume it's considering the position you maintained in the app/car as "home". In my case it shows home when I am at home. You can display the position on a map in HA as well with the GPS attributes: image

Nice...

It is not what I saved, it is away in front of my house, which is "home" in the Navigation system / App

jlatvala commented 10 months ago

It is not what I saved, it is away in front of my house, which is "home" in the Navigation system / App

I have used this integration (acdcnow's) now 6 days and the position entity has stopped getting updates few times. Other entities (e.g. mileage) keeps working. HA reboot helps and after that Q4 position works again (until it doesn't).

Not sure yet if there is an error logged when the position update stops working.

minosrex commented 9 months ago

So with our new Q4 just arrived, I tried these integrations. With the one from @acdcnow I got a bunch of sensors (door status, mileage, range, time to charge, charging status etc.) -great! However the values did not update -something I only noticed when I moved the car the day after. I tried reinstalling the integration, but now only get the famous two entities (model and charging rate). With other forks I get similar or less entities. The logs read the following:

1) Logger: custom_components.audiconnect.audi_connect_account Source: custom_components/audiconnect/audi_connect_account.py:429 Integration: Audi Connect (documentation, issues) First occurred: 13 December 2023 at 21:09:31 (1 occurrences) Last logged: 13 December 2023 at 21:09:31

Unable to obtain the vehicle status report of (VIN): 'measurements'

2) Error adding entities for domain sensor with platform audiconnect Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 509, in async_add_entities await asyncio.gather(*tasks) File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 754, in _async_add_entity await entity.add_to_platform_finish() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1025, in add_to_platform_finish self.async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 745, in async_write_ha_state self._async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 845, in _async_write_ha_state state, attr = self._async_generate_attributes() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 786, in _async_generate_attributes state = self._stringify_state(available) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 751, in _stringify_state if (state := self.state) is None: ^^^^^^^^^^ File "/config/custom_components/audiconnect/sensor.py", line 35, in state return self._instrument.state ^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/audiconnect/dashboard.py", line 155, in state val = super().state ^^^^^^^^^^^^^ File "/config/custom_components/audiconnect/dashboard.py", line 119, in state if hasattr(self._vehicle, self._attr): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/audiconnect/audi_connect_account.py", line 1203, in actual_charge_rate return parse_float(self._vehicle.state.get("actualChargeRate")) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/audiconnect/util.py", line 37, in parse_float return float(val) ^^^^^^^^^^ TypeError: float() argument must be a string or a real number, not 'NoneType'

3) Error while setting up audiconnect platform for sensor Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 369, in _async_setup_platform await asyncio.gather(pending) File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 509, in async_add_entities await asyncio.gather(tasks) File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 754, in _async_add_entity await entity.add_to_platform_finish() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1025, in add_to_platform_finish self.async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 745, in async_write_ha_state self._async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 845, in _async_write_ha_state state, attr = self._async_generate_attributes() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 786, in _async_generate_attributes state = self._stringify_state(available) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 751, in _stringify_state if (state := self.state) is None: ^^^^^^^^^^ File "/config/custom_components/audiconnect/sensor.py", line 35, in state return self._instrument.state ^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/audiconnect/dashboard.py", line 155, in state val = super().state ^^^^^^^^^^^^^ File "/config/custom_components/audiconnect/dashboard.py", line 119, in state if hasattr(self._vehicle, self._attr): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/audiconnect/audi_connect_account.py", line 1203, in actual_charge_rate return parse_float(self._vehicle.state.get("actualChargeRate")) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/audiconnect/util.py", line 37, in parse_float return float(val) ^^^^^^^^^^ TypeError: float() argument must be a string or a real number, not 'NoneType'

esesen1 commented 9 months ago

Hi,

The original integration has never worked for my Q4 and I only got two entities. I have tried both forks (@acdcnow 's and @moritzwiechers ) and, although I have improved a little (now there are 4 entities) I still cannot see most of them... Any suggestions?

image

minosrex commented 9 months ago

Meanwhile:

So there is no satisfying solution right now for me. The easiest -short of a working HA integration :-D- would be if I just knew the syntax of queries to the Audi API, then I could programme these in Python and run them periodically over cron. If anyone has other ideas...

acdcnow commented 8 months ago

since 18.12.2023 VW and related brands have changed the API structure hence the Audi Q4 integration that not work just on the header data but not on sensors . This needs to be adjusted. EVCC-IO has done that already on there app and as soon as I have more time I well perform that as well but this will take some more weeks as I'm overloaded with business tasks.

N3rdix commented 8 months ago

since 18.12.2023 VW and related brands have changed the API structure hence the Audi Q4 integration that not work just on the header data but not on sensors . This needs to be adjusted. EVCC-IO has done that already on there app and as soon as I have more time I well perform that as well but this will take some more weeks as I'm overloaded with business tasks.

Do you have a link where this EVCC is already adjusted? I could spend some spare time and check if I can support with the adjustment

acdcnow commented 8 months ago

endpoint and structure adjusted in version 0.123.1

https://github.com/evcc-io/evcc

check the vehicle part and there the the audi/etron selection.

https://github.com/evcc-io/evcc/tree/master/vehicle/audi/etron

https://github.com/evcc-io/evcc/pull/2968 Refactor VAG integration

N3rdix commented 8 months ago

I got the integration (at least mostly) back to work, feel free to take over the changed files temporarily from PR https://github.com/moritzwiechers/audi_connect_ha_q4/pull/1 unless it is not merged by @moritzwiechers

Thanks @acdcnow for the hint, I found the changed API endpoint after digging into EVCC's solution.

@ all: note that I removed the attribute remainingChargingTime for now as I had not enough time to handle missing attributes in the received payload yet. This can come later. All other attributes work as expected:

image
moritzwiechers commented 8 months ago

@N3rdix thanks for figuring out the changed endpoint usage. I will try to figure out how to start climatisation and charging in the next days. Merged your requests and updated the integration in ha - works for me.

minosrex commented 8 months ago

Thank you very much for your efforts, everything works great now! I currently use the battery status, the range, the charging time and the car's parking position. The charging time is important because I have to charge in on-street stations, so looking forward to having that sensor available again.

BTW, since the colour scheme of the Map Card was awful within my theme (and most themes, for that matter), I took the opportunity of learning how to access the Google Maps API, define a custom map in the greenish colour scheme of the theme, and create a camera from the static image (see https://www.home-assistant.io/examples/google_maps_card/).

My home dashboard just became even more useful. HNY everyone and thanks again! IMG_9545

minosrex commented 8 months ago

Update: the map might look nice but it stopped updating. The position sensor keeps the same coordinates as attributes for days now, while in the Audi app the car's position is updated correctly. Anyone else has this problem?

jlatvala commented 8 months ago

Anyone else has this problem?

Yes, reboot HA and position updates again (until it again doesn't).

minosrex commented 7 months ago

@N3rdix thanks for figuring out the changed endpoint usage. I will try to figure out how to start climatisation and charging in the next days. Merged your requests and updated the integration in ha - works for me.

Any updates on this?

andy-ich commented 7 months ago

Hi, is there a known issue with Home Assistant Core 2024.1.5? I was able to use this fork without any problems, but since the update from 2023.12.4 to 2024.1.5 today, most of the entities no longer work. Reinstall and reboot without success.

thx for help image

N3rdix commented 7 months ago

Hi, is there a known issue with Home Assistant Core 2024.1.5? I was able to use this fork without any problems, but since the update from 2023.12.4 to 2024.1.5 today, most of the entities no longer work. Reinstall and reboot without success.

Might not be an update issue but an API issue again. I see errors like this since tonight. Do you see this as well?

Traceback (most recent call last):
  File "/config/custom_components/audiconnect/audi_connect_account.py", line 436, in update_vehicle_statusreport
    status = await self._audi_service.get_stored_vehicle_data(self._vehicle.vin)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/audiconnect/audi_services.py", line 183, in get_stored_vehicle_data
    data = await self._api.get(
           ^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/audiconnect/audi_api.py", line 82, in get
    full_headers = self.__get_headers()
                   ^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/audiconnect/audi_api.py", line 136, in __get_headers
    data["Authorization"] = "Bearer " + self.__token.get("access_token")
                            ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
TypeError: can only concatenate str (not "NoneType") to str
andy-ich commented 7 months ago

Where exactly do I get the log like you? So that there are no misunderstandings, I use "https://github.com/acdcnow/HA_audi_connect_q4" since I read that this is currently the most reliable fork for the Q4? Is that so?

I have the following from the Home Assistant Core Log:

Dieser Fehler wurde von einer benutzerdefinierten Integration verursacht

Logger: custom_components.audiconnect.audi_connect_account
Source: custom_components/audiconnect/audi_connect_account.py:437
Integration: Audi Connect Q4 (documentation, issues)
First occurred: 20:24:47 (3 occurrences)
Last logged: 20:29:46

Unable to obtain the vehicle status report of ***************: 'remainingChargingTimeToComplete_min'
Traceback (most recent call last):
  File "/config/custom_components/audiconnect/audi_connect_account.py", line 437, in update_vehicle_statusreport
    status = await self._audi_service.get_stored_vehicle_data(self._vehicle.vin)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/audiconnect/audi_services.py", line 188, in get_stored_vehicle_data
    return VehicleDataResponse(data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/audiconnect/audi_models.py", line 69, in __init__
    self.states.append({"name" : "remainingChargingTime", "value" : data["charging"]["chargingStatus"]["value"]["remainingChargingTimeToComplete_min"]})
                                                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'remainingChargingTimeToComplete_min'
N3rdix commented 7 months ago

Your issue has already been fixed by me in the "Q4 optimized" repo https://github.com/moritzwiechers/audi_connect_ha_q4. At least it looks like the same root cause, maybe you want to give this repo a try

andy-ich commented 7 months ago

Hey Nerdix, thx its working! I miss the "Remaining chagre time" entity. Ist this a problem in my HA or ist this not supportet in your Integration? It's a very helpful sensor and I would like to get it working.

cdnninja commented 7 months ago

Would you be open to creating a pull request to this repo? I have access to merge fixes now.

N3rdix commented 7 months ago

Hey Nerdix, thx its working! I miss the "Remaining chagre time" entity. Ist this a problem in my HA or ist this not supportet in your Integration? It's a very helpful sensor and I would like to get it working.

it’s an issue with the changed API and therefore has been (temporarily) removed, see https://github.com/moritzwiechers/audi_connect_ha_q4/pull/1

I hope to get some time soon to investigate how to restore this sensor.

pergolafabio commented 6 months ago

Hi , also ordered Q4, delivered in summer... Was already spreading... But why are there so many repos? I also see this one. For example..

https://github.com/cyr-ius/hass-audiconnect

Why isn't it possible to merge to 1 active component?

pergolafabio commented 6 months ago

For Q4 it seems there are 2 repos, both active? Is there an particular reason for it? Witch to choose?

pergolafabio commented 6 months ago

I see the official fork got lots of updates, also using new API? Does it work for Q4 now?

jeffkibuule commented 5 months ago

Q4 is working fine for my wife's car, though I'm wondering if I'm supposed to be seeing battery percentage in addition to range. This is running v1.2.0.

Screenshot 2024-04-06 at 1 20 20 PM
lozzd commented 5 months ago

It seems https://github.com/moritzwiechers/audi_connect_ha_q4 managed to get State of Charge which I'd love - good to see new releases of this being made, if SOC could be added that'd be ideal. "Remaining charge time" got added for me today, but it just shows Unknown (even when the car is charging)

epweston commented 5 months ago

Same here ("Q4 e-tron® Charging Complete Time" Unknown), reloaded integration but no help. Would love SOC also. Keep up the great work and thank you.

N3rdix commented 5 months ago

Same here ("Q4 e-tron® Charging Complete Time" Unknown), reloaded integration but no help. Would love SOC also. Keep up the great work and thank you.

I am using Moritz's Repo and the remaining charging time works when charging is active. Did you reload the integration while charging?

epweston commented 5 months ago

Same here ("Q4 e-tron® Charging Complete Time" Unknown), reloaded integration but no help. Would love SOC also. Keep up the great work and thank you.

I am using Moritz's Repo and the remaining charging time works when charging is active. Did you reload the integration while charging?

I think so, what steps should I have taken, or should I take.

epweston commented 5 months ago

Reloaded again while not charging did not help. I enabled debug logging, got this JSON from the log. (had to add quotes to dates and some other things) Perhaps it will help.

Sensor_sample Json_Sample

coreywillwhat commented 5 months ago

Reloaded again while not charging did not help. I enabled debug logging, got this JSON from the log. (had to add quotes to dates and some other things) Perhaps it will help.

can you upload your debug log

coreywillwhat commented 5 months ago

Reloaded again while not charging did not help. I enabled debug logging, got this JSON from the log. (had to add quotes to dates and some other things) Perhaps it will help.

are you reloading the integration, or running the update_cloud_data service? or both? Do you have active polling turned on, and cloud update on start in configuration options?

epweston commented 5 months ago

Reloaded again while not charging did not help. I enabled debug logging, got this JSON from the log. (had to add quotes to dates and some other things) Perhaps it will help.

can you upload your debug log

Sorry, I am new to this and GitHub discussions, so I tried to sanitize the file due to a lot of data, some personal. Hope this helps, if not, let me know what to look for. This is running on a VM in Windows 10 and is my HA playground/test system.

I reloaded under Settings -> Devices & Services -> Audi Connect -> hamburger icon next to "Configure" -> Reload Also did a reboot, no change.

SANITIZED-home-assistant_audiconnect_2024-04-08T17-56-27.082Z.log

coreywillwhat commented 5 months ago

@epweston Just to confirm for review, you're on 1.3.0 of this repo?

Your logs show its pulling the remaining charging time: 245 min. So there must be an issue between it finding the value and displaying it in the sensor. name:remainingChargingTime tsoff:-1 loc:['charging', 'chargingStatus', 'value', 'carCapturedTimestamp']: val:245 ts:2024-04-08 17:02:15+00:00

Charging Complete Time relies on the Last Update sensor and remainingChargingTime time to work so we need to find whats going on with those data points.