Getting a rest call to Tibber for production data

I have this query from Tibber Grapql :

 {viewer {homes {production (resolution: MONTHLY, last:1 ) {nodes {profit unitPrice production }}}}}

It produces the correct output like:

 {
  "data": {
    "viewer": {
      "homes": [
        {
          "production": {
            "nodes": [
              {
                "profit": 340.66446335,
                "unitPrice": 1.555972,
                "production": 218.94
              }
            ]
          }
        }
      ]
    }
  }
}

I now try to do the same from Home Assitant using rest:

- platform: rest
    name: Tibber Production per hour
    unique_id: tibber_production_per_hour
    resource: https://api.tibber.com/v1-beta/gql
    method: POST
    payload: '{ "query": "{viewer {homes {production (resolution: MONTHLY, last:1 ) {nodes {profit unitPrice production }}}}}" }'
    json_attributes_path: "$.data.viewer.homes[0].production"
    json_attributes:
      - profit 
      - unitPrice 
    value_template: "{{ value_json.data.viewer.homes[0].production.nodes.production | float }}"
    scan_interval: "01:00:00"
    headers:
        Authorization: !secret tibber_token
        Content-Type: application/json
        User-Agent: REST
        unit_of_measurement: SEK/kWh    

This does however not work. I got it to work for prices and cost but totally fail to se what type of error I am doing with the production figures. If anyone can point me in the right direction I would really appreciate it.

nodesis also an array, so you would need:

value_json.data.viewer.homes[0].production.nodes[0].production 
1 Like

Many thanks for this, I am so blind. I did not see that so got totally blind. It did work instantly when i changed to the proposed solution so really, thank you so much for this, most appreciated!