Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EU (>2023) controls - how to help get working? #995

Open
badnbusy opened this issue Dec 25, 2024 · 22 comments
Open

EU (>2023) controls - how to help get working? #995

badnbusy opened this issue Dec 25, 2024 · 22 comments

Comments

@badnbusy
Copy link

badnbusy commented Dec 25, 2024

How can I help in getting the newer cars EU (>2023) controls working like Climate, Seat Controls, Charge Start/Stop, Open/Close Windows etc?

According to the docs, these controls are possible on pre 2023 models so what has changed?

How can I help in figuring out the API calls/endpoints?

I have a Hyundai Kona EV 2024 (UK).

Thanks

@cdnninja
Copy link
Collaborator

cdnninja commented Dec 25, 2024

Have you tested and they don't work? My understanding is they do work.

@badnbusy
Copy link
Author

badnbusy commented Dec 25, 2024

They don't seem to do anything and checking in Bluelink they haven't turned on the AC or whatever set on the options...

HA log when performing the Climate enable option:

This error originated from a custom integration.

Logger: homeassistant
Source: custom_components/kia_uvo/coordinator.py:175
integration: Kia Uvo / Hyundai Bluelink (documentation, issues)
First occurred: 00:30:36 (2 occurrences)
Last logged: 00:32:10

