Hyundai-Kia-Connect / kia_uvo

A Home Assistant HACS integration that supports Kia Connect(Uvo) and Hyundai Bluelink. The integration supports the EU, Canada and the USA.
MIT License
398 stars 84 forks source link

EV9 is not showing as an EV and is not recognized #766

Closed Bubo08 closed 6 months ago

Bubo08 commented 7 months ago

Region and Brand of car Europe Kia EV9

Version of the integration HACS Integration v2.16.3

Describe the bug The HACS integration is not showing all the data of the EV. Instead it shows the car battery level. In the logfile it shows, that it does not recognize the EV9 and defaults to a gazoline car.

Debug logs if an error occurred 2023-12-09 17:00:55.132 DEBUG (SyncWorker_12) [hyundai_kia_connect_api.VehicleManager] hyundai_kia_connect_api - Time differential in seconds: 1861.13263 2023-12-09 17:00:55.334 DEBUG (SyncWorker_12) [hyundai_kia_connect_api.KiaUvoApiEU] hyundai_kia_connect_api - get_cached_vehicle_status response: {'retCode': 'S', 'resCode': '0000', 'resMsg': {'vehicleStatusInfo': {'vehicleStatus': {'windowRearCurtain': {}, 'transCond': True, 'airCtrlOn': False, 'engine': False, 'doorLock': True, 'doorOpen': {'frontLeft': 0, 'frontRight': 0, 'backLeft': 0, 'backRight': 0}, 'trunkOpen': False, 'defrost': False, 'lowFuelLight': False, 'acc': False, 'ign3': False, 'hoodOpen': False, 'steerWheelHeatStep2': 0, 'steerWheelHeat': 0, 'sideBackWindowHeat': 0, 'dte': {'value': 381, 'unit': 1}, 'tirePressureLamp': {'tirePressureLampAll': 0, 'tirePressureLampFL': 0, 'tirePressureLampFR': 0, 'tirePressureLampRL': 0, 'tirePressureLampRR': 0}, 'seatHeaterVentState': {'frSeatHeatState': 2, 'flSeatHeatState': 2, 'rlSeatHeatState': 2, 'rrSeatHeatState': 2}, 'battery': {'batSoc': 90, 'bacState': 0, 'sjbDeliveryMode': 2}, 'sunroofOpen': False, 'lampWireStatus': {'stopLamp': {'leftLamp': False, 'rightLamp': False}, 'headLamp': {'headLampStatus': False, 'leftLowLamp': False, 'rigthLowLamp': False, 'leftHighLamp': False, 'rightHighLamp': False}, 'turnSignalLamp': {'leftFrontLamp': False, 'rightFrontLamp': False, 'leftRearLamp': False, 'rightRearLamp': False}}, 'windowOpen': {'frontLeft': 0, 'frontRight': 0, 'backLeft': 0, 'backRight': 0}, 'windowOpen2': {'frontLeft': 0, 'frontRight': 0, 'backLeft': 0, 'backRight': 0}, 'tailLampStatus': 0, 'hazardStatus': 0, 'smartKeyBatteryWarning': False, 'fuelLevel': 0, 'washerFluidStatus': False, 'breakOilStatus': False, 'sleepModeCheck': False, 'time': '20231209165920', 'airCleaning': {'airPurifierStatus': 1, 'fineDustStep': 0, 'fineDustColor': 0}}}}, 'msgId': 'f48085eb-84dc-4df4-ba88-8c3e0b1e69e0'} 2023-12-09 17:00:55.335 DEBUG (SyncWorker_12) [hyundai_kia_connect_api.KiaUvoApiEU] hyundai_kia_connect_api - last_updated_at - before 20231209165920 2023-12-09 17:00:55.335 DEBUG (SyncWorker_12) [hyundai_kia_connect_api.KiaUvoApiEU] hyundai_kia_connect_api - last_updated_at - after 2023-12-09 16:59:20+01:00 2023-12-09 17:00:55.335 DEBUG (SyncWorker_12) [hyundai_kia_connect_api.KiaUvoApiEU] hyundai_kia_connect_api - SOC Levels couldn't be found. May not be an EV. 2023-12-09 17:00:55.524 DEBUG (SyncWorker_12) [hyundai_kia_connect_api.KiaUvoApiEU] hyundai_kia_connect_api - get_driving_info responseAlltime {'retCode': 'S', 'resCode': '0000', 'resMsg': {'drivingInfo': [{'drivingPeriod': 0}, {'drivingPeriod': 1}], 'drivingInfoDetail': []}, 'msgId': '54fe8e6a-8f79-45f9-93e7-242786e6cbe9'} 2023-12-09 17:00:55.744 DEBUG (SyncWorker_12) [hyundai_kia_connect_api.KiaUvoApiEU] hyundai_kia_connect_api - get_driving_info response30d {'retCode': 'S', 'resCode': '0000', 'resMsg': {'drivingInfo': [{'drivingPeriod': 0}, {'drivingPeriod': 1}, {'drivingPeriod': 2}], 'drivingInfoDetail': []}, 'msgId': 'ce5595f2-cdfa-451e-a2a1-d584d68b7c88'} 2023-12-09 17:00:55.744 ERROR (SyncWorker_12) [hyundai_kia_connect_api.KiaUvoApiEU] Failed to parse driving info. Possible reasons:

Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/hyundai_kia_connect_api/KiaUvoApiEU.py", line 333, in update_vehicle_with_cached_state state = self._get_driving_info(token, vehicle) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/hyundai_kia_connect_api/KiaUvoApiEU.py", line 1072, in _get_driving_info and drivingInfoItem["calculativeOdo"] > 0


KeyError: 'calculativeOdo'
2023-12-09 17:00:55.951 DEBUG (MainThread) [custom_components.kia_uvo.coordinator] Finished fetching kia_uvo data in 0.820 seconds (success: True)

**To Reproduce**
It happens everytime reading data from KIA connect.

**Expected behavior**
It should fetch the Odometer and the EV battery. It should akt like the EV6, which is very similar to the EV9.

**Screenshots**
![grafik](https://github.com/Hyundai-Kia-Connect/kia_uvo/assets/12473381/b7d00f54-7f8d-48f6-8007-79af27bc8eae)

![grafik](https://github.com/Hyundai-Kia-Connect/kia_uvo/assets/12473381/8361e7a2-be71-4236-a11c-e041323a97f0)

**Additional context**
cdnninja commented 7 months ago

Same issue as what someone else reported for their ev6. Seems the API has changed. New endpoints must exist for the newer cars. Someone needs to sniff the traffic for it be implemented.

Bubo08 commented 7 months ago

I will try to snif it if I can. At the time I am searching for the best way to do this. I was thinking about to add some additional DEBUG statements to the code, building my own branche and somehow test it. But I am still struggling how this works in home assistant. The other way - which migth be easier - is to create a python script.

cdnninja commented 7 months ago

Python test scripts are very easy. An example exists in that repo to run the code.

Sniffing with nox and Charles works well.

Bubo08 commented 7 months ago

I can now debug the api with PyCharm. It looks like the same issue as https://github.com/Hyundai-Kia-Connect/hyundai_kia_connect_api/issues/440 and https://github.com/Hyundai-Kia-Connect/kia_uvo/issues/760

In #440 you are proposing to switch a line of code

Switching this line: https://github.com/Hyundai-Kia-Connect/hyundai_kia_connect_api/blob/444b07ca6f1820ca30989fdef2e53836e5226976/hyundai_kia_connect_api/KiaUvoApiEU.py#L1025C20-L1025C31

But I do not understand with what kind of code I have to replace this line.

Or should I try to snif the call and what I get back? How can I do this best with nox or Charles?

Bubo08 commented 7 months ago

I switched the line url = self.SPA_API_URL + "vehicles/" + vehicle.id + "/status/latest" to url = self.SPA_API_URL_V2 + "vehicles/" + vehicle.id + "/status/latest" in _get_cached_vehicle_state

The result was {'error': 'Access to this API has been disallowed'}

I also tried to overwrite the URL with self.SPA_API_URL: str = "https://" + self.BASE_URL + "/api/v2/spa/" But this didn't work, either.

So no low hanging fruits.

cdnninja commented 7 months ago

Yeah worth sniffing the traffic. I do think this is related to v2 apis but I think headers or something else need to change for that to work. bluelinky uses some v2 apis where as it hasn't worked for us. I don't own a Hyundai or Kia and don't live in EU so hard for me to help and less motivation than when I owned a Kia.

Bubo08 commented 7 months ago

Yeah worth sniffing the traffic. I do think this is related to v2 apis but I think headers or something else need to change for that to work. bluelinky uses some v2 apis where as it hasn't worked for us. I don't own a Hyundai or Kia and don't live in EU so hard for me to help and less motivation than when I owned a Kia.

Thanks for your help anyway. My motiviation is much higher as I own now my first KIA.

How can I best snif the API trafic of the KIA connect app? Is the best way to create a virtual instance of Android, install the app on it and then snif the trafic or is there a better way?

fuatakgun commented 7 months ago

Can you try bluelinky and see if it works right? Depending on the case, we can migrate into v2 version.

There was a difference between v1 and v2 about app ids, so a simple change wouldn't work

Bubo08 commented 7 months ago

I'm using Kia Uvo / Hyundai Bluelink HACS integration which has the problem above. Should I test https://github.com/Hacksore/bluelinky?

Bubo08 commented 7 months ago

I tried the bluelinky node red implementation https://flows.nodered.org/node/node-red-contrib-bluelinky but it seems not to work. image

I see a short login note visible but then it goes to error. Not sure if the login is not correct, something else is wrong or if it is really broken. My login looks like this:

image

ZuinigeRijder commented 6 months ago

Yeah worth sniffing the traffic. I do think this is related to v2 apis but I think headers or something else need to change for that to work. bluelinky uses some v2 apis where as it hasn't worked for us. I don't own a Hyundai or Kia and don't live in EU so hard for me to help and less motivation than when I owned a Kia.

Thanks for your help anyway. My motiviation is much higher as I own now my first KIA.

How can I best snif the API trafic of the KIA connect app? Is the best way to create a virtual instance of Android, install the app on it and then snif the trafic or is there a better way?

@Bubo08 Same approach as with Bluelink can be used with Kia Connect.

How to sniff

For the ones who also want to be able to sniff the calls from the App, this is how I did it (do it at your own risk):

ZuinigeRijder commented 6 months ago

I have a German user with a Kona model 2024, which has the same problem as the Kia EV9 here, using my tool hyundai_kia_connect_monitor:

PS C:\Users\Erhard\Documents\hyundai_kia_connect_monitor-R3.15.0> python monitor.py
Failed to parse driving info. Possible reasons:
- incompatible vehicle (ICE)
- new API format
- API outage

Traceback (most recent call last):
File "C:\Users\Erhard\Documents\hyundai_kia_connect_monitor-R3.15.0\hyundai_kia_connect_api\KiaUvoApiEU.py", line 334, in update_vehicle_with_cached_state
state = self._get_driving_info(token, vehicle)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Erhard\Documents\hyundai_kia_connect_monitor-R3.15.0\hyundai_kia_connect_api\KiaUvoApiEU.py", line 1073, in _get_driving_info
and drivingInfoItem["calculativeOdo"] > 0
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
KeyError: 'calculativeOdo'

I asked to provide the information from the drive info, and the returned information is indeed only partly filled:

DEBUG:urllib3.connectionpool:https://prd.eu-ccapi.hyundai.com:8080 "POST /api/v1/spa/vehicles/de75e7e1-a460-471f-b229-59ea3f6386e4/drvhistory HTTP/1.1" 200 169
DEBUG:hyundai_kia_connect_api.KiaUvoApiEU:hyundai_kia_connect_api - get_driving_info responseAlltime {'retCode': 'S', 'resCode': '0000', 'resMsg': {'drivingInfo': [{'drivingPeriod': 0}, {'drivingPeriod': 1}], 'drivingInfoDetail': []}, 'msgId': '4c9e6e9f-a246-4e85-88f1-904edca7f3e4'}
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): prd.eu-ccapi.hyundai.com:8080
DEBUG:urllib3.connectionpool:https://prd.eu-ccapi.hyundai.com:8080 "POST /api/v1/spa/vehicles/de75e7e1-a460-471f-b229-59ea3f6386e4/drvhistory HTTP/1.1" 200 189
DEBUG:hyundai_kia_connect_api.KiaUvoApiEU:hyundai_kia_connect_api - get_driving_info response30d {'retCode': 'S', 'resCode': '0000', 'resMsg': {'drivingInfo': [{'drivingPeriod': 0}, {'drivingPeriod': 1}, {'drivingPeriod': 2}], 'drivingInfoDetail': []}, 'msgId': 'a5857467-ff82-408c-bf04-a932bb5c7cd8'}

If I compare it to what is returned for my IONIQ 5:

DEBUG:urllib3.connectionpool:https://prd.eu-ccapi.hyundai.com:8080 "POST /api/v1/spa/vehicles/9ac0c568-e9fe-4b75-a1c4-0d772063f9fd/drvhistory HTTP/1.1" 200 1160
DEBUG:hyundai_kia_connect_api.KiaUvoApiEU:hyundai_kia_connect_api - get_driving_info responseAlltime {'retCode': 'S', 'resCode': '0000', 'resMsg': {'drivingInfo': [{'drivingPeriod': 0, 'totalPwrCsp': 415546, 'motorPwrCsp': 338848, 'climatePwrCsp': 16678, 'eDPwrCsp': 60020, 'batteryMgPwrCsp': 0, 'regenPwr': 117959, 'calculativeOdo': 2403}, {'drivingPeriod': 1, 'totalPwrCsp': 5467, 'motorPwrCsp': 4458, 'climatePwrCsp': 219, 'eDPwrCsp': 789, 'batteryMgPwrCsp': 0, 'regenPwr': 1552, 'calculativeOdo': 31.61842105263158}], 'drivingInfoDetail': [{'drivingPeriod': 1, 'drivingDate': '202401', 'totalPwrCsp': 152, 'motorPwrCsp': 22, 'climatePwrCsp': 10, 'eDPwrCsp': 120, 'batteryMgPwrCsp': 0, 'regenPwr': 12, 'calculativeOdo': 0}, {'drivingPeriod': 1, 'drivingDate': '202312', 'totalPwrCsp': 191315, 'motorPwrCsp': 159300, 'climatePwrCsp': 8545, 'eDPwrCsp': 23470, 'batteryMgPwrCsp': 0, 'regenPwr': 45924, 'calculativeOdo': 1057}, {'drivingPeriod': 1, 'drivingDate': '202311', 'totalPwrCsp': 111727, 'motorPwrCsp': 84556, 'climatePwrCsp': 6181, 'eDPwrCsp': 20990, 'batteryMgPwrCsp': 0, 'regenPwr': 36046, 'calculativeOdo': 606}, {'drivingPeriod': 1, 'drivingDate': '202310', 'totalPwrCsp': 112352, 'motorPwrCsp': 94970, 'climatePwrCsp': 1942, 'eDPwrCsp': 15440, 'batteryMgPwrCsp': 0, 'regenPwr': 35977, 'calculativeOdo': 740}]}, 'msgId': '72aeb740-1552-4ddf-b4cb-0fb2dcde4e41'}
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): prd.eu-ccapi.hyundai.com:8080
DEBUG:urllib3.connectionpool:https://prd.eu-ccapi.hyundai.com:8080 "POST /api/v1/spa/vehicles/9ac0c568-e9fe-4b75-a1c4-0d772063f9fd/drvhistory HTTP/1.1" 200 None
DEBUG:hyundai_kia_connect_api.KiaUvoApiEU:hyundai_kia_connect_api - get_driving_info response30d {'retCode': 'S', 'resCode': '0000', 'resMsg': {'drivingInfo': [{'drivingPeriod': 0, 'totalPwrCsp': 184952, 'motorPwrCsp': 154861, 'climatePwrCsp': 7911, 'eDPwrCsp': 22180, 'batteryMgPwrCsp': 0, 'regenPwr': 43875, 'calculativeOdo': 1024}, {'drivingPeriod': 1, 'totalPwrCsp': 7398, 'motorPwrCsp': 6194, 'climatePwrCsp': 316, 'eDPwrCsp': 887, 'batteryMgPwrCsp': 0, 'regenPwr': 1755, 'calculativeOdo': 40.96}, {'drivingPeriod': 2, 'totalPwrCsp': 11746, 'motorPwrCsp': 10822, 'climatePwrCsp': 144, 'eDPwrCsp': 780, 'batteryMgPwrCsp': 0, 'regenPwr': 1528, 'calculativeOdo': 80}], 'drivingInfoDetail': [{'drivingPeriod': 0, 'drivingDate': '20240101', 'totalPwrCsp': 152, 'motorPwrCsp': 22, 'climatePwrCsp': 10, 'eDPwrCsp': 120, 'batteryMgPwrCsp': 0, 'regenPwr': 12, 'calculativeOdo': 0}, {'drivingPeriod': 0, 'drivingDate': '20231231', 'totalPwrCsp': 24941, 'motorPwrCsp': 23125, 'climatePwrCsp': 366, 'eDPwrCsp': 1450, 'batteryMgPwrCsp': 0, 'regenPwr': 2932, 'calculativeOdo': 161}, {'drivingPeriod': 0, 'drivingDate': '20231230', 'totalPwrCsp': 4237, 'motorPwrCsp': 3275, 'climatePwrCsp': 152, 'eDPwrCsp': 810, 'batteryMgPwrCsp': 0, 'regenPwr': 1308, 'calculativeOdo': 24}, {'drivingPeriod': 0, 'drivingDate': '20231229', 'totalPwrCsp': 120, 'motorPwrCsp': 4, 'climatePwrCsp': 6, 'eDPwrCsp': 110, 'batteryMgPwrCsp': 0, 'regenPwr': 0, 'calculativeOdo': 0}, {'drivingPeriod': 0, 'drivingDate': '20231228', 'totalPwrCsp': 2985, 'motorPwrCsp': 2338, 'climatePwrCsp': 77, 'eDPwrCsp': 570, 'batteryMgPwrCsp': 0, 'regenPwr': 1058, 'calculativeOdo': 18}, {'drivingPeriod': 0, 'drivingDate': '20231227', 'totalPwrCsp': 7704, 'motorPwrCsp': 5342, 'climatePwrCsp': 1082, 'eDPwrCsp': 1280, 'batteryMgPwrCsp': 0, 'regenPwr': 3636, 'calculativeOdo': 36}, {'drivingPeriod': 0, 'drivingDate': '20231224', 'totalPwrCsp': 31837, 'motorPwrCsp': 29177, 'climatePwrCsp': 530, 'eDPwrCsp': 2130, 'batteryMgPwrCsp': 0, 'regenPwr': 5250, 'calculativeOdo': 175}, {'drivingPeriod': 0, 'drivingDate': '20231222', 'totalPwrCsp': 5400, 'motorPwrCsp': 4048, 'climatePwrCsp': 202, 'eDPwrCsp': 1150, 'batteryMgPwrCsp': 0, 'regenPwr': 2228, 'calculativeOdo': 31}, {'drivingPeriod': 0, 'drivingDate': '20231221', 'totalPwrCsp': 6134, 'motorPwrCsp': 5176, 'climatePwrCsp': 158, 'eDPwrCsp': 800, 'batteryMgPwrCsp': 0, 'regenPwr': 3187, 'calculativeOdo': 36}, {'drivingPeriod': 0, 'drivingDate': '20231220', 'totalPwrCsp': 3182, 'motorPwrCsp': 2469, 'climatePwrCsp': 203, 'eDPwrCsp': 510, 'batteryMgPwrCsp': 0, 'regenPwr': 1410, 'calculativeOdo': 18}, {'drivingPeriod': 0, 'drivingDate': '20231219', 'totalPwrCsp': 7730, 'motorPwrCsp': 6213, 'climatePwrCsp': 437, 'eDPwrCsp': 1080, 'batteryMgPwrCsp': 0, 'regenPwr': 2265, 'calculativeOdo': 36}, {'drivingPeriod': 0, 'drivingDate': '20231218', 'totalPwrCsp': 3598, 'motorPwrCsp': 2412, 'climatePwrCsp': 576, 'eDPwrCsp': 610, 'batteryMgPwrCsp': 0, 'regenPwr': 1304, 'calculativeOdo': 19}, {'drivingPeriod': 0, 'drivingDate': '20231217', 'totalPwrCsp': 3267, 'motorPwrCsp': 2599, 'climatePwrCsp': 148, 'eDPwrCsp': 520, 'batteryMgPwrCsp': 0, 'regenPwr': 1288, 'calculativeOdo': 18}, {'drivingPeriod': 0, 'drivingDate': '20231216', 'totalPwrCsp': 24804, 'motorPwrCsp': 22933, 'climatePwrCsp': 451, 'eDPwrCsp': 1420, 'batteryMgPwrCsp': 0, 'regenPwr': 3175, 'calculativeOdo': 157}, {'drivingPeriod': 0, 'drivingDate': '20231215', 'totalPwrCsp': 3140, 'motorPwrCsp': 2368, 'climatePwrCsp': 192, 'eDPwrCsp': 580, 'batteryMgPwrCsp': 0, 'regenPwr': 1006, 'calculativeOdo': 18}, {'drivingPeriod': 0, 'drivingDate': '20231214', 'totalPwrCsp': 6684, 'motorPwrCsp': 5687, 'climatePwrCsp': 297, 'eDPwrCsp': 700, 'batteryMgPwrCsp': 0, 'regenPwr': 1978, 'calculativeOdo': 38}, {'drivingPeriod': 0, 'drivingDate': '20231213', 'totalPwrCsp': 3242, 'motorPwrCsp': 2464, 'climatePwrCsp': 148, 'eDPwrCsp': 630, 'batteryMgPwrCsp': 0, 'regenPwr': 1148, 'calculativeOdo': 18}, {'drivingPeriod': 0, 'drivingDate': '20231212', 'totalPwrCsp': 2847, 'motorPwrCsp': 2081, 'climatePwrCsp': 166, 'eDPwrCsp': 600, 'batteryMgPwrCsp': 0, 'regenPwr': 619, 'calculativeOdo': 10}, {'drivingPeriod': 0, 'drivingDate': '20231211', 'totalPwrCsp': 6098, 'motorPwrCsp': 4665, 'climatePwrCsp': 243, 'eDPwrCsp': 1190, 'batteryMgPwrCsp': 0, 'regenPwr': 1735, 'calculativeOdo': 30}, {'drivingPeriod': 0, 'drivingDate': '20231210', 'totalPwrCsp': 1534, 'motorPwrCsp': 1068, 'climatePwrCsp': 96, 'eDPwrCsp': 370, 'batteryMgPwrCsp': 0, 'regenPwr': 81, 'calculativeOdo': 6}, {'drivingPeriod': 0, 'drivingDate': '20231209', 'totalPwrCsp': 9360, 'motorPwrCsp': 7704, 'climatePwrCsp': 406, 'eDPwrCsp': 1250, 'batteryMgPwrCsp': 0, 'regenPwr': 1611, 'calculativeOdo': 45}, {'drivingPeriod': 0, 'drivingDate': '20231207', 'totalPwrCsp': 4174, 'motorPwrCsp': 3014, 'climatePwrCsp': 370, 'eDPwrCsp': 790, 'batteryMgPwrCsp': 0, 'regenPwr': 1540, 'calculativeOdo': 20}, {'drivingPeriod': 0, 'drivingDate': '20231206', 'totalPwrCsp': 4030, 'motorPwrCsp': 2789, 'climatePwrCsp': 281, 'eDPwrCsp': 960, 'batteryMgPwrCsp': 0, 'regenPwr': 1777, 'calculativeOdo': 22}, {'drivingPeriod': 0, 'drivingDate': '20231205', 'totalPwrCsp': 7689, 'motorPwrCsp': 5450, 'climatePwrCsp': 729, 'eDPwrCsp': 1510, 'batteryMgPwrCsp': 0, 'regenPwr': 1627, 'calculativeOdo': 34}, {'drivingPeriod': 0, 'drivingDate': '20231204', 'totalPwrCsp': 10063, 'motorPwrCsp': 8438, 'climatePwrCsp': 585, 'eDPwrCsp': 1040, 'batteryMgPwrCsp': 0, 'regenPwr': 1700, 'calculativeOdo': 54}]}, 'msgId': '8ae49b4d-863c-4802-b18f-ee63f2e12046'}

