Integration of Polestar 2

I would like to contribute on top of already excellent post by @scriven33

Those are some great modifications. Thanks for updating my work - mine was very much early stages and needed cleaning up, as I knew it could be done better.

I prefer the sensor for the Charge Port Connected, as it states True, which I think is more true to life.
Your modifications also allowed me to remove some of the additional templates I created as well.
Are you on the International Polestar Forum? If so, you might want to post your mods on there as well.

Not an active user there.

Feel free to link from there to here :wink: (thus avoiding duplication)

I just want to leave this here:

It seems some heros have developed exactly what we are all looking for, but for the Volvo environment. I think it would just be a matter of branching this to Polestar and we’re all set (with a rock solid integration not relying on 3rd party integrations and intermediary apps).

Perhaps someone here could port it? Alternatively help me petition the creator to help branch their creation to the Polestar environment!

Cheers
//S

AFAIK we do not share the same backend

Do you have access to your car information through a webpage ? Like volvo’s do ?

Clearly there is an API since companies like Tibber can develop functionalities towards it (Polestar Smartladdning – Ladda din Polestar smart ⚡️ Tibber), but it’s likely not public.

The only access I have, as you well know, is through the Polestar App.

edit: my thought was the Polestar API likely shares a similar internal structure to the VCC API.

If you just need the SoC, checkout here

2 Likes

A new version of Car Stats Viewer has been released, although it isn’t on all of the tracks. New functionality in the API, but the old one works as before.

Hi @scriven33
I am using your templates and stuff in Home Assistant. They mostly work great but I don’t seem to get any Lat Long or Altitude data. I’ve checked ABRP is working and the blue connection icon shows in CSV. Any ideas?

Have you enabled the option in CSV in the car to send that information? I am sure it is a toggle (not with the car right now).

Seeing this makes me sad that Polestar doesn’t offer the same things for us. The platforms are the same but the backends are different, so this wont work for us. Look at all the things they get directly with the Volvo API:

VEHICLES_URL = “https://api.volvocars.com/connected-vehicle/v1/vehicles
VEHICLE_DETAILS_URL = “https://api.volvocars.com/connected-vehicle/v1/vehicles/{0}
WINDOWS_STATE_URL = “https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/windows
CLIMATE_START_URL = “https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/commands/climatization-start
CLIMATE_STOP_URL = “https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/commands/climatization-stop
LOCK_STATE_URL = “https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/doors
CAR_LOCK_URL = “https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/commands/lock
CAR_UNLOCK_URL = “https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/commands/unlock
RECHARGE_STATE_URL = “https://api.volvocars.com/energy/v1/vehicles/{0}/recharge-status
ODOMETER_STATE_URL = “https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/odometer
LOCATION_STATE_URL = “https://api.volvocars.com/location/v1/vehicles/{0}/location
TYRE_STATE_URL = “https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/tyres
ENGINE_STATE_URL = “https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/engine-status
BATTERY_CHARGE_STATE_URL = “https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/battery-charge-level
FUEL_STATE_URL = “https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/fuel
STATISTICS_URL = “https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/statistics
ENGINE_DIAGNOSTICS_URL = “https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/engine
VEHICLE_DIAGNOSTICS_URL = “https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/diagnostics

I’m jealous.

I’m going to try to host my own test version of CSV and then push to HA, guess that’s our best bet today.

This works pretty well. I have added a Charger Status indicator to my EV page, and I’m calculating the estimated SOC based on how many kWh were added to the starting battery level and divided by the battery capacity.

At home, when plugging in the charger before locking the car, the data gets sent to HA properly. When done charging, unlocking the car will get the information sent to HA.

The left battery bar is the estimated SOC, the right bar is the actual data coming from the car. I took the screenshot after going out to the post office, but they did match when the car first reported its level back.

2 Likes

I tried this setup via tibber (free account without energy contract), works pretty good!

Similar solution via bash script has already been mentioned above:

1 Like

How does Tibber obtain the information? Does it have a connection to the Polestar API?

Yes, tibber has access to a non public API for the Polestar account :confused:
You have to pair the polestar account in the tibber app.

Hmm. I’ll have to give this a go. Thanks

Hi,

I will get a polestar 2 this week, I don’t have any home assistant configured, but I’ve got my own rpis working with some stuff… This integration for the moment only shows data of the polestar right? I can also publish this into some grafana/prometheus stack, right?

Other point, this week, I don’t know how, in duckduckgo, I found this link:
https://api.polestar.com/

I don’t know if you know it, but… feels like we only need to know the endpoints…

Thanks for everything,
D.

The API location is well known. If it was that easy it would have been found by now. A lot of people, particularly in Europe want car information.
The only way to connect are outlined in this thread and on the German and English fan forums. What you do with the data is up to you.
Realistically, the only open way is via the Tibber method, as while CSV is very good, it is restricted on numbers because of the workarounds to get it I. The car.

for people who need more data from tibber

- resource: https://app.tibber.com/v4/gql
    method: POST
    payload: '{"query": "{ me { homes { electricVehicles {id name shortName lastSeen lastSeenText isAlive hasNoSmartChargingCapability imgUrl schedule {isEnabled isSuspended localTimeTo minBatteryLevel} batteryText chargingText consumptionText consumptionUnitText energyCostUnitText chargeRightAwayButton chargeRightAwayAlert {imgUrl title description okText cancelText}backgroundStyle energyDealCallToAction{text url redirectUrlStartsWith link action enabled} settingsScreen{settings {key value valueType valueIsArray isReadOnly inputOptions{type title description pickerOptions {values postFix} rangeOptions{max min step defaultValue displayText displayTextPlural} selectOptions {value title description imgUrl iconName isRecommendedOption} textFieldOptions{imgUrl format placeholder} timeOptions{doNotSetATimeText}}} settingsLayout{uid type title description valueText imgUrl iconName isUpdated isEnabled callToAction {text url redirectUrlStartsWith link action enabled} childItems{uid type title description valueText imgUrl iconName isUpdated isEnabled callToAction {text url redirectUrlStartsWith link action enabled} settingKey settingKeyForIsHidden} settingKey settingKeyForIsHidden}} settingsButtonText settingsButton  {text url redirectUrlStartsWith link action enabled}enterPincode message {id title description style iconName iconSrc callToAction {text url redirectUrlStartsWith link action enabled} dismissButtonText} scheduleSuspendedText faqUrl battery { percent percentColor isCharging chargeLimit}}}}}"}'
    headers:
      Authorization: "{{ states.sensor.tibber_api_access_token.state }}"
      Content-Type: "application/json"
    scan_interval: 15 #15 sec
    sensor:
      - name: "Polestar 2 SOC"
        unique_id: polestar2_soc
        value_template: "{{ value_json.data.me.homes[0].electricVehicles[0].battery.percent | int }}"
        unit_of_measurement: "%"
        icon: mdi:car-electric
        device_class: battery
      - name: "Polestar 2 Battery Charge Limit"
        unique_id: polestar2_battery_charge_limit
        value_template: "{{ value_json.data.me.homes[0].electricVehicles[0].battery.chargeLimit | int }}"
        unit_of_measurement: "%"
        icon: mdi:car-electric
        device_class: battery
      - name: "Polestar 2 Range"
        unique_id: polestar2_range
        value_template: "{{ (value_json.data.me.homes[0].electricVehicles[0].battery.percent / 100 * 375) | int }}"
        unit_of_measurement: "km"
        icon: mdi:car-electric
        device_class: distance
      - name: "Polestar 2 SOC Last Update"
        unique_id: polestar2_soc_lastupdate
        device_class: timestamp
        value_template: "{{ value_json.data.me.homes[0].electricVehicles[0].lastSeen | as_datetime | as_local }}"
    binary_sensor:
      - name: "Polestar 2 Battery Charging"
        unique_id: polestar2_battery_charging
        value_template: "{{ value_json.data.me.homes[0].electricVehicles[0].battery.isCharging }}"
        icon: mdi:car-electric

you will get the following information (need manual add entities that you need)

{
    "data": {
        "me": {
            "homes": [
                {
                    "electricVehicles": [
                        {
                            "id": "xxxxx",
                            "name": "2023 Polestar 2 Space",
                            "shortName": "Polestar 2",
                            "lastSeen": "2023-11-13T09:19:05.000+00:00",
                            "lastSeenText": "Last updated: 44 minutes ago",
                            "isAlive": true,
                            "hasNoSmartChargingCapability": true,
                            "imgUrl": "https://resources.tibber.com/vehicles/Polestar_Space.png",
                            "schedule": {
                                "isEnabled": true,
                                "isSuspended": false,
                                "localTimeTo": "07:00:00",
                                "minBatteryLevel": null
                            },
                            "batteryText": "72%",
                            "chargingText": "Zaptec or Easee charger required to smart charge this car",
                            "consumptionText": null,
                            "consumptionUnitText": null,
                            "energyCostUnitText": null,
                            "chargeRightAwayButton": null,
                            "chargeRightAwayAlert": null,
                            "backgroundStyle": "default",
                            "energyDealCallToAction": {
                                "text": "Activate energy deal",
                                "url": "https://appviews.tibber.com/energy-deal?homeId=xxxxx",
                                "redirectUrlStartsWith": "https://appviews.tibber.com/done",
                                "link": null,
                                "action": null,
                                "enabled": false
                            },
                            "settingsScreen": {
                                "settings": [],
                                "settingsLayout": [
                                    {
                                        "uid": null,
                                        "type": "header",
                                        "title": "Smart Charging",
                                        "description": "This Power-up doesn't work with your current version of the Tibber app. Please update the app on your phone.",
                                        "valueText": null,
                                        "imgUrl": null,
                                        "iconName": null,
                                        "isUpdated": null,
                                        "isEnabled": null,
                                        "callToAction": null,
                                        "childItems": null,
                                        "settingKey": null,
                                        "settingKeyForIsHidden": null
                                    }
                                ]
                            },
                            "settingsButtonText": "How to smart charge this car?",
                            "settingsButton": {
                                "text": "How to smart charge this car?",
                                "url": "https://support.tibber.com/en/articles/6675026-smart-charge-your-polestar-volvo-recharge-with-tibber",
                                "redirectUrlStartsWith": null,
                                "link": null,
                                "action": null,
                                "enabled": false
                            },
                            "enterPincode": false,
                            "message": null,
                            "scheduleSuspendedText": null,
                            "faqUrl": null,
                            "battery": {
                                "percent": 72,
                                "percentColor": "#FFFFFF",
                                "isCharging": false,
                                "chargeLimit": 100
                            }
                        }
                    ]
                }
            ]
        }
    }
}
1 Like

I’ve just quickly set up an integration via HACS. There might be some issues, but it’s functional for now.

5 Likes

I’ve noticed that the battery charge limit always shows 100% although my car is set to 90% and my partner’s car is limited to 80%.
Haven’t yet tested if this updates to the correct % when charging.
Anyone tested this yet?
I would like to use this info to calculate the remaining charge time.