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 that you accept these cookies being set.

Tibber API
#41
(23.02.2024, 11:35)admin Wrote: Can you send your token and home ID via PM?

Thank's for your answer admin.

I restored the LM with a backup from January, and Tibber is working again.
Lost some loggings, but everything else seems ok.

Best regards, 
Carl
Reply
#42
Hey, i'm trying to get the current price. But i dont have a subscription or a home in tibber. So is it possible to read the current price? And want to write it in a GA.
Here is my code and what i get, but i dont understand why.

Attached Files Thumbnail(s)
   
Reply
#43
(23.04.2024, 06:16)davidkoch29 Wrote: Hey, i'm trying to get the current price. But i dont have a subscription or a home in tibber. So is it possible to read the current price? And want to write it in a GA.
Here is my code and what i get, but i dont understand why.

You need a Tibber account with a token.

Best regards, Jørn.
Reply
#44
Hi Jorn, i have a Tibber account and token.

I deleted the token for the picture
Reply
#45
Try this query:
Code:
query = [[
{
  viewer {
    homes {
      currentSubscription {
        priceInfo {
          current {
            total
          }
        }
      }
    }
  }
}
]]

I suppose you need to create a currentSubscription/home before using queries.
Reply
#46
Is this method working anymore?
My script suddenly stopped working 8 jan.

i now returns code 400


Code:
os.sleep(1)
https = require('ssl.https')
json = require('json')
ltn12 = require('ltn12')
token = '5K4MVS-OjfWhK_4yrjOlFe1F6kJXPVf7eQYggo8ebAE' -- demotoken
data = json.encode({
  query = '{viewer {homes {currentSubscription {priceInfo}}}}' --kwh pris med avgifter
})
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)
homes = resp.data.viewer.homes
info = homes[ 1 ].currentSubscription.priceInfo.current
log(res, code, info.total, info.level)
  grp.write('33/0/51', info.total*100)
  grp.write('33/0/53', info.level)
else
  log(res, code, homes, info)
end
Reply
#47
You are missing priceInfo fields that API should return.

Code:
data = json.encode({
  query = [[
    { viewer
      { homes
        { currentSubscription
          { priceInfo
            { current { total level startsAt } }
          }
        }
      }
    }
  ]]
})

Error logging can be improved because the server response contains a useful error message.
Code:
resp = table.concat(tbl)

if res and code == 200 then
  resp = json.pdecode(resp)
  homes = resp.data.viewer.homes
  info = homes[ 1 ].currentSubscription.priceInfo.current
  
  log(res, code, info.total, info.level)

  grp.write('33/0/51', info.total*100)
  grp.write('33/0/53', info.level)
else
  log(res, code, resp)
end
Reply
#48
Thanks for your quick reply.

I still got the error but ran the pieces of code on https://developer.tibber.com/explorer and it worked there.

Then I remembered that I some weeks ago I added Melcloud powerup in the Tibber-APP..
In my Melcloud-account I have inserted one extra heatpump at another location.
For some reason this has bumped my mainhome to home #2.

So then i had to change the line 
info = homes[ 1 ].currentSubscription.priceInfo.current
to 
info = homes[ 2 ].currentSubscription.priceInfo.current

and then we are back up and running.

Thank you again for sharing your knowledge  Cool
Reply


Forum Jump: