REST with Tibber and attribute

Am trying to create a new sensor that gets its data from the Tibber REST API.
It works as far as getting correct data to an attribute but I dont want to create a separate template sensor just to convert it. Have seen other similar topics but I just cant get it to work with my sensor…

This is my sensor code

  - platform: rest
    name: Tibber price without tax
    resource: https://api.tibber.com/v1-beta/gql
    method: POST
    payload: '{ "query": "{viewer{homes{currentSubscription{priceInfo{current{energy}}}}}}" }'
    json_attributes_path: "$.data.viewer.homes[0].currentSubscription.priceInfo"
    json_attributes:
      - current
    value_template: "{{ value_json['currentSubscription.priceInfo']['current']}}"
    headers:
      Authorization: !secret tibber
      Content-Type: application/json
      User-Agent: REST

This is how my sensor looks:
current

You can use the rest integration (instead of the rest sensor platform) to make as many sensors as you want from the one resource call:

e.g. configurtion.yaml

rest:
  - resource: https://api.tibber.com/v1-beta/gql
    method: POST
    payload: '{ "query": "{viewer{homes{currentSubscription{priceInfo{current{energy}}}}}}" }'
    sensor:
      - name: "Tibber price without tax (Status)"
        value_template: "{{ value_json.currentSubscription.priceInfo.current }}"

      - name: "Tibber price without tax (Current)"
        value_template: "{{ value_json.data.viewer.homes[0].currentSubscription.priceInfo.current }}"
        device_class: monetary

Am trying to sort this out but its not working.
The sensor value is “unknown”.

REST and RESTful is hard to get a grip on for me :exploding_head:

  - resource: https://api.tibber.com/v1-beta/gql
    method: POST
    payload: '{ "query": "{viewer{homes{currentSubscription{priceInfo{current{energy}}}}}}" }'
    headers:
      Authorization: !secret tibber
    sensor:
      - name: "Tibber price without tax (Status)"
        value_template: "{{ value_json.currentSubscription.priceInfo.current }}"

      - name: "Tibber price without tax (Current)"
        value_template: "{{ value_json.data.viewer.homes[0].currentSubscription.priceInfo.current }}"
        device_class: monetary

current2

Okey so after some tinkering around I found out what the problem was.
I also added some attribute values, will move some other sensors to RESTful later on to save on the number of API calls to Tibber.

Works like a charm! Thanks for pointing me in the right direction @tom_l

rest:
  - resource: https://api.tibber.com/v1-beta/gql
    method: POST
    payload: '{ "query": "{viewer{homes{currentSubscription{priceInfo{current{total energy tax startsAt}}}}}}" }'
    headers:
      Authorization: !secret tibber
      Content-Type: application/json
      User-Agent: REST
    sensor:
      - unique_id: tibber_spot_price
        name: "Tibber spot price"
        json_attributes_path: "$.data.viewer.homes[0].currentSubscription.priceInfo.current"
        value_template: "{{ value_json.data.viewer.homes[0].currentSubscription.priceInfo.current.energy | float }}"
        json_attributes:
          - total
          - energy
          - tax
          - startsAt
        unit_of_measurement: SEK/kWh
        device_class: monetary
        state_class: measurement

1 Like

Hey! I’m really sorry to bother you with a beginner’s problem. :confused: Since days i try to implement a Tibber price forecast. As i found this thread, i´ve found two codes for me:

One for the sensors.yaml:

- platform: rest
  name: TibberPreise
  resource: https://api.tibber.com/v1-beta/gql
  method: POST
  scan_interval: 60
  payload: '{ "query": "{ viewer { homes { currentSubscription { priceInfo { today { total startsAt } tomorrow { total startsAt }}}}}}" }'
  json_attributes_path: "$.data.viewer.homes[0].currentSubscription.priceInfo"
  json_attributes:
    - today
    - tomorrow
    - startsAt
  value_template: Ok
  headers:
    Authorization: !secret tibber
    Content-Type: application/json
    User-Agent: REST

and one for the configuration.yaml:

rest:
  - resource: https://api.tibber.com/v1-beta/gql
    method: POST
    payload: '{ "query": "{viewer{homes{currentSubscription{priceInfo{current{total energy tax startsAt}}}}}}" }'
    headers:
      Authorization: !secret tibber
      Content-Type: application/json
      User-Agent: REST
    sensor:
      - unique_id: tibber_spot_price
        name: "Tibber spot price"
        json_attributes_path: "$.data.viewer.homes[0].currentSubscription.priceInfo.current"
        value_template: "{{ value_json.data.viewer.homes[0].currentSubscription.priceInfo.current.energy | float }}"
        json_attributes:
          - total
          - energy
          - tax
        unit_of_measurement: €/kWh
        device_class: monetary
        state_class: measurement

Unfortunately I have problems with both… Two questions:

  1. The “Authorization” is my tibber API-Key or my timmer home id?
  2. I would also like to fetch the energy-Parameter. But i got N/A or Zero.

May you help me and find a solution for me problem? At the ent i would like to show the actualy and the forecast price in a chart. Thank you! :pray: