Tibber - Set SoC of an "non integrated" EV in Home Assistant

I use Tibber as power company/buy/sell electricity from.
I also have an MG4 EV. The MG4 does not have an “Tibber Integration”, which means that every time I want to charge my MG4 at home, with my “Tibber Integrated” EV charger (Easee), I need to manually enter the SoC (state of charge) of the MG4 into the Tibber app.

I would much rather have HA do that form me :smiley:

I can read relevant data from MG/SAIC using the integration;

And I have the Home Assistant Tibber Integration installed.

- Now, do we have any geniuses in here that can poke around in the Tibber API and find out if I can change the SoC of a specified EV (we have two).

1 Like

Use evcc.io

Tibber is controlling my Easee EV charger. So, I kind of need to get the SoC value into Tibber.
But evcc looks super cool!

I have the same issue with my 2016 Nissan Leaf.
@Goethe14 How would evcc.io help in this situation?

1 Like

evcc was of no help for me too.

The following works for me. Please note that this is not the official API and you should behave with care! It may break at any point without notice and cannot expect any help.

configuration.yaml:

rest_command:
  tibber_login:
    url: "https://app.tibber.com/login.credentials"
    method: POST
    content_type: application/json
    payload: '{"email": "{{ email }}", "password": "{{ password }}"}'

  tibber_set_vehicle:
    url: "https://app.tibber.com/v4/gql"
    method: POST
    content_type: application/json
    headers:
      Authorization: "Bearer {{ token }}"
    payload: >
      {"query":"mutation setVehicleSettings { me { setVehicleSettings(id:\"{{ vehicle_id }}\", homeId:\"{{ home_id }}\", settings:[{key:\"offline.vehicle.batteryLevel\", value: {{ value }} }]) { id } } }"}

scripts.yaml

push_to_tibber:
  alias: "Push value to Tibber"
  fields:
    value: {}
    vehicle_id: {}
    home_id: {}
  sequence:
    # Step 1: Login to Tibber API
    - service: rest_command.tibber_login
      data:
        email: !secret tibber_email
        password: !secret tibber_password
      response_variable: tibber_auth

    # Step 2: Use returned token to send mutation
    - service: rest_command.tibber_set_vehicle
      data:
        token: "{{ tibber_auth.content.token }}"
        vehicle_id: "{{ vehicle_id }}"
        home_id: "{{ home_id }}"
        value: "{{ value }}"
      response_variable: tibber_set # optional, for debugging only

automations.yaml (i configured it via the UI, hence the numeric id

- id: '1755891222498'
  alias: Kia Ladestand zu Tibber
  description: ''
  triggers:
  - entity_id: sensor.kia_soc
    trigger: state
  conditions:
  - condition: not
    conditions:
    - condition: state
      entity_id: sensor.kia_soc
      state: unavailable
  - condition: not
    conditions:
    - condition: state
      entity_id: sensor.kia_soc
      state: unknown
  actions:
  - data:
      value: '{{ states(''sensor.kia_soc'') }}'
      vehicle_id: 'VEHICLE-UUID'
      home_id: 'HOME-UUID'
    action: script.push_to_tibber
3 Likes

M8!
I have to try this out!!
This is like the exact thing I have asked Tibber devs to implement and document in their API Explorer

Thanks @jks!

Here’s a slightly modified version (homeId is no longer needed it seems) that also allows you to easily discover the right IDs:

configuration.yaml:

# Tibber app API
rest_command:
  tibber_login:
    url: "https://app.tibber.com/login.credentials"
    method: POST
    content_type: application/json
    payload: '{"email": "{{ email }}", "password": "{{ password }}"}'

  tibber_get_ids:
    url: "https://app.tibber.com/v4/gql"
    method: POST
    content_type: "application/json"
    headers:
      Authorization: "Bearer {{ token }}"
    payload: '{"query": "{ me { homes { id electricVehicles { id name } } } }"}'

  tibber_set_vehicle:
    url: "https://app.tibber.com/v4/gql"
    method: POST
    content_type: application/json
    headers:
      Authorization: "Bearer {{ token }}"
    payload: >
      {"query":"mutation setVehicleSettings { me { setVehicleSettings(id:\"{{ vehicle_id }}\", settings:[{key:\"offline.vehicle.batteryLevel\", value: {{ value }} }]) { id } } }"}

scripts.yaml:

push_soc_to_tibber:
  alias: "Push SoC to Tibber"
  fields:
    value:
      description: "The SoC percentage"
      example: "80"
    vehicle_id:
      description: "The UUID of your vehicle in Tibber"
      example: "12345678-abcd-1234-abcd-1234567890ab"
  sequence:
    # Step 1: Login to Tibber API
    - action: rest_command.tibber_login
      data:
        email: !secret tibber_email
        password: !secret tibber_password
      response_variable: tibber_auth

    # Step 2: Use returned token to send mutation
    - action: rest_command.tibber_set_vehicle
      data:
        token: "{{ tibber_auth.content.token }}"
        vehicle_id: "{{ vehicle_id }}"
        value: "{{ value }}"
      response_variable: tibber_set
discover_tibber_ids:
  alias: "Discover Tibber Home and Vehicle IDs"
  sequence:
    # 1. Login
    - action: rest_command.tibber_login
      data:
        email: !secret tibber_email
        password: !secret tibber_password
      response_variable: login_res

    # 2. Get IDs
    - action: rest_command.tibber_get_ids
      data:
        token: "{{ login_res['content']['token'] }}"
      response_variable: id_res

    # 3. Create a Notification in the HA Sidebar
    - action: notify.persistent_notification
      data:
        title: "Tibber ID Discovery"
        message: >
          {% set homes = id_res['content']['data']['me']['homes'] %}
          {% for home in homes %}
            **Home ID:** `{{ home.id }}`  
            **Vehicles:**
            {% for car in home.electricVehicles %}
              - {{ car.name }}: `{{ car.id }}`
            {% endfor %}
            ---
          {% endfor %}

There is a dedicated integration for this as well now: GitHub - Elibart-home/tibber_soc_updater: Deze custom component voor Home Assistant maakt directe verbinding met de Tibber GraphAPI mogelijk, specifiek gericht op het uitlezen en besturen van elektrische voertuigen. De integratie gebruikt directe authenticatie met je Tibber account, onafhankelijk van de officiële Tibber integratie.