hyundai_kia_connect_api
hyundai_kia_connect_api copied to clipboard
Instructions how to use
Please add some pointers in the usage documentation as in how to you the module.
Apart from hyundai_kia_connect_api :
- sample code for the parameters (especially region and brand)
- sample code to initialise the module
- sample code to eg. request status
This is still work in progress, a good starting point: https://github.com/home-assistant/core/pull/62451
Let's keep this issue open to come up with basic documentation.
I'll try come up with some of the basics in the next few days. Any example format you both like?
Misclick on the close. I started on the homepage to document this. When I have more time I will add examples of initializing the module and a few basics calls. As a quick note we have done a recent refactor of the code, so far initial pass is done on EU and CA regions. USA hasn't been done yet, I hope to do that this weekend but don't have anyone lined up to test. The refactor allows all these APIs to work with multiple cars where as the previous versions only worked on the first car on an account.
I am interested to hear what you are working on if willing to share! It may help us ensure this API works for others as well.
I am interested to hear what you are working on if willing to share! It may help us ensure this API works for others as well.
My fist intention would to make sure that all API endpoints the app uses are made available. That is not to hard. That way this library will be up to par with Bluelinky. Secondly I have some ideas for minor additions to the HA integration, such as setting charge schedule, adjust temperature for preheating, and retrieve information about trips and store that info in a database..
Any example format you both like?
Maybe a working sample code: importing the module connecting to the vehiclemanager loop through a menu for
- get a cached status
- get a refreshed status
- get the location
- lock the door
- stop charging
- set the climate and start it
- display information on car and owner, service etc.
Did you go through the open home assistant PR? You will find answers for almost of these questions.
Did you go through the open home assistant PR? You will find answers for almost of these questions. I don't have any questions. @cdnninja asked what documentation of this repo I would like to see, I answered his question..
Got it, until documentation is ready, that will give you a brief idea how we are using this.
@PierreLevres Any chance are your car is from the USA? Hoping to have someone help test and update either the Kia or Hyundai API to help get it working.
@PierreLevres Any chance are your car is from the USA? Hoping to have someone help test and update either the Kia or Hyundai API to help get it working.
Sorry no, European. But you can find some USA car owners in the discord server for BlueLinky. They might be willing to test.
Hi All,
I got the following so far:
from hyundai_kia_connect_api import *
vm = VehicleManager(region=1, brand=2, username="[email protected]", password="secret", pin="1234")
print(vm.check_and_refresh_token())
print(vm.vehicles)
Which returns the vehicle id, name, model and registration_date - the rest is pretty much "None".
Did you check the open PR link above? It will help you a lot?
Hi All,
I got the following so far:
from hyundai_kia_connect_api import *
vm = VehicleManager(region=1, brand=2, username="[email protected]", password="secret", pin="1234")
print(vm.check_and_refresh_token())
print(vm.vehicles)
Which returns the vehicle id, name, model and registration_date - the rest is pretty much "None".
Try vm.update_all_vehicles_with_cached_state() right after you update vehicle manager. You will then have the data for the car.
Or call check_and_force_update_vehicles
, it will loop through all vehicles, get cached data from cloud and depending on force_refresh interval you supplied, it will try to force refresh stale data.
All data will be stored and updated inside Manager.vehicles dictionary
@PierreLevres the home page now has this above example listed plus the other methods vehicle manager offers.
Hi all,
Thank you for posting the example. I updated my code and got the following results:
vm.check_and_force_update_vehicles(60)
gives me the following error:
Traceback (most recent call last):
File "/home/user/PycharmProjects/bluelinx/main.py", line 7, in <module>
vm.check_and_force_update_vehicles(60)
File "/home/user/PycharmProjects/bluelinx/venv/lib/python3.10/site-packages/hyundai_kia_connect_api/VehicleManager.py", line 65, in check_and_force_update_vehicles
f"time diff - {(started_at_utc - vehicle.last_updated_at).total_seconds()}"
TypeError: can't subtract offset-naive and offset-aware datetimes
and
vm.update_all_vehicles_with_cached_state()
seems to struggle with the TEMPERATURE_UNITS being empty:
Traceback (most recent call last):
File "/home/user/PycharmProjects/bluelinx/main.py", line 6, in <module>
vm.update_all_vehicles_with_cached_state()
File "/home/user/PycharmProjects/bluelinx/venv/lib/python3.10/site-packages/hyundai_kia_connect_api/VehicleManager.py", line 55, in update_all_vehicles_with_cached_state
self.update_vehicle_with_cached_state(self.get_vehicle(vehicle_id))
File "/home/user/PycharmProjects/bluelinx/venv/lib/python3.10/site-packages/hyundai_kia_connect_api/VehicleManager.py", line 58, in update_vehicle_with_cached_state
self.api.update_vehicle_with_cached_state(self.token, vehicle)
File "/home/user/PycharmProjects/bluelinx/venv/lib/python3.10/site-packages/hyundai_kia_connect_api/KiaUvoApiEU.py", line 202, in update_vehicle_with_cached_state
TEMPERATURE_UNITS[
KeyError: 0
Potentially python-dateutil
is interfering - any ideas?
Great work !!!
Op 15 jan. 2022 om 05:24 heeft cdnninja @.***> het volgende geschreven:
@PierreLevres the home page now has this above example listed plus the other methods vehicle manager offers.
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.
Hi all,
Thank you for posting the example. I updated my code and got the following results:
vm.check_and_force_update_vehicles(60)
gives me the following error:Traceback (most recent call last): File "/home/user/PycharmProjects/bluelinx/main.py", line 7, in <module> vm.check_and_force_update_vehicles(60) File "/home/user/PycharmProjects/bluelinx/venv/lib/python3.10/site-packages/hyundai_kia_connect_api/VehicleManager.py", line 65, in check_and_force_update_vehicles f"time diff - {(started_at_utc - vehicle.last_updated_at).total_seconds()}" TypeError: can't subtract offset-naive and offset-aware datetimes
and
vm.update_all_vehicles_with_cached_state()
seems to struggle with the TEMPERATURE_UNITS being empty:Traceback (most recent call last): File "/home/user/PycharmProjects/bluelinx/main.py", line 6, in <module> vm.update_all_vehicles_with_cached_state() File "/home/user/PycharmProjects/bluelinx/venv/lib/python3.10/site-packages/hyundai_kia_connect_api/VehicleManager.py", line 55, in update_all_vehicles_with_cached_state self.update_vehicle_with_cached_state(self.get_vehicle(vehicle_id)) File "/home/user/PycharmProjects/bluelinx/venv/lib/python3.10/site-packages/hyundai_kia_connect_api/VehicleManager.py", line 58, in update_vehicle_with_cached_state self.api.update_vehicle_with_cached_state(self.token, vehicle) File "/home/user/PycharmProjects/bluelinx/venv/lib/python3.10/site-packages/hyundai_kia_connect_api/KiaUvoApiEU.py", line 202, in update_vehicle_with_cached_state TEMPERATURE_UNITS[ KeyError: 0
Potentially
python-dateutil
is interfering - any ideas?
v1.18.8 should resolve that second keyError. Please retry and let me know if it is solved.
I have also cut a PR #15 for the first issue. This is caused by it having a last updated yet since we haven't called for vehicle data. It should work if you first call for cached state and then force the update. That should be resolved soon too though.
@cdnninja Thank you very much - v1.18.8 fixed it: I know see plenty of details. Is there also a way to e.g. activate the defrost remotely or set the per-conditioning timer?
@Empor-co Remote start does exist in the base APIs. We haven't exposed it yet to vehicleManager. It does work in the older version of this for home assistant though: https://github.com/fuatakgun/kia_uvo. I don't think implementing this would take long at all. I will cut a separate issue for remote start. For each feature like this could you cut a issue and we can track separately? Testers like you are key to this growing and being robust so thanks for playing with it!
This API is the early days of prepping for core integration. It eventually will be used by the above custom as well once it has feature parity.
Hi, thanks for this great module: I've start using it to make a plugin for Domoticz, https://github.com/CreasolTech/domoticz-hyundai-kia I also think that some more comments in the VehicleManager.py will help who, as me, don't know enough about python programming and kia/hyundai API/restrictions/.... Every N minutes, I call:
vm.check_and_refresh_token() vm.force_refresh_all_vehicles_states() vm.update_all_vehicles_with_cached_state()
Is this sequence good to get a complete refreshed status from the vehicle? While some status are freshed (e.g. is_charging, ev_range, ....), the location is 3 hours old. I tried several times to refresh, but location keeps old. Then I open Kia Connect app on my smartphone, check the location (that is old), enter pin, and location get refreshed to the new one on both smartphone and Domoticz. What is the right way to get location refreshed? Thanks a lot !! Paolo
You might want to take a look at https://github.com/JanJaapKo/BlUVO https://github.com/JanJaapKo/BlUVO An already existing plugin for domoticz...
Location is refreshed by the api call /location, have a look at the bluelinky code: https://github.com/Hacksore/bluelinky/blob/master/src/vehicles/european.vehicle.ts https://github.com/Hacksore/bluelinky/blob/master/src/vehicles/european.vehicle.ts
public async location(): Promise<VehicleLocation> {
const http = await this.controller.getVehicleHttpService();
try {
const response = this.updateRates(
await http.get(/api/v2/spa/vehicles/${this.vehicleConfig.id}/location
)
);
const data = response.body.resMsg?.gpsDetail ?? response.body.resMsg;
this._location = {
latitude: data?.coord?.lat,
longitude: data?.coord?.lon,
altitude: data?.coord?.alt,
speed: {
unit: data?.speed?.unit,
value: data?.speed?.value,
},
heading: data?.head,
};
return this._location;
} catch (err) {
throw manageBluelinkyError(err, 'EuropeVehicle.location');
}
}
On 21 Feb 2022, at 16:46, Creasol @.***> wrote:
Hi, thanks for this great module: I've start using it to make a plugin for Domoticz, https://github.com/CreasolTech/domoticz-hyundai-kia https://github.com/CreasolTech/domoticz-hyundai-kia I also think that some more comments in the VehicleManager.py will help who, as me, don't know enough about python programming and kia/hyundai API/restrictions/.... Every N minutes, I call:
vm.check_and_refresh_token() vm.force_refresh_all_vehicles_states() vm.update_all_vehicles_with_cached_state()
Is this sequence good to get a complete refreshed status from the vehicle? While some status are freshed (e.g. is_charging, ev_range, ....), the location is 3 hours old. I tried several times to refresh, but location keeps old. Then I open Kia Connect app on my smartphone, check the location (that is old), enter pin, and location get refreshed to the new one on both smartphone and Domoticz. What is the right way to get location refreshed? Thanks a lot !! Paolo
— Reply to this email directly, view it on GitHub https://github.com/Hyundai-Kia-Connect/hyundai_kia_connect_api/issues/12#issuecomment-1047013578, or unsubscribe https://github.com/notifications/unsubscribe-auth/AO7MCG4EC4UP5FVND27JRZDU4JM55ANCNFSM5LQWJVMA. You are receiving this because you were mentioned.
Thanks for the answer. In this hyundai_kia_connect_api I cannot find a call to the url /location : I've just checked the API from PierreLevres and found that, to get a refresh, he call, in sequence, /status #to get all data and ask for vehicle fresh data /status/latest # to read new data from cloud then compare the first with second odometer values: if differ, call the url /location # to get fresh coordinates Is it useful to call /location url to get a fresh location, or is it useless? Thanks.
Which region? I assume EU? I don’t think location update is implemented for EU. That will be a quick fix if you can test it for me since I am in CA.
On Feb 23, 2022, at 11:26 AM, Creasol @.***> wrote:
Thanks for the answer. In this hyundai_kia_connect_api I cannot find a call to the url /location : I've just checked the API from PierreLevres and found that, to get a refresh, he call, in sequence, /status #to get all data and ask for vehicle fresh data /status/latest # to read new data from cloud
then compare the first with second odometer: if differ, call the url
/location # to get fresh coordinates Is it useful to call /location url to get a fresh location, or is it useless? Thanks.
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.
Which region? I assume EU? I don’t think location update is implemented for EU. That will be a quick fix if you can test it for me since I am in CA.
Yes, /location URL exists in EU region.
This is the response:
{'retCode': 'S', 'resCode': '0000', 'resMsg': {'gpsDetail': {'coord': {'lat': 45.8815, 'lon': 12.189481, 'alt': 0, 'type': 0}, 'head': 0, 'speed': {'value': 0, 'unit': 0}, 'accuracy': {'hdop': 0, 'pdop': 0}, 'time': '20220223205017'}, 'drvDistance': {'rangeByFuel': {'evModeRange': {'value': 394, 'unit': 1}, 'totalAvailableRange': {'value': 394, 'unit': 1}}, 'type': 2}}, 'msgId': '285475a6-b1db-48db-ab2c-9827b37f43fc'}
#51 adds this calling method. Interested on feedback. Current approach automatically forces this location update if the odometer has changed on the cached vehicle call. Would you rather to have the control available to you to update or are you okay with us checking if odometer changed and updating.
In a future PR I am also thinking of limiting since the last location call so it will only update location lets say once an hour.
#51 adds this calling method. Interested on feedback. Current approach automatically forces this location update if the odometer has changed on the cached vehicle call. Would you rather to have the control available to you to update or are you okay with us checking if odometer changed and updating.
Thanks @cdnninja , I have just fetch your PR , but I have to move the car to know if it really works (and here is midnight!). Probably the speed variable should also be updated...
Hi @cdnninja , I've checked the lib with your PR, and I've also added
def get_location(self, vehicle_id: str) -> bool:
self.api.get_location(self.token, self.get_vehicle(vehicle_id))
to VehicleManager.py so I can call vm.get_location(). If I call vm.force_refresh_all_vehicles_states() , I can see that API get /status and /status/latest , but they are exactly the same with the same odometer (when car is moving, of course). If then I call vm.get_location(VEHICLEID) which call api.get_location(TOKEN, VEHICLE_ID) then I get the updated location and speed.
So, the main problem is that vm.force_refresh_all_vehicles_states() does not poll data from the car, but always from the cache, so odometer does not change and api.get_location() is not called. What is the method I should call to ask Kia to fetch data from the car? If you prefer, my Telegram nick is @CreasolTech