skodaconnect / homeassistant-skodaconnect

Skoda Connect - A home assistant plugin to add integration with your car
Apache License 2.0
232 stars 28 forks source link

add switch for cable lock #139

Closed Jorn72 closed 1 year ago

Jorn72 commented 2 years ago

First thanks for this awesome component.

I tried to make a automation to unlock the charging port when i am at home (location of my phone). This way i can easily unplug my car when at home. When i am not at home the charging port should be locked. (If i am at a public station i don't want somebody unplug my car). I see that there is a binary sensor in home assistant that shows if the port is locked or unlocked but it doesn't have a switch to lock or unlock it from home assistant. The Skoda app has a option to turn the lock on or off like you will see in the attached picture.

myskoda cable lock

So shortly i would like to see a switch being added to unlock the cable from home assistant. If easier a service call to unlock the port would also work fine.

Thanks again for your work.

Farfar commented 2 years ago

I would need debugs from app to incorporate this, I don't have an Enyaq myself so it might take a while. I'll see if I can get relevant info to fix this in the future.

Jorn72 commented 2 years ago

Hi @Farfar thanks for your reply. I looked in the debug log in Home Assistant but i didn't find anything that might be useful for you. I didn't find anything related to the cable lock or charging in general. I do only get specifications of my car and climate info. I think the Home assistant log is also not interesting for you because you need to see the command for the cable lock instead of the incoming data from: https://api.connect.skoda-auto.cz (correct me if i am wrong)

Is there anything i can help you with this? Can i somehow get a debug log of me switching the cable lock on and off? Or is there something else i can help you with?

ChristophCaina commented 2 years ago

@Jorn72 What @Farfar means is, that he would need some "debug" information from the skoda app directly - to reverse engeneer the cable lock mechanism...

Jorn72 commented 2 years ago

Hi @ChristophCaina thanks for your reply. That's what I thought as well. On android you have a debug folder automatically made by the myskoda app. Sadly it has always been empty for me. It will probably only create a log when the app crashes or if it detects some sort of problem. Is there any way to activate debugging in the myskoda app?

ChristophCaina commented 2 years ago

it's not that kind of "debug" :)

In this case, debug probably means some kind of reverse engeneer - which means, that you probably need to emulate an android device in a development environment and run the app in proper debug modes - and also where you can keep track of the incomming and outgoing traffic from that app.

Unfortunately, I am not really used to this kind of environment and had no time to really start investigating how to set this up... as of now - I can live without this functionallity - although it would be nice to have. Maybe - I can give it a try at some point - but I cannot make any promisses as of now, since I don't know, when I would have the time for this... :-(

sreichholf commented 1 year ago

This is actually already"prepared" in the skodaconnect python lib. At least the actual API call seems to be well-known.

https://github.com/lendy007/skodaconnect/blob/main/skodaconnect/vehicle.py#L366

RamonQu commented 1 year ago

I will try to fetch the calls, however the cable-lock option is currently not available in my app because the car is fully charged (80% in battery care mode). I will update when I get the calls.

For now, here are the GET-calls related to the Cable-lock switch

GET on https://api.connect.skoda-auto.cz/api/v1/charging/{VIN}/status

{
    "plug": {
        "connectionState": "Connected",
        "lockState": "Locked"     # Current lock-state charging plug
    },
    "charging": {
        "state": "ReadyForCharging",
        "remainingToCompleteInSeconds": 0,
        "chargingPowerInWatts": 0.0,
        "chargingRateInKilometersPerHour": 0.0,
        "chargingType": "Invalid",
        "chargeMode": "MANUAL",
        "chargingSettings": "PROFILE"
    },
    "battery": {
        "cruisingRangeElectricInMeters": 335000,
        "stateOfChargeInPercent": 80
    }
}

GET on https://api.connect.skoda-auto.cz/api/v1/charging/{VIN}/settings

{
    "maxChargeCurrentAc": "Maximum",
    "autoUnlockPlugWhenCharged": "Off",  # Current auto unlock-setting charging plug
    "targetStateOfChargeInPercent": 80
}
RamonQu commented 1 year ago

Off-topic: I just found out an additional state is introduced while it's freezing over here. It's look like a state to prevent the battery from becoming too cold.

    "charging": {
        "state": "ChargePurposeReachedAndConservation",
ChristophCaina commented 1 year ago

I think, I have See this once in my Car. It was plugged in to my charger - and charged to 80%.

On the Display it showed: charging Limit reached - and will be hold' (or something Like that).

Means: it will start charging whenever Something will use battery (climatization, etc) and the Car will asure that the battery does stay at 80%

sreichholf commented 1 year ago

Means: it will start charging whenever Something will use battery (climatization, etc) and the Car will asure that the battery does stay at 80%

This is exactly what happens in the App, too and. Once the car is "fully" charged (to the set limit) but stays connected, any kind of consumption will request the required power from the charger. The german android app, for example, will then show the state as "Erhaltung", which translates to "conservation".

According to https://github.com/tillsteinbach/WeConnect-python/blob/27684caaf15546c31456c922eea25be40a58884c/weconnect/elements/charging_status.py#L110 I would also expect another related state to exist for skoda, too:

'chargePurposeReachedAndNotConservationCharging'

RamonQu commented 1 year ago

Hmm, option doesn't seem to be available in my app currently. Not really sure under which conditions it is available. I will try again later.

RamonQu commented 1 year ago

I successfully managed to retrieve the messages between the app and the skoda servers. The cablelock-setting is not available in the MySkoda-app when the Enyaq is located on a stored charging location (e.g. home) in the car. Don't ask me why ;)

autoUnlockPlugWhenCharged has two states:

    "autoUnlockPlugWhenCharged": "Permanent", // Socket is unlocked after charging is complete
    "autoUnlockPlugWhenCharged": “Off”,       // Socket is locked after charging is complete

The current status (AutoUnlockPlugWhenCharged) is retrieved with GET from https://api.connect.skoda-auto.cz/api/v1/charging/{VIN}/settings

{
    "maxChargeCurrentAc": "Maximum",
    "autoUnlockPlugWhenCharged": "Permanent",
    "targetStateOfChargeInPercent": 80
}

Setting is changed with a POST to https://api.connect.skoda-auto.cz/api/v1/charging/operation-requests?vin={VIN}

Request:
{
    "type": "UpdateSettings",
    "chargingSettings": {
        "targetStateOfChargeInPercent": 80,
        "maxChargeCurrentAc": "Maximum",
        "autoUnlockPlugWhenCharged": "Off"
    },
    "deeplink": "skodaconnect:\/\/addon\/RemoteBatteryChargingAddon?vin={VIN}”
}

Response:

{
    "id": "{transactionID}“,
    "status": "InProgress",
    "deeplink": "skodaconnect://addon/RemoteBatteryChargingAddon?vin={VIN}"
}

Status of mutation is retrieved with GET from

https://api.connect.skoda-auto.cz/api/v1/charging/operation-requests/{transactionID}

{
    "id": "{transactionID}",
    "status": "InProgress",
    "deeplink": "skodaconnect://addon/RemoteBatteryChargingAddon?vin={VIN}"
}

Which keeps polling (currently every 6 seconds) until Successful is retrieved in the status. Changing the setting took me 107 seconds this morning.

{
    "id": "[transactionID}",
    "status": "Successful",
    "deeplink": "skodaconnect://addon/RemoteBatteryChargingAddon?vin={VIN}"
}
Farfar commented 1 year ago

Thank you @RamonQu ! Implemented in >=1.1.1 and reported as working.

RamonQu commented 1 year ago

Great! Just updated to 1.1.4 and tried the cable lock switch. Indeed, works like a charm.