0

Tibber.com API call - help with authorization.

Joachim 2 years ago in Devices / Http updated 1 year ago 11

Hi.

I'm trying to reach my electricity company through their public API.

I'm able to use the POST field in the command to get a response but a layer of authorization is required.


Is anyone able to point me in the right direction on how to incorporate the authorization token in my call?

This call gives me a response (from their examples)

call:

{
"query": "{ viewer { name }}"
}

response:

{"data":null,"errors":[{"message":"No valid access token in request","locations":[{"line":1,"column":3}],"path":["viewer"],"extensions":{"code":"INTERNAL_SERVER_ERROR"}}]}


Documentation:

https://developer.tibber.com/docs/guides/calling-api


Any help is appreciated

+1

In your POST, did you add the "authorization bearer" header followed by you personal token as indicated in the API :

Passing the token

The token is passed to the server through the Authorization header and must be included on every call.

Authorization: Bearer <token>

Personal Access Token give you access to your data and your data only. This is ideal for DIY people that want to leverage the Tibber platform to extend the smartness of their home. Such a token can be acquired here.

HTTP POST seem to require 2 headers :

Authorization: Bearer d1007ead2dc84a2b82f0de19451c5fb22112f7ae11d19bf2bedb224a003ff74a
Content-Type: application/json

Regards,

Thank you. Putting the auth token and the content-type line in the header field did the trick. Not easy to figure all of this out without having any programming experience.

I have to play around with this further but I already managed to get the current hour power price as a double.

The API is quite extensive and gives a lot of possibilities on power consumption trends/prices etc for Norwegians. Right now I'm waiting for my little "Tibber Pulse" device that gives me the ability to read my live consumption.

Happy to read it made the trick  ;-)

Following this topic. I have now installed my live consumption meter. Accessing its data requires me to subscribe to the data via web socket. 


from https://developer.tibber.com/docs/guides/calling-api:

wss://api.tibber.com/v1-beta/gql/subscriptions


Some demo values:

Another alternative is to use MQTT. Is any of this possible with bOS?

BR
Joachim

Hi Joachim,


The easiest is to use the JSON answer token value directly in bOS.

I'm using http://jsoneditoronline.org/ to help me identifying the correct token "adress".

If you have difficulties, please copy/paste here the full above demo token in text format and I'll try to help you .

Regards,

How do I shape the request in the "bOS command" as it's not supposed to poll every 300 sec but be connected to a web socket subscription address? 

wss://api.tibber.com/v1-beta/gql/subscriptions

demo token:

d1007ead2dc84a2b82f0de19451c5fb22112f7ae11d19bf2bedb224a003ff74a

demo subscription:

subscription{
liveMeasurement(homeId:"68e6938b-91a6-4199-a0d4-f24c22be87bb"){
timestamp
power
accumulatedConsumption
accumulatedCost
currency
minPower
averagePower
maxPower
}
}

+1

Well, I didn't realize it is through wss. Not sure it is supported by bOS, but will make some tests....

+1

Hi Joachim

So far, I was not able to get it to wotk with wss connection. All data can be collected under normal http API, but not the subscription data. 

@ bOS team : can you let us know if wss connection are even possible ?

I will do further test through other way and see if I get it to work. Also, I didn't find a way through MQTT neither, except for the standard http API info.

Regards

Tanks for your effort @Fabien Fuster!

@bOS team: Please look into this or at least take the time to give an answer on your forum.

Hi Joachim

I am struggling with the same issue. 

Have you found a way to set up bOS to receive the power datastream from Tibber?


Until now I have worked around this by using a Raspberry PI to read and convert HAN Data, before writing a subset of the data to bOS with RPC. However, more information is available from Tibber (accumulated cost, hourly price etc) than through the HAN ports, which makes me prefer the Tibber subscription stream data,  (could of course set up the PI to read the datastream, and forward to bOS using RPC, but I would like to get rid of the extra components).

Hi. Sorry for my late answer. I'm not any closer to resolve this issue. I was hoping that the dev team would pick up on this post and get WSS to work.

The data not received from the HAN port i was able to get from their API. Hourly price etc was OK. Stopped working after a while for some reason and I haven't done anything more with it.