Tibber API (Swedish/Norweigan electric company)

Posted on
Thu Sep 13, 2018 3:09 am
eriass offline
Posts: 20
Joined: May 12, 2016

Tibber API (Swedish/Norweigan electric company)

I have made a script that collects your data from Tibber (http://www.tibber.se)

In this script you collect information about your consumption, current electricalprice etc. (see variables). To collect more data look at developer.tibber.com

First of all you will have to install JSON Helper from AppStore.

After that create these variables in Indigo:

tibber_consumption_from
tibber_consumption_to
tibber_consumption_totalcost
tibber_consumption_unitcost
tibber_consumption_unitprice
tibber_consumption_unitpricevat
tibber_consumption_consumption
tibber_consumption_consumptionunit

Then create a Action Group and paste this(Make sure to replace YOUR-API-KEY with your API key that you get from developer.tibber.com with your personal login):

-------------------------------------------------------------------------------------------------------------------------


set respons to do shell script "curl -H \"Authorization: Bearer YOUR-API-KEY\" -H \"Content-Type: application/json\" -X POST -d '{ \"query\": \"{viewer {homes {consumption(resolution: HOURLY, last: 1) {nodes {from to totalCost unitCost unitPrice unitPriceVAT consumption consumptionUnit }} meteringPointData {estimatedAnnualConsumption } currentSubscription {priceInfo {current {total energy tax startsAt }}}}}}\" }' https://api.tibber.com/v1-beta/gql"

tell application "JSON Helper"
set myRecord to read JSON from respons
set myJSON to make JSON from myRecord
set pris_total to total of current of priceInfo of currentSubscription of item 1 of homes of viewer of |data| of myRecord as number
set pris_skatt to tax of current of priceInfo of currentSubscription of item 1 of homes of viewer of |data| of myRecord as number
set pris_energy to energy of current of priceInfo of currentSubscription of item 1 of homes of viewer of |data| of myRecord as number
set consumption_from to |from| of item 1 of nodes of consumption of item 1 of homes of viewer of |data| of myRecord as string
set consumption_to to |to| of item 1 of nodes of consumption of item 1 of homes of viewer of |data| of myRecord as string
set consumption_totalcost to totalCost of item 1 of nodes of consumption of item 1 of homes of viewer of |data| of myRecord as number
set consumption_unitcost to unitCost of item 1 of nodes of consumption of item 1 of homes of viewer of |data| of myRecord as number
set consumption_unitprice to unitPrice of item 1 of nodes of consumption of item 1 of homes of viewer of |data| of myRecord as number
set consumption_unitpricevat to unitPriceVAT of item 1 of nodes of consumption of item 1 of homes of viewer of |data| of myRecord as number
set consumption_consumption to consumption of item 1 of nodes of consumption of item 1 of homes of viewer of |data| of myRecord as number
set consumption_consumptionunit to consumptionUnit of item 1 of nodes of consumption of item 1 of homes of viewer of |data| of myRecord as string



tell application "IndigoServer"

set value of variable "tibber_priceinfo_total" to pris_total
set value of variable "tibber_priceinfo_skatt" to pris_skatt
set value of variable "tibber_priceinfo_energy" to pris_energy

set value of variable "tibber_consumption_from" to consumption_from
set value of variable "tibber_consumption_to" to consumption_to
set value of variable "tibber_consumption_totalcost" to consumption_totalcost
set value of variable "tibber_consumption_unitcost" to consumption_unitcost
set value of variable "tibber_consumption_unitprice" to consumption_unitprice
set value of variable "tibber_consumption_unitpricevat" to consumption_unitpricevat
set value of variable "tibber_consumption_consumption" to consumption_consumption
set value of variable "tibber_consumption_consumptionunit" to consumption_consumptionunit

end tell

end tell

log "Tibber Uppdaterad"


-------------------------------------------------------------------------------------------------------------------------
Then make a schedule to execute the action group.



Hope you like it! They have a great Api Explorer on their page to get more info if your want some more.

//Eric

Posted on
Wed Sep 26, 2018 1:08 am
thomas-ja27 offline
Posts: 8
Joined: Jul 03, 2018
Location: Mosjøen, Norway

Re: Tibber API (Swedish/Norweigan electric company)

Thanks you!
Works well here in Norway :D

Next step is to get data from Tibber Pulse :)

Thomas

Posted on
Mon Oct 01, 2018 5:47 am
thomas-ja27 offline
Posts: 8
Joined: Jul 03, 2018
Location: Mosjøen, Norway

Re: Tibber API (Swedish/Norweigan electric company)

Hi!

Do you know if it is possible to collect future electricity prices in Indigo? (today -tomorrow). Then I could set up when power-consuming devices should use power :)
I see at the API explorer that it is possible, but i dont know how get this to indigo :?

PriceInfo
Field Argument Type Description
current Price
The energy price right now

today [Price]!
The hourly prices of the current day

tomorrow [Price]!
The hourly prices of the upcoming day

range SubscriptionPriceConnection
Range of prices relative to before/after arguments

resolution PriceResolution!
first Int
last Int
before String
after String

Thomas

Posted on
Wed Oct 03, 2018 11:50 am
eriass offline
Posts: 20
Joined: May 12, 2016

Re: Tibber API (Swedish/Norweigan electric company)

I got an answer from Tibber that it leaked out from their api to early, it will be available in the future!


Skickat från min iPhone med Tapatalk

Posted on
Tue Nov 13, 2018 1:37 am
zaiks offline
Posts: 12
Joined: May 19, 2016

Re: Tibber API (Swedish/Norweigan electric company)

Future prices are available via Nord Pool Spot's API https://www.nordpoolgroup.com/trading/api/
Of course you have to take consideration the market price difference from your reselles price

Posted on
Mon Dec 03, 2018 2:52 pm
mortenkols offline
Posts: 194
Joined: Oct 29, 2014
Location: Norway

Re: Tibber API (Swedish/Norweigan electric company)

Has anyone made a script to get data from puls? :)

Posted on
Wed Dec 05, 2018 12:01 am
thomas-ja27 offline
Posts: 8
Joined: Jul 03, 2018
Location: Mosjøen, Norway

Re: Tibber API (Swedish/Norweigan electric company)

I can read real time data in the Api Explorer from Tibber Pulse at https://developer.tibber.com/explorer, but i dont have enough programmingskills to get this into indigo...
Attachments
tibber pulse.png
tibber pulse.png (49.88 KiB) Viewed 328 times

Thomas

Posted on
Wed Dec 05, 2018 5:15 am
GlennNZ offline
Posts: 479
Joined: Dec 07, 2014

Re: Tibber API (Swedish/Norweigan electric company)

Hi

Use GhostXml Plugin
https://www.indigodomo.com/pluginstore/38/

If have a set http webpage which passes the needed homeid should work really well.
Eg. Http://website?homeid=2626353

No programming skills needed!

Glenn

Posted on
Wed Dec 05, 2018 7:29 am
haakon offline
Posts: 27
Joined: Mar 02, 2017

Re: Tibber API (Swedish/Norweigan electric company)

That sounds promising, Glenn! Could you give some details about how to set up GhostXML to do this?

Posted on
Wed Dec 05, 2018 2:20 pm
GlennNZ offline
Posts: 479
Joined: Dec 07, 2014

Re: Tibber API (Swedish/Norweigan electric company)

haakon wrote:
That sounds promising, Glenn! Could you give some details about how to set up GhostXML to do this?


Have a look a GhostXml documentation - very well documented far better than mine! Hopefully you have played with it by now.

Basically takes a JSON or XML result from a http query and converts it into indigo custom states very cleverly.

Open plugin, set up what http query that you get above results for - hopefully passing id/or passwords in the URL. It should then return all those states as indigo custom states within that device. Which you can then use as needed from within indigo.

Glenn

Posted on
Wed Dec 05, 2018 3:15 pm
mortenkols offline
Posts: 194
Joined: Oct 29, 2014
Location: Norway

Re: Tibber API (Swedish/Norweigan electric company)

Tibber puls streams data via websocket, you cannot use query then?