At least the KiaUvoApiEU.py should be adapted, to not throw an exception, but it should just not fill the daily_stats and just continue without this information filled.

However, maybe the daily stats needs to be gather via a different API, but that means someone having an EV9 or Kona 2024 model should do some sniffing with Kia Connect or Hyundai Bluelink.

I have a proposal to at least avoid the exception, by adding checks to KiaUvoApiEU.py in method _get_driving_info, adding checks:

if get_child_value(day, "calculativeOdo") is not None:

and

if get_child_value(drivingInfoItem, "calculativeOdo") is not None:

Whole fragment of KiaUvoApiEU.py in method _get_driving_info (optimized):

            drivingInfo["dailyStats"] = []
            if get_child_value(response30d, "resMsg.drivingInfoDetail.0"):
                for day in response30d["resMsg"]["drivingInfoDetail"]:
                    if get_child_value(day, "calculativeOdo") is not None:
                        processedDay = DailyDrivingStats(
                            date=dt.datetime.strptime(day["drivingDate"], "%Y%m%d"),
                            total_consumed=get_child_value(day, "totalPwrCsp"),
                            engine_consumption=get_child_value(day, "motorPwrCsp"),
                            climate_consumption=get_child_value(day, "climatePwrCsp"),
                            onboard_electronics_consumption=get_child_value(
                                day, "eDPwrCsp"
                            ),
                            battery_care_consumption=get_child_value(
                                day, "batteryMgPwrCsp"
                            ),
                            regenerated_energy=get_child_value(day, "regenPwr"),
                            distance=get_child_value(day, "calculativeOdo"),
                        )
                        drivingInfo["dailyStats"].append(processedDay)

            for drivingInfoItem in response30d["resMsg"]["drivingInfo"]:
                calculativeOdo = get_child_value(drivingInfoItem, "calculativeOdo")
                if (
                    get_child_value(drivingInfoItem, "drivingPeriod") == 0
                    and calculativeOdo is not None
                    and calculativeOdo > 0
                ):
                    drivingInfo["consumption30d"] = round(
                        get_child_value(drivingInfoItem, "totalPwrCsp") / calculativeOdo
                    )
                    break