Error doing job: Task exception was never retrieved (None)
Traceback (most recent call last):
  File "/config/custom_components/kia_uvo/coordinator.py", line 175, in async_await_action_and_refresh
    await self.hass.async_add_executor_job(
    ...<5 lines>...
    )
  File "/usr/local/lib/python3.13/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.13/site-packages/hyundai_kia_connect_api/VehicleManager.py", line 215, in check_action_status
    return self.api.check_action_status(
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        self.token, self.get_vehicle(vehicle_id), action_id, synchronous, timeout
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/local/lib/python3.13/site-packages/hyundai_kia_connect_api/KiaUvoApiEU.py", line 1727, in check_action_status
    state = self.check_action_status(
        token, vehicle, action_id, synchronous=False
    )
  File "/usr/local/lib/python3.13/site-packages/hyundai_kia_connect_api/KiaUvoApiEU.py", line 1767, in check_action_status
    raise APIError(f"No action found with ID {action_id}")
hyundai_kia_connect_api.exceptions.APIError: No action found with ID 74eee010-c257-11ef-b454-a2ddc41f8b0e

@cdnninja
Copy link
Collaborator

The action thing seems to be an ongoing item but shouldn't impact the first call. Climate start is very dependent on the options sent.

If you sniff the traffic from the native app you can compare the payload to see what it didn't work.

@badnbusy
Copy link
Author

badnbusy commented Dec 25, 2024

Ok, will do.

It will all be HTTPS so assuming some MITM proxy required here and a 3rd party CA cert on Android etc.

Tried Charles Proxy but the app refuses to connect with that even when SSL proxying is enabled.

Will go down the Android emulator route, with root access to install System CA certs and the app.

@cdnninja
Copy link
Collaborator

That's the right path. Certificate pinning is implemented as well which makes it harder. I have heard Android 6 helps getting around this. The blue linky discord has talked about this too. I don't live in eu so personally haven't needed to do this much. Canada is easier to sniff.

@steps56
Copy link

steps56 commented Jan 3, 2025

Android 6 ??? ... is ooooold.
We are at 13 min.

I'm in EU/Germany and at Android 13 using 2x HA setup serving 2 raspis/HA at 2 locations.
All working nice, even by VPN worldwide.

Anyway, AC f. i..is working for sure too.
You need the right action trigger setup.
Here my setup .yaml code for the AC card shown at the screens too.

Its the card shown after "force update".
(image of Ioniq5 used, has to be uploaded to HA's www folder)
Only thing not working, is seat heating.
This is deactivated by /at german/EU software sadly and even not possible by BlueLink App too.
But all the rest shown at the screens down here, is working nice.

type: picture-elements
image: /api/image/serve/186c68b153608507efaedecc91137f44/512x512
elements:
  - type: state-icon
    entity: binary_sensor.ioniq_5_marion_steps_air_conditioner
    icon: mdi:air-conditioner
    title: null
    state_color: true
    style:
      left: 10%
      top: 1%
      transform: scale(1.1, 1.1)
  - type: service-button
    title: Start AC
    target: {}
    style:
      color: black
      top: 90%
      left: 80%
    action: kia_uvo.start_climate
    data:
      device_id: c3e30095....... (deleted for security)
      duration: 10
      defrost: true
      heating: "4"
      flseat: "7"

Screenshot_20250103_160832_Home Assistant
Screenshot_20250103_162931_Home Assistant

Screenshot_20250103_160849_Home Assistant
Screenshot_20250103_160900_Home Assistant

@badnbusy
Copy link
Author

badnbusy commented Jan 7, 2025

So I've been testing this out against my car.

For the most part, climate works. I can start the climate with the front/rear defrost/heated wheel and also set the temperature.

The part that isn't working is the seat heating/cooling. It just ignores whatever I set and leaves them turned off. If I use the Bluelink app to enable climate, it correctly sets the seat heating/cooling to level 1/2/3 etc.

Here is the code I am using:

action: kia_uvo.start_climate
data:
  device_id: 55cdb61b5e8252ef836a97f576cf6db9
  climate: true
  duration: 5
  temperature: 20
  defrost: true
  heating: "1"
  flseat: "6"
  rlseat: "6"
  rrseat: "6"
  frseat: "6"

So the above works but without the values set in the xxseat options.

When I run the above action, the "data" attribute for my car returns the following for the seats:

Seat:
    Row2:
      Left:
        Climate:
          State: 2
      Right:
        Climate:
          State: 2
    Row1:
      Passenger:
        Climate:
          State: 2
      Driver:
        Climate:
          State: 2

image

When I enable the same through the Bluelink app, the "data" attribute looks like this:

  Seat:
    Row2:
      Left:
        Climate:
          State: 6
      Right:
        Climate:
          State: 6
    Row1:
      Passenger:
        Climate:
          State: 6
      Driver:
        Climate:
          State: 6

image

So it does look like the correct values, but using the above action, it doesn't work. Any clues?

I've tried sending the xxseat values with no quotes either, still doesn't work.

Also note, for my Kona 2024 UK/EU model, I have to use heating: "1" instead of heating: "4" in order to enable front/rear/wheel. If I use heating: "4" does not enable front/rear/wheel at all.

When enabling through Bluelink, the Home Assistant entities do show the seats being correctly set to "Low Heat":

image

Thanks

@steps56
Copy link

steps56 commented Jan 7, 2025

Seat Heating doesn't work remote in EU as far as I know and tested in Reality.
So no way to remote start Seatheating with BlueLink.
Everything else ist working nice even using HA.

@badnbusy
Copy link
Author

badnbusy commented Jan 7, 2025

Is that just because the code has changed for newer models? As the Bluelink app can do it so it must just be calling an endpoint with some json payload?

@cdnninja
Copy link
Collaborator

cdnninja commented Jan 7, 2025

Different payloads exist by model and years. seats aren't implemented in the payload for EU in this package right now. Someone needs to sniff the traffic and then implement it. Here is our payload format for EU:

https://github.com/Hyundai-Kia-Connect/hyundai_kia_connect_api/blob/3a672ef3caa24a7908e33326f2c5d801bf955d7a/hyundai_kia_connect_api/KiaUvoApiEU.py#L961-L970

As an example here is payload for Canada cars with seat support:

https://github.com/Hyundai-Kia-Connect/hyundai_kia_connect_api/blob/3a672ef3caa24a7908e33326f2c5d801bf955d7a/hyundai_kia_connect_api/KiaUvoApiCA.py#L583-L621

@badnbusy
Copy link
Author

badnbusy commented Jan 8, 2025

Ok, got it via HTTP toolkit.

Here is the call which enables climate control (in particular seat heating/cooling) on the new EU models. Mine is a Kona 2024 Electric, UK - Right Hand Drive

Note the URL is also different, there is an additional "ccs2" in the URL, and it's also v2 spa: /api/v2/spa/vehicles/<vehicle_id>/ccs2/control/temperature

{
  "drvSeatLoc": "R",
  "tempUnit": "C",
  "seatClimateInfo": {
    "rrSeatClimateState": 6,
    "drvSeatClimateState": 6,
    "psgSeatClimateState": 6,
    "rlSeatClimateState": 6
  },
  "sideRearMirrorHeating": 1,
  "hvacTempType": 1,
  "hvacTemp": "22.0",
  "command": "start",
  "windshieldFrontDefogState": true,
  "ignitionDuration": 5,
  "strgWhlHeating": 1
}

So from this I can deduce that the seat heating levels are:

Seat heating/cooling
2 = Off
3 = Cooling Level 1
4 = Cooling Level 2
5 = Cooling Level 3
6 = Heating Level 1
7 = Heating Level 2
8 = Heating Level 3

"seatClimateInfo": {
    "rrSeatClimateState": 6,
    "drvSeatClimateState": 6,
    "psgSeatClimateState": 6,
    "rlSeatClimateState": 6
  }

Defrost front windscreen
true = On
false = Off

"windshieldFrontDefogState": true

Rear and side window heating
0 = Off
1 = On

`"sideRearMirrorHeating": 1

Steering wheel heating
0 = Off
1 = Level 1
2 = Level 2

"strgWhlHeating": 1

Duration
in minutes

ignitionDuration: 5

@badnbusy
Copy link
Author

badnbusy commented Jan 8, 2025

What's the best way for this to be added in to support newer EU models? I can supply all the API json calls required...

@cdnninja
Copy link
Collaborator

cdnninja commented Jan 8, 2025

Two options. One is I create a release with my best guess on this and you test it out. This approach may have lots of back and forth.

Option two is I help you get a basic dev environment setup. I give you the exact code changes as my best guess and you can tinker and test. If tech savvy this will most likely make sense for you.

@badnbusy
Copy link
Author

badnbusy commented Jan 8, 2025

More than happy to take option 2, test your examples and then fix/push back.

How will you handle the fact that some newer cars use mainly the ccs2 endpoints and different payloads than the current/older cars? Some kind of toggle in the UI that allows the owner to select their model/year?

@cdnninja
Copy link
Collaborator

cdnninja commented Jan 9, 2025

I'll start with logic on if the car supports ccs2. We do that for other commands already. If that is adequate leave to that. If we have other issues can add checks for years or model checks.

I'll get you more detailed step by step but to start download GitHub desktop. As well as vscode. Vscode is optional but makes things easier. Any text editor will do. Both those items are free.

Once downloaded clone Hyundai Kia connect the api repo not this one. You will also need python installed but probably already is.

I'm assuming you are on windows.

@cdnninja
Copy link
Collaborator

cdnninja commented Jan 9, 2025

Alright within github desktop:

  1. Click add > clone repo
  2. URL tab enter: https://github.com/Hyundai-Kia-Connect/hyundai_kia_connect_api set the path you want to store this - take note of it.
  3. Under current branch up top you will be able to select the branches I build for this. Select EUSeats.
  4. You can edit the files by click repository up top and either open the folder structure or open in visual studio code.

To "Run" this code you are going to want to make a text file named something like hyundaitest.py and open it in a text editor of your choice. VS code being the easiest since it can run the python code.

Past this into it, editing the path to the repo you downloaded.

from pathlib import Path
import logging
import sys
import os

path_root = r"C:\Users\PATH TO GitHub\main\hyundai_kia_connect_api"
sys.path.append(str(path_root))
from hyundai_kia_connect_api import *
from hyundai_kia_connect_api.exceptions import *

logging.basicConfig(stream=sys.stdout, level=logging.DEBUG, format='%(asctime)s %(name)s %(levelname)s:%(message)s')
logger = logging.getLogger(__name__)

climateOptions = ClimateRequestOptions(set_temp = 20, duration = 10, defrost = True, climate = True, heating = 1)
print(climateOptions)
vm.start_climate(vm.vehicles[0].id, climateOptions)

Once you are to that point we can expand the testing. Once we are closer you can expand "ClimateRequestOptions" to pass the other values you pass in the seats or other settings. Think of that as your YAML automation - it is exactly what home assistant is doing.
Here is a link to what we can contain in our climate request: https://github.com/Hyundai-Kia-Connect/hyundai_kia_connect_api/blob/3a672ef3caa24a7908e33326f2c5d801bf955d7a/hyundai_kia_connect_api/ApiImpl.py#L27-L36

Here is what we think those values are. They seem different by car though: https://github.com/Hyundai-Kia-Connect/hyundai_kia_connect_api/blob/3a672ef3caa24a7908e33326f2c5d801bf955d7a/hyundai_kia_connect_api/const.py#L44-L65

Let me know if that is enough to get you setup to test the code directly. I created a branch, lets move to comments to the pull request for it here: Hyundai-Kia-Connect/hyundai_kia_connect_api#705 So we can comment on specific code.

@badnbusy
Copy link
Author

badnbusy commented Jan 9, 2025

Thanks @cdnninja, got it all up and running giving me the ability to test/commit changes.

I've now adapted the code to pass/accept variables rather than the hardcoded json. It's working 👍

I had to fork the repo in order to push my changes up, so please see badnbusy/hyundai_kia_connect_api@d20d830

One question I do have is that for the CCS2 start_climate call, the "defrost" is now an integer not a boolean in following data class

@dataclass
class ClimateRequestOptions:
     ...
    defrost: bool = None
     ...

I am still sending True/False but then converting it to int() when it forms the payload, is that okay? It seems to work fine when either not setting it, or setting to 0/1.

Also, in the ccs2 payload for climate, there is a param called drvSeatLoc which in the UK is R but the rest of EU probably L. I think this might impact the drvSeatClimateState and psgSeatClimateState respectively, so we might need a toggle in the Home Assistant UI to set RHD/LHD and modify the code accordingly?

Please let me know your initial thoughts.

I will now move on to getting the other car features working, like lock/unlock as these currently don't work either and require ccs2.

*** edit ***

Two further commits... (new branch called hyundai-ccs2-eu)

support lock/unlock:
badnbusy/hyundai_kia_connect_api@8294884

support start/stop charge:
badnbusy/hyundai_kia_connect_api@5833e7b

Thanks

@CosAdrPala
Copy link

Can we set:
image
I want to have the hours set dynamically by HA but I can't find them.

It uses the EU version and I can only see these controls:
image

@badnbusy
Copy link
Author

badnbusy commented Jan 13, 2025

@cdnninja The PR you opened for this now appears to be closed without the code from my forked branch, any ideas when it will be merged to hyundai_kia_connect_api repo?

https://github.com/badnbusy/hyundai_kia_connect_api/commits/EUSeats

Thanks!

@Dinges28
Copy link

Dinges28 commented Jan 15, 2025

@steps56

#offtopic... can you share your dashboard? it looks really good

@ShinyMcGlint
Copy link

This is super timely - I'm happy to help with any testing, UK Ioniq 5N

@steps56
Copy link

steps56 commented Jan 16, 2025

@steps56

#offtopic... can you share your dashboard? it looks really good

Sorry, I offered already some yaml, but too much personal data in the dasboard to share.
But template to find at the web as I did 😎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants