Tibber (Norway) websocket subscription

Hello, everybody. I have a problem, and I hope somebody please can help me.

Norwegian tibber uses graphQl subscription for live and accumulated power consumption-data. I would really like to get this data in to my IP-Symcon. To even out the peaks of powerconsumption in norway (typically on the morning and around dinnertime) the government and the power-companies charge extra based on maximum power consumption pr. hour. With these data I could regulate moveable consumption to minimize maximum hourly consumption. I’ve been trying to achieve this on and off for quite some time now, and I’ve gotten a few steps done. But now my (quite meagre) programming skills fall short of what I want to do.

I’ve managed to open a web socket, and connect to my smart meter, and I get valid response in the debug tab on the websocket.

The code I’ve use so far is this

$client = 34873; // the WS-client
$json = ‚{„type“:„connection_init“,„payload“:{„token“: „476c477d8a039529478ebd690d35ddd80e3308ffc49b59c65b142321aee963a4“}}‘;
WSC_SendMessage ($client, $json);

$query= ‚{„id“: „1“,„type“: „start“,„payload“: {„query“: „subscription{liveMeasurement(homeId:"c70dcbe5-4485-4821-933d-a8a86452737b"){timestamp power powerProduction accumulatedConsumption accumulatedCost}}“}}‘;
WSC_SendMessage ($client, $query);

The token and homeId are tibbers demo-tokens, not mine.

The response I get is:
05.08.2022, 15:35:48 | RECEIVED | {„type“:„connection_ack“}
05.08.2022, 15:35:51 | RECEIVED | {„type“:„data“,„id“:„1“,„payload“:{„data“:{„liveMeasurement“:{„timestamp“:„2022-08-05T15:35:52.500+02:00“,„power“:0,„powerProduction“:1386,„accumulatedConsumption“:15.955366,„accumulatedCost“:46.070754}}}}
05.08.2022, 15:35:54 | RECEIVED | {„type“:„data“,„id“:„1“,„payload“:{„data“:{„liveMeasurement“:{„timestamp“:„2022-08-05T15:35:55.000+02:00“,„power“:0,„powerProduction“:null,„accumulatedConsumption“:15.955366,„accumulatedCost“:46.070754}}}}
05.08.2022, 15:35:56 | RECEIVED | {„type“:„data“,„id“:„1“,„payload“:{„data“:{„liveMeasurement“:{„timestamp“:„2022-08-05T15:35:57.500+02:00“,„power“:0,„powerProduction“:null,„accumulatedConsumption“:15.955366,„accumulatedCost“:46.070754}}}}
etc.

What I’d like is to get access to the power powerProduction accumulatedConsumption accumulatedCost data, and get it into Symcon.

How can I do this?

You can connect a „Register Variable“ instance behind the WebSocket and it will receive all WebSocket messages. RegisterVariable — IP-Symcon :: Automation Software

parey

Thank you! An important step forward :slight_smile:

And I figured out that I had to empty the buffer at the end of the cycle. But I still don’t quite know how to get the variables :noob:

At the other (non subscription) request i get a json array(?) which I then parse (?) into current price etc, but when I try to adapt the subscription in the same way I get a blank.

This is an typical string I get in return:
{„type“:„data“,„id“:„1“,„payload“:{„data“:{„liveMeasurement“:{„timestamp“:„2022-08-05T16:44:10.000+02:00“,„power“:0,„powerProduction“:942,„accumulatedConsumption“:16.138631,„accumulatedCost“:46.609486}}}}

Which is in the $data variable from the example script in the documentation.

$accumul = $data->payload->data->liveMeasurment->accumulatedConsumption[0];
SetValue (13928, $accumul);

which then is blank. When I use
SetValue (13928, $data);

I get the whole data string in the variable.

Do you have any more pointers for me, please?

Andreas

1 „Gefällt mir“

I made it! The [0] wasn’t supposed to be there. Lots of trial, googeling and failing, before I achieved success. :sunglasses:

1 „Gefällt mir“