Bubo08 commented 6 months ago

I sniffed the code of my EV9. It looks like the same API but new keys. At the time I am stuck with the CBR calculation. You may find more details here: https://discord.com/channels/1185840788979064832/1185840882461708309

ZuinigeRijder commented 6 months ago

Also other information is not filled, so my defensive proposal 2 posts up does not help, because other API's must also be adapted to have a useful functionality, for example the next is NOT filled for Kona 2024:

_odometer=None,
_odometer_value=None,
_odometer_unit=None,
_geocode_address=None,
_geocode_name=None,
ev_battery_percentage=None,
_ev_driving_range=None
ristoavila commented 6 months ago

Interesting is that somehow someone in reddit has it working https://www.reddit.com/r/KiaEV9/comments/192ogwh/home_assistant_status_dashboard/

ristoavila commented 6 months ago

I sniffed the code of my EV9. It looks like the same API but new keys. At the time I am stuck with the CBR calculation. You may find more details here: https://discord.com/channels/1185840788979064832/1185840882461708309

it seems I can't access the channel where is it located?

ZuinigeRijder commented 6 months ago

@Bubo08 has removed the invite to the channel in one of the posts, so you should ask @Bubo08

Bubo08 commented 6 months ago

I created a pull request with my changes: https://github.com/Hyundai-Kia-Connect/hyundai_kia_connect_api/pull/480

In my test application I'm getting now the basic data like odometer, range and battery percentage. What I would like to do now is testing my changes in home assistant but I am not sure how to do it.

The caveta is that the change is only for EU.

cdnninja commented 6 months ago

Interesting is that somehow someone in reddit has it working https://www.reddit.com/r/KiaEV9/comments/192ogwh/home_assistant_status_dashboard/

Keep in mind only eu isn't working. Other regions are different code in this integration.

ristoavila commented 6 months ago

I created a pull request with my changes: Hyundai-Kia-Connect/hyundai_kia_connect_api#480

In my test application I'm getting now the basic data like odometer, range and battery percentage. What I would like to do now is testing my changes in home assistant but I am not sure how to do it.

The caveta is that the change is only for EU.

With your data there seems to be more data but not mapped correctly. image

E.g. here it seems not to be identified as EV and now the Highvoltage battery level is mapped to 12v battery. With out your patch the small battery level was reported correctly at least what I know of. btw I'm also located in EU and can easily test changes on my HA as I do have few instanses to try out.

Bubo08 commented 6 months ago

Cool!

I will try to adapt for EV and non EV. The mapping is not easy as all the name changed and I was not able to test it in the home assistant. The odometer was the only easy one. The good thing is, that you should now see all the delivered data in the debug log and could help me with the wrong mappings.

