telegraf

How to fetch and import current Tibber prices from Tibber API into InfluxDB using Telegraf?


I'm currently working on a project that requires me to retrieve the latest Tibber electricity prices from the Tibber API and then store them in InfluxDB using telegraf. Despite going through the telegraf documentation, I haven't been able to find a clear example or guidance on how to set up this integration specifically with the Tibber API.

Could someone provide a code snippet demonstrating how to configure telegraf to fetch real-time Tibber prices from the Tibber API? Any insights into potential considerations or specific settings would also be incredibly helpful.


Solution

  • I've found a solution:

    [[inputs.http]]
      name_override = "tibber"
      urls = ["https://api.tibber.com/v1-beta/gql"]
      method = "POST"
      timeout = "5s"
      interval = "30m"
      headers = { "Content-Type" = "application/json", "Authorization" = "Bearer *YOUR_TOKEN*" }
      body = '{ "query": "{viewer {home(id: \"*YOUR_HOME_ID*\") {currentSubscription {priceInfo {today {total energy tax startsAt }}}}}}" }'
      data_format = "json"
      json_query = "data.viewer.home.currentSubscription.priceInfo.today"
      json_time_key = "startsAt"
      json_time_format = "2006-01-02T15:04:05.000-07:00"
    
    [[inputs.http]]
      name_override = "tibber"
      urls = ["https://api.tibber.com/v1-beta/gql"]
      method = "POST"
      timeout = "5s"
      interval = "30m"
      headers = { "Content-Type" = "application/json", "Authorization" = "Bearer *YOUR_TOKEN*" }
      body = '{ "query": "{viewer {home(id: \"*YOUR_HOME_ID*\") {currentSubscription {priceInfo {tomorrow {total energy tax startsAt }}}}}}" }'
      data_format = "json"
      json_query = "data.viewer.home.currentSubscription.priceInfo.tomorrow"
      json_time_key = "startsAt"
      json_time_format = "2006-01-02T15:04:05.000-07:00"