This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

Tibber API
#1
I have been trying to pull some data like power consumption and prices. Limited Lua/json scripting skills have brought it to a stop, can anybody help`? 

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

Best regards, Jørn.
Reply
#2
Change token and data query as needed:

Code:
https = require('ssl.https')
json = require('json')
ltn12 = require('ltn12')

token = 'd1007ead2dc84a2b82f0de19451c5fb22112f7ae11d19bf2bedb224a003ff74a'

data = json.encode({
  query = '{viewer {homes {currentSubscription {priceInfo {current {total energy tax startsAt }}}}}}'
})

tbl = {}
res, code = https.request({
  url = 'https://api.tibber.com/v1-beta/gql',
  method = 'POST',
  headers = {
    ['authorization'] = 'Bearer ' .. token,
    ['content-type']  = 'application/json',
    ['content-length'] = #data,
  },
  source = ltn12.source.string(data),
  sink = ltn12.sink.table(tbl),
})

if res and code == 200 then
  resp = table.concat(tbl)
  resp = json.pdecode(resp)

  log(resp)
else
  log(res, code)
end
Reply
#3
Superb! But i get "nesting too deep" before all data is retrieved, is this issue on Tibber side or LM `? 

Code:
* table:
[data]
  * table:
   [viewer]
    * table:
     [homes]
      * table:
       [1]
        * table:
         [currentSubscription]
          * table:
           [priceInfo]
            * table:
             nesting too deep

Best regards, Jørn.
Reply
#4
There's a limit of how deep the table can be for log() function, try this:
Code:
log(resp.data.viewer.homes)
Reply
#5
Hi,

How de we retrieve a value from table within table here, and write this to a group address?

grp.write('32/1/16', 'tbl[1][1][1][1][4][1]')?

kind regards 
thomas
Reply
#6
Depends, can you show log output for this table?
Reply
#7
   
Reply
#8
Code:
homes = resp.data.viewer.homes
info = homes[ 1 ].currentSubscription.priceInfo.current
log(info.energy)
log(info.tax)
log(info.total)
Reply
#9
That worked :-) Thank you again :-)
Reply
#10
Hi 

I've been testing this for a while, and get all the readings from viewer, homes, currentSubscriptions and so on.
But the liveMeasurement I can't really figure out.

Have anyone got this to work?

Eirik
Reply
#11
Very interesting. Anyone who knows how to also integrate the current Power consumption and data from the TIBBER PULSE ? Would be great With some help.
Schneider Wiser (homeLynk), DALI controller, Actuators and Multitouch Pro buttons. Panasonic Heating pump, Flexit balanced ventilation. Lemus Speaker system.
Reply


Forum Jump: