Tibber API (Swedish/Norweigan electric company)

Posted on
Thu Sep 13, 2018 3:09 am
eriass offline
Posts: 19
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

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest