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

Feature Request: Add battery level for connected Cars #67

Open
Stroell opened this issue Aug 29, 2023 · 12 comments
Open

Feature Request: Add battery level for connected Cars #67

Stroell opened this issue Aug 29, 2023 · 12 comments
Assignees
Labels
enhancement New feature or request wontfix This will not be worked on

Comments

@Stroell
Copy link

Stroell commented Aug 29, 2023

It would be great if you could get the battery level of a connected Car (via PowerUps) as well.
Background: My car (Polestar) does not have an open API to get statistics, but connecting it to Tibber gives me at least the battery level.
Unfortunately, Tibber does not provide that data via the Developer API, but it is possible via the App API.

Here is some sample Java Script Code that I use currently to get the data from Tibber. It is far from perfect, but a good start.
I don´t know how long the requested tokens are valid. Requesting a new one every time the script runs is probably not necessary .

//Get Token from Tibber
var LoginUri = "https://app.tibber.com/login.credentials";
var output = "1";
var params = {
  "@type": "login",
  "email": "[email protected]",
  'password': '1234'};

//Using the request.post function to send a POST request with JSON data
request.post({
  url: LoginUri,
  json: params
}, function(error, response, body) {
  if (error) {
    console.error(error);
  } else {
    var TokenFromLogin = body.token;
    //console.log(TokenFromLogin);

    //Request Battery Status
    var uri = "https://app.tibber.com/v4/gql?query={me{homes{electricVehicles{lastSeen%0A%20 battery{percent}}}}}";
    var Token = TokenFromLogin;
    //Using the request.post function to send a POST request with a Bearer token
    request.post({
      url: uri,
      headers: {
        'Authorization': 'Bearer ' + Token
      }
    }, function(error, response, body) {
      if (error) {
        console.error(error);
        
      } else {
        //console.log(body);
        output = body;
        setState("0_userdata.0.Geräte.Polestar2.TibberResponse", output);
        
      }
    });
  }
});
@hombach hombach self-assigned this Aug 29, 2023
@hombach hombach added the enhancement New feature or request label Aug 29, 2023
@hombach
Copy link
Owner

hombach commented Aug 29, 2023

First of all: congratulations to drive electric! :)

Best would be to have an Polestar Adapter like there is one for e.g. Tesla .... so, that's a pitty that this isn't possible.

The idea to get this data by a route over the Tibber server is nice.
I'll try your code with my wife's Skoda and we'll see if we could include this in the adapter.

@Stroell
Copy link
Author

Stroell commented Aug 30, 2023

Thank you!
Just for reference, here is my documentation how I currently use it in ioBroker (German):
https://forum.iobroker.net/topic/67947/bastell%C3%B6sung-polestar-ladezustand-via-tibber-app-api

@MirkoHuf
Copy link

Would love to see it. Please have it in the back of your mind - possible that you have more than one car. @Stroell in your iobroker implementation it's allways the first car - you have to modify the script (a little bit) for a second car.

@hombach
Copy link
Owner

hombach commented Sep 23, 2023

Up to now I didn't manage to link my wife's skoda to tibber - perhaps I'll try with the Tesla to have a test scenario for this addon

@MrP646
Copy link

MrP646 commented Nov 14, 2023

I'm facing a similar problem.
We drive a Nissan Leaf and it doesn't have a Tibber PowerUp.
But I have the SOC via the Nissan adapter in ioBroker.
I added the Leaf as “not integrated” in the Tibber app.
Here I have to enter the SOC manually.
Is there a way to send the SOC from ioBroker to Tibber via the Adapter?
Thanks for the help and the great adapter!

@hombach
Copy link
Owner

hombach commented Nov 14, 2023

There`s nothing about car data in the Tibber API documentation

@hombach
Copy link
Owner

hombach commented Feb 2, 2024

I don't see any possibilities to implement this - no data about connected cars in Tibber API. Also I don*t think that they wan't to have this implemented.
If someone could help here - please feel free to do so ;)

@hombach hombach added the help wanted Extra attention is needed label Feb 2, 2024
@hombach
Copy link
Owner

hombach commented May 6, 2024

Still no news in Tibber API to implement anything about connections to cars - closing this thread

@hombach hombach closed this as completed May 6, 2024
@kptkip
Copy link

kptkip commented May 31, 2024

This is a snippet from a JS in IoBroker Forum:

function fetchData(token, callback) {
    const dataOptions = {
        uri: 'https://app.tibber.com/v4/gql',
        method: 'POST',
        headers: {
            'Authorization': `Bearer ${token}`
        },
        json: {
            query: `
                {
                    me {
                        homes {
                            electricVehicles {
                                lastSeen
                                battery {
                                    percent
                                }
                            }
                        }
                    }
                }
            `
        }
    };

As you can see, there is a very easy implementation to fetch the SOC of a car from Tibber

@hombach hombach reopened this Jun 1, 2024
@hombach
Copy link
Owner

hombach commented Jun 2, 2024

Okay, I tried it. It works, but it prevents the car from sleeping... Tibber is probably doing something wrong there - I won't support it like this for now.

@hombach hombach added wontfix This will not be worked on and removed help wanted Extra attention is needed labels Jun 2, 2024
@kptkip
Copy link

kptkip commented Jun 2, 2024

Wow! Spooky!
I use it with my Polestar 2. There it doesn't do this.

Is this a tibber-car-adapter specific phenomenon?

@kptkip
Copy link

kptkip commented Jun 2, 2024

Would it be worth, implementing it with a feature-toggle in the instance-config? And a explicit remark?

So people can chose using it or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

5 participants