Tibber - Sensor for power consumption for electric car charging

I copied the ‘rest’ template code above into my sensors.yaml and get numerous “duplicate key” errors

What formatting should I be using given this is not in configuration.yaml but a separate file linked to by

sensor: !include sensors.yaml

I assume this is a damn YAML thing where the use of spaces or the - symbol is all important

Right I changed it too:

###############################
#                             #
#          SENSORS            #
#                             #
###############################
- platform: rest
  name: Polestar
  resource: https://app.tibber.com/login.credentials
  scan_interval: 21600 #6h
  timeout: 60
  method: POST
  payload: !secret tibber
  headers:
    Content-Type: "application/json"
- platform: template
  sensors:
    tibber_access_token:
      friendly_name: "Tibber API Access Token"
      value_template: "Bearer {{ value_json.token }}"
- platform: rest
  resource: https://app.tibber.com/v4/gql
  method: POST
  payload: '{ "query": "{ me { homes { electricVehicles { lastSeen battery { percent }}}}}"}'
  headers:
    Authorization: "{{ states.sensor.tibber_access_token.state }}"
    Content-Type: "application/json"
  scan_interval: 600 #10m
- platform: template
  sensors:
    polestar_soc:
      friendly_name: "Polestar 2 SOC"
      unique_id: polestar2_soc
      value_template: "{{ value_json.data.me.homes[0].electricVehicles[0].battery.percent | int }}"
      unit_of_measurement: "%"
      device_class: battery
    polestar_range:
      friendly_name: "Polestar 2 Range"
      unique_id: polestar2_range
      value_template: "{{ (value_json.data.me.homes[0].electricVehicles[0].battery.percent / 100 * 487) | int }}"
      unit_of_measurement: "km"
      device_class: battery
    polestar_last_update: 
      friendly_name: "Polestar 2 SOC Last Update"
      unique_id: polestar2_soc_lastupdate
      value_template: "{{ value_json.data.me.homes[0].electricVehicles[0].lastSeen }}"

Does this seem OK

The payload also looks incorrect, shouldn;t it be:

tibber: '{"email":"EMAIL","password":"PASSWORD"}'

noting the extra quote after the email address, and I am assuming that the uppercase values are replaced with actual account values?

OMG! This just worked out of the box. Now I have Polestar data. Thanks so much.

1 Like

I used the changed version and copied it to sensors.yaml.
Copied the tibber credentials to secrets.yaml.
But it does not work for me. The sensors are the and but they say unavailable.

Any suggestiosn to what I may have done wrong?

both combinations, when even actually the same, are not working for me,
any other tip?

Hi Christian,
did you find out what was your issue?

best regards.

Screenshot your config files and blur the password, so i can help.

here you go, and thx in advance.

I’ve tested the scriped version and it works, but would prefer to get the sensors.yaml version to run.

Its a config package and not something for the sensors.yaml…

1 Like

I see a lot of confusion around sensors.yaml. May I just state something bold? Every user should implement packages in their configuration. I think it is a mistake that a packages setup is not part of the standard configuration provided with HA.

homeassistant:
  packages: !include_dir_named packages

Some could see this as personal preference but it really isn’t. Packages can be used to have one sensors heavy file, one automations centered file… if the user wanted to.

@lwde thanks for your snippet! This makes everything so much easier. I’m hopefully soon in a position to test and give feedback.

2 Likes

thank you…
took a while till the “sensors” updated themselves… but it works…
thank you also to bringing up the “packages” thats totally new to me… something new to figure out in HA.

BR and greetings

Thanks for sharing, works like a charm. I changed device_class to distance for polestar2_range.

But that value isn’t really helpful, anyways. Where does the number 487 for the calculation SoC%/100*487 come from?

I really hope Polestar is listening and finally opens up their API, at least a little bit for the most basic information…

I added the device class now too.

487km is the WLTP range for the 2020 LR AWD version.

just integrated my Polestar in conjunction with the tibber app into HA and it works!
I now would like to add a second car, is this possible?
if it is, what and how should I modify in the yaml files?

I guess as follows?

value_template: "{{ value_json.data.me.homes[0].electricVehicles[1].lastSeen | as_datetime | as_local }}"

edit: never mind, it worked :slight_smile:

This Tibber solution looks great and simple to implement, except it hasn’t worked for me, as when I try and add my Polestar EV as a Power-up in the Tibber app, the app just hangs when I try and login using my Polestar ID. Seems that the service is unreachable!? I’m not sure whether it’s because I’m in New Zealand (Tibber doesn’t exist here), or because my Polestar is leased (although I have a Polestar ID and can log in independently of Tibber and have the Polestar app etc.). Any ideas or wise insights appreciated :slight_smile:

Hi @KiwiAndy I am also a kiwi and got Tibber working with my Polestar 2 by setting my Tibber account to be in France. Then about a month ago it stopped, it looks like something as happened to block us kiwi’s using Tibber. maybe they ahve geo-locked access?

Hi @Simon_Bunn. That confirms it thanks. I assume Tibber has blocked access to the NZ Polestar VIN database or similar. You may be able to use the customer integration in this post though:
Integration of Polestar 2 - #165 by leeyuentuen.

Unfortunately, I can not as it requires your car to be identified and owned by you under your Polestar ID, which being a lease car mine is not.

HI,

sorry for the late reply. Did you get it to work yourself?
I did. The problem was I had not realized I had to put it in a package to get it to work in my setup.

So, in configuration.yaml I needed to add

homeassistant:
packages:
tibber_polestar_2: !include tibber_polestar_2.yaml

And then enter the code into in my caser the file tibbe_polestar_2.yaml

Works since then.
But I do not use it anymore, as now there is a possibility with API thru Polestar which use instead.