Where did you put the changed api in the home assistant directory so that you could test? I would also like to do it :-)

ristoavila commented 6 months ago

I'm running HA in python virtual environment and the api package is located in ./lib/python3.11/site-packages/kia_hyundai_api inside the virtual env folder.

Bubo08 commented 6 months ago

I'm using hassion and can not find this library. Anyway, I updated my pull request. Hopefully, both batteries are now correct.

Bubo08 commented 6 months ago

Do you know of other wrong attributes?

ristoavila commented 6 months ago

Thanks, now it seems two batterys show up correctly. I also now noticed that GPS locations is now also up to date!

Looking through logs I still did see `2024-01-17 20:53:44.736 ERROR (SyncWorker_10) [hyundai_kia_connect_api.KiaUvoApiEU] Failed to parse driving info. Possible reasons:

Traceback (most recent call last): File "/homeassistant/lib/python3.11/site-packages/hyundai_kia_connect_api/KiaUvoApiEU.py", line 338, in update_vehicle_with_cached_state state = self._get_driving_info(token, vehicle) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/homeassistant/lib/python3.11/site-packages/hyundai_kia_connect_api/KiaUvoApiEU.py", line 1182, in _get_driving_info and drivingInfoItem["calculativeOdo"] > 0


KeyError: 'calculativeOdo'
`
This is propably why the daily driving stats shows 0 d.
Also not sure if the estimated charging numbers make sense.
![image](https://github.com/Hyundai-Kia-Connect/kia_uvo/assets/47506692/91c625d2-c33c-47e3-b89a-856e62e7c983)
Not sure how I would intrepreter "Fast charge duration", "Portable charge duration" and "Station charge duration"
If Fast charge == home 11kw AC then it propably should be around 4,8 hours, portable charger = 2.4kw travel charger time should be over 22h. Station Charge I would intrepreter to be DC charger where the 69min could match considering notable down scale on the charging time. Also to me its unclear are these times towards set limits e.g. now AC charging limit is se to 60% in that case I would switch the 360min with 80min.

Locking status is also not updated nor controllable. 

Missing status compared to previous where it was not detected as EV
Door lock & functionality (it's not working with the previous either but shows locked)
Air conditioner status
Defrost
Engine
Front Left Seat heating
Front Left Window
Front Right Seat heating
Front Right Window
last updated at
Rear left seat heater
rear right seat
smart key battery warning
steering wheel heater
tire pressure - all

Missing stats comparing to the US version would be
get&set AC Chargining limit
get&set DC charging limit
DTC count
Charger status (Not charging / charging)
Plug status
last update
next service
Trunk status
set temperature
back window heater
air conditioner
defrost
side mirror heater
steering wheel heater
engine status
Bubo08 commented 6 months ago

Now a bigger change. Driving statistics is working now. I also switched the values as proposed. I still have to map status attributes but other things might work now.

ristoavila commented 6 months ago

Now a bigger change. Driving statistics is working now. I also switched the values as proposed. I still have to map status attributes but other things might work now.

No errors anymore but I'm not sure if the daily driving stats make sense as it now shows 13 d, I'm not sure what that means. With latest patch there now is also Total Energy Consumption and Total Energy Regeneration added.

image

Today when going to work I was also able to look at the charging limits and the durations mentioned earlier comes from there.

"Fast Charge Duration" -> High voltage DC charger "Super charger 100kw+" "Station Charge Duration" -> DC charger "50kw etc" "Portable Charger" -> 3-phase 11kw charger at home There is also 4th reported in the car and this is the real portable charger that comes with the car. Times provided are relative to set charging limits.

E.g. in my case I set both AC and DC limits to 80% at that time numbers were Highvoltage DC - 1h 7min DC - 1h 21min 3-phase 11kw AC - 4h 15min Travel charger - 18h 40min

Also still with the latests changes I see image

This shows "unknown" state so it doesn't know if it's locked or not. With out your changes it can show the right state and history but still can't open or close the actual locks.

image

cdnninja commented 6 months ago

2.19 is out as a beta release to make this easier to access. Big thanks to Bubo08 for making this happen!

Bubo08 commented 6 months ago

The new pre release 2.19.0 fixed the problem. Thanks all for there help :-)

zappoo commented 5 months ago

No support for Kia EV9 in AUstralia, sadly :( Would love to see this added.

cdnninja commented 5 months ago

@zappoo please open an issue for this. Each region is developed separately.