Posted on
Wed Dec 05, 2018 3:39 pm
GlennNZ offline
Posts: 479
Joined: Dec 07, 2014

Tibber API (Swedish/Norweigan electric company)

mortenkols wrote:
Tibber puls streams data via websocket, you cannot use query then?


Probably not - needs to be http query - unless Dave is keen to add curl command line support to GhostXML (?doable)

I’ve PM’ed DaveL17

@DaveL17
Interested in considering GhostXml update? Would be easiest as new ‘raw curl’ call, with just an additional text field for everything passed via curl, and then returns json - same as everything else.
With plugin doing everything else the same after - creating states etc..

G

Posted on
Thu Dec 06, 2018 2:06 am
GlennNZ offline
Posts: 479
Joined: Dec 07, 2014

Re: Tibber API (Swedish/Norweigan electric company)

DaveL is a bit snowed under - so had a look, forked and updated GhostXML here:
https://github.com/Ghawken/GhostXML
Download and Install version 0.4.15


This adds a new mode - to use raw curl commands:
Adds a use Raw Curl for each device.

Image

Click this useRawCurl checkbox:

Add Url:

and enter into Curl Commands Box:
Code: Select all
-H "Authorization: Bearer d1007ead2dc84a2b82f0de19451c5fb22112f7ae11d19bf2bedb224a003ff74a" \
-H "Content-Type: application/json" \
-X POST \
-d '{ "query": "{viewer {homes {consumption(resolution: HOURLY, last: 1) {nodes {from to totalCost unitCost unitPrice unitPriceVAT consumption consumptionUnit }} meteringPointData {estimatedAnnualConsumption } currentSubscription {priceInfo {current {total energy tax startsAt }}}}}}" }'


For a working example from tidder api
https://developer.tibber.com/docs/guides/calling-api

Obviously can change the example to whatever you want to pull and plugin will alter states - beware of the correct use of quotes.




Glenn

Posted on
Thu Dec 06, 2018 3:40 am
thomas-ja27 offline
Posts: 8
Joined: Jul 03, 2018
Location: Mosjøen, Norway

Re: Tibber API (Swedish/Norweigan electric company)

Get this when i try your code:

GhostXML Warning [1918328067] curl error * Illegal characters found in URL * Closing connection -1 /bin/sh: line 1: -H: command not found /bin/sh: line 2: -X: command not found /bin/sh: line 3: -d: command not found .
Attachments
tibber.png
tibber.png (155.6 KiB) Viewed 210 times

Thomas

Posted on
Thu Dec 06, 2018 4:26 am
GlennNZ offline
Posts: 479
Joined: Dec 07, 2014

Re: Tibber API (Swedish/Norweigan electric company)

thomas-ja27 wrote:
Get this when i try your code:

GhostXML Warning [1918328067] curl error * Illegal characters found in URL * Closing connection -1 /bin/sh: line 1: -H: command not found /bin/sh: line 2: -X: command not found /bin/sh: line 3: -d: command not found .


Mate, here I am forking anothers excellent plugin in my spare time to work just for you, in your very specific circumstances, a few words would not go amiss.....
Anyhow...

Have doubled checked - and the code is fine, working well for me- not that I can use tibbler or wish to

You will have likely entered a extra space or extra return, or incorrect character somewhere in the Curl commands big field.
(it does say for advanced use only)
More specifically likely a extra empty line below:
Code: Select all
-d '{ "query": "{viewer {homes {consumption(resolution: HOURLY, last: 1) {nodes {from to totalCost unitCost unitPrice unitPriceVAT consumption consumptionUnit }} meteringPointData {estimatedAnnualConsumption } currentSubscription {priceInfo {current {total energy tax startsAt }}}}}}" }'

Make sure you have no extra line - box should end on the last '

I have double checked - copy and pasted my code example given above again and it works fine.

Double check your entry.
Mine correctly fills and creates the states returned:

Image


If on the rare chance this doesn't fix the issue, I have uploaded 0.4.16 to add debug logging of the entire sent curl command so can double check what is being sent.
Upgrade to this and post the debug log if still issues.

Glenn

Who is online

Users browsing this forum: No registered users and 3 guests