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

Ioniq 5 "Unknown Error" when scheduling charge #971

Open
rebuilder opened this issue Nov 12, 2024 · 12 comments
Open

Ioniq 5 "Unknown Error" when scheduling charge #971

rebuilder opened this issue Nov 12, 2024 · 12 comments

Comments

@rebuilder
Copy link

Region and Brand of car
EU Ioniq 5
Version of the integration
2.29.0
Describe the bug
I'm trying to schedule charging using the functionality newly provided byt the integration. To do so , I'm running the "Kia Uvo / Hyundai Bluelink Schedule charging and climate" action from developer tools in HA.

I've enabled the target vehicle (tried without as well), scheduled charging, first departure and time, the off-peak start and end-times of course, as well as tried with climate control set on. In short, I've tried with a wide variety of options toggled on and off.

All that happens is I get the error "Failed to perform the action kia_uvo.schedule_charging_and_climate. Unknown error".

Does anyone have success using this feature?

@asychow
Copy link
Contributor

asychow commented Nov 12, 2024

Tested on my end that if no data is supplied, schedules are turned off (although you may get an error in HA log saying 'action not found', but the request went through). Here is the yaml I used

action: kia_uvo.schedule_charging_and_climate
data: {}

Can you post the yaml you tried to run (hide the device id)? I may be able to point out anything that is off.

@rebuilder
Copy link
Author

rebuilder commented Nov 12, 2024

I tried the yaml with no data as you showed, still got the same error and no change in the schedules on the car's end.

Here's an example of what I tried to run:


action: kia_uvo.schedule_charging_and_climate
data:
  charging_enabled: true
  first_departure_enabled: true
  first_departure_days:
    - "0"
  first_departure_time: "07:00:00"
  off_peak_start_time: "01:00:00"
  off_peak_end_time: "02:00:00"
  off_peak_charge_only_enabled: true
  device_id: [censored]

@rebuilder
Copy link
Author

I tried running the close charge port action, also got an unknown error. My automations that start charging, climate etc continue to work though. Not sure what's going on now.

@asychow
Copy link
Contributor

asychow commented Nov 12, 2024

Your script works on my vehicle, therefore I guess your issue is model specific ...

It is worth noting that actions which work on your vehicle use
SPA_API_URL and self._get_authenticated_headers

Actions which don't work use
SPA_API_URL_V2 and self._get_control_headers

Would you be able to capture what BL sends for the not-working-actions?

@rebuilder
Copy link
Author

I'd be happy to try capturing, but I don't know how :D Is there a guide somewhere?

@asychow
Copy link
Contributor

asychow commented Nov 13, 2024

I had some luck with proxyman, but there is plenty of alternatives

@b3uk
Copy link

b3uk commented Nov 16, 2024

I'm also getting an "Unknown error" when running any code using this service from the developer tools, eg

action: kia_uvo.schedule_charging_and_climate
data: {}

If I write a script to run the service, I get a slightly different "controlToken" error, shown here in the script trace:

Executed: 16 November 2024 at 20:30:30
Error: 'controlToken'
Result:
params:
  domain: kia_uvo
  service: schedule_charging_and_climate
  service_data:
    charging_enabled: true
    first_departure_enabled: true
    first_departure_days:
      - '0'
    off_peak_start_time: '19:40:00'
    off_peak_end_time: '19:50:00'
    off_peak_charge_only_enabled: true
    climate_enabled: true
    temperature: 21
    temperature_unit: '0'
    defrost: true
    device_id: [hidden]
    first_departure_time: '07:30:00'
    second_departure_enabled: true
    second_departure_days:
      - '0'
    second_departure_time: '16:00:00'
  target: {}
running_script: false

Here are my details:

Region and Brand of car
EU Kona EV (21)
Version of the integration
2.29.0
Describe the bug
Trying to run the schedule_charging_and_climate service always fails.

And the details from my log:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 28, in _handle_async_response
    await func(hass, connection, msg)
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 816, in handle_execute_script
    script_result = await script_obj.async_run(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1801, in async_run
    return await asyncio.shield(create_eager_task(run.async_run()))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 464, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 528, in _async_step
    self._handle_exception(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 558, in _handle_exception
    raise exception
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 526, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 764, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 727, in _async_run_long_action
    return await long_task
           ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2802, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2845, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/kia_uvo/services.py", line 229, in async_handle_schedule_charging_and_climate
    await coordinator.async_schedule_charging_and_climate(
  File "/config/custom_components/kia_uvo/coordinator.py", line 281, in async_schedule_charging_and_climate
    action_id = await self.hass.async_add_executor_job(
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/hyundai_kia_connect_api/VehicleManager.py", line 262, in schedule_charging_and_climate
    return self.api.schedule_charging_and_climate(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/hyundai_kia_connect_api/KiaUvoApiEU.py", line 1432, in schedule_charging_and_climate
    url, json=payload, headers=self._get_control_headers(token, vehicle)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/hyundai_kia_connect_api/KiaUvoApiEU.py", line 235, in _get_control_headers
    control_token, _ = self._get_control_token(token)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/hyundai_kia_connect_api/KiaUvoApiEU.py", line 1699, in _get_control_token
    control_token = "Bearer " + response["controlToken"]
                                ~~~~~~~~^^^^^^^^^^^^^^^^
KeyError: 'controlToken'

@cdnninja
Copy link
Collaborator

Does it work in the native app?

@cdnninja
Copy link
Collaborator

I think this is based on the new vs old APIs. Maybe year based. Could those with the error post the year and model of the car? Also interested to hear the same for those that it works for.

@b3uk
Copy link

b3uk commented Nov 16, 2024

Does it work in the native app?

Yes scheduling works in the Hyundai app.

And I made a mistake before - it’s a 2020 model Kona that I’ve got.

@rebuilder
Copy link
Author

I have an MY 2022 Ioniq 5

@rebuilder
Copy link
Author

rebuilder commented Nov 25, 2024

I was able to capture the BL POST request for setting the charge time, here’s the JSON part of it

Content-Type: application/json; charset=UTF-8

{
  "reservFlag": 1,
  "offPeakPowerInfo": {
    "offPeakPowerFlag": 2,
    "offPeakPowerTime1": {
      "endtime": {
        "timeSection": 0,
        "time": "0600"
      },
      "starttime": {
        "timeSection": 0,
        "time": "0110"
      }
    }
  },
  "reservChargeInfo1": {
    "reservChargeSet": true,
    "reservFatcSet": {
      "airTemp": {
        "value": "24.0",
        "hvacTempType": 1,
        "unit": 0
      },
      "airCtrl": 0,
      "heating1": 0,
      "defrost": true
    },
    "reservInfo": {
      "day": [
0,
1,
2,
3,
4,
5,
6
      ],
      "time": {
        "timeSection": 0,
        "time": "0700"
      }
    }
  },
  "reservChargeInfo2": {
    "reservChargeSet": false,
    "reservInfo": {
      "day": [
5
      ],
      "time": {
        "time": "1200",
        "timeSection": 0
      }
    },
    "reservFatcSet": {
      "airCtrl": 0,
      "airTemp": {
        "value": "24.0",
        "hvacTempType": 1,
        "unit": 0
      },
      "heating1": 0,
      "defrost": true
    }
  }
}

I can also provide the test of the request data If you need it, it’s not quite clear to me how much of that is safe to post publicly.

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

4 participants