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

fix: set_climatisation #450 #492

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft

fix: set_climatisation #450 #492

wants to merge 3 commits into from

Conversation

Kolbi
Copy link
Contributor

@Kolbi Kolbi commented Nov 12, 2024

@Kolbi Kolbi changed the title set_climatisation #450 fix: set_climatisation #450 Nov 12, 2024
@pergolafabio
Copy link

i was testing the start_climate_control with my Q4
do you know why there is a calculation for the temp_c ?
i inspected the json, and it was sending a temp like 25xx , resulting in a bad request...
maybe this was needed for the old API? i commented it out for me, and below works
again , hardcoded, proably doesnt work for other regions for users with Q4

      async def start_climate_control(self, vin: str, temp_f: int, temp_c: int, glass_heating: bool, seat_fl: bool, seat_fr: bool, seat_rl: bool, seat_rr: bool):

        target_temperature = None
        if temp_f is not None:
            target_temperature = int(((temp_f - 32) * (5 / 9)) * 10 + 2731)
        elif temp_c is not None:
            #target_temperature = int(temp_c * 10 + 2731)
            target_temperature = int(temp_c)

        # Default Temp
        target_temperature = target_temperature or 23
        data = { 
            "targetTemperature" : target_temperature, 
            "targetTemperatureUnit": "celsius", 
            "climatisationWithoutExternalPower": True, 
            "climatizationAtUnlock": False, 
            "windowHeatingEnabled": glass_heating, 
            "zoneFrontLeftEnabled": seat_fl, 
            "zoneFrontRightEnabled": seat_fr, 
            "zoneRearLeftEnabled": False, 
            "zoneRearRightEnabled": False 
        }
        data = json.dumps(data)
        headers = {
            "Authorization": "Bearer " + self._bearer_token_json["access_token"]
        }
        res = await self._api.request(
            "POST",
            "https://emea.bff.cariad.digital/vehicle/v1/vehicles/{vin}/climatisation/start".format(
                vin=vin.upper(),
            ),
            headers=headers,
            data=data,
        )

@coreywillwhat
Copy link
Contributor

Q4 data structure is different than all the older vehicles, and as you know, the EU is different than NA region endpoints.

I dont know if the Q4 data structure is going to be the new standard or if only for electric vehicles or some other subset of vehicles. A while back i was working on some logic to use the correct logic based on the vehicle, or even having the user select an option under integration options.

Your Q4 uses Celsius in the new data structure. Legacy data structure used 'deca-kelvin'. Why they used that in the past, i have no idea.

My time is so limited these days, I'm really not sure I'll have time to work on this until the new year, unfortunately.
I could probably get it working pretty quickly for NA/Legacy Data structure, but finding even an afternoon to work on it is hard at the moment.

Making it work universally and smart enough to do it automatically is the real challenge. I was also working on integration options that the user would select to try different data structures or endpoints. Ultimately that may be the best path forward, but again, last time i worked on it, they changed everything again so I lost the progress.

Happy to answer any questions you have if any others.

@pergolafabio
Copy link

ok, that makes sence with the temparature
but take your time, no hurry, i have a working solution now, i can turn on/off climate not from HA

@Kolbi Kolbi marked this pull request as draft November 20, 2024 12:04
@niilorm
Copy link

niilorm commented Nov 22, 2024

i was testing the start_climate_control with my Q4 do you know why there is a calculation for the temp_c ? i inspected the json, and it was sending a temp like 25xx , resulting in a bad request... maybe this was needed for the old API? i commented it out for me, and below works again , hardcoded, proably doesnt work for other regions for users with Q4
...

After some quick and rough testing can confirm this to be working on A3 TFSIe in EU. Will need to be fine tuned if eg. the status needs to be queried. (See #450)

Extended the hotfix to enable climatisation to be interrupted as well via Execute Vehicle Action. Not pretty as made at 5 AM but it works nevertheless.

audi_services.py

async def set_climatisation(self, vin: str, start: bool):
        if start:
            await self.start_climate_control(vin, None, 22, False, False, False, False, False)
        else:

            data = {"": ""}
            data = json.dumps(data)
            headers = {
                "Authorization": "Bearer " + self._bearer_token_json["access_token"]
            }
            res = await self._api.request(
                "POST",
                "https://emea.bff.cariad.digital/vehicle/v1/vehicles/{vin}/climatisation/stop".format(
                    vin=vin.upper(),
                ),
                headers=headers,
                data=data,
            )

@pergolafabio
Copy link

Correct, the status is indeed missing, I removed that part , it needs to be included as well, if the status is successful, it wil probably update the climate sensor as well? Now we need to wait for the next 15 min poll interval to actually see if the climate is turned on?

@niilorm
Copy link

niilorm commented Nov 22, 2024

Correct, the status is indeed missing, I removed that part , it needs to be included as well, if the status is successful, it wil probably update the climate sensor as well? Now we need to wait for the next 15 min poll interval to actually see if the climate is turned on?

Yes, I believe that can be and should be implemented directly via a request to https://emea.bff.cariad.digital/vehicle/v1/vehicles/{VIN}/pendingrequests.

However, I don't see it as something really urgent as the action can be assumed successful in most cases.

Will need to be addressed when fixing the API calls.

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

Successfully merging this pull request may close these issues.

4 participants