Create and integrate RestAPI

Hello Home Assistant Community,

i have problems and also understanding problems when creating a sensor using API.
I tried to do it with Platform:Rest.

I would like to show the grid frequency from the Page: [Mains frequency monitoring the UCTE power grid | Gridradar]

This page also provides documentation:
[API Account]

In my config.YAML I added the following:

  - platform: rest
    name: "Netzfrequenz"
    resource: https://api.gridradar.net/query?token=mytoken&metric=frequency-ucte-median-1s
    force_update: 60

I also have a security token. When I paste the link into the browser, I get the values ​​as well.

[{"datapoints":[[49.99564,"2022-01-29 13:52:21"],[49.99555,"2022-01-29 13:52:22"],[49.99357,"2022-01-29 13:52:23"],[49.99213,"2022-01-29 13:52:24"],[49.9913,"2022-01-29 13:52:25"],[49.99017,"2022-01-29 13:52:26"],[49.98894,"2022-01-29 13:52:27"],[49.98811,"2022-01-29 13:52:28"],[49.98791,"2022-01-29 13:52:29"],[49.98796,"2022-01-29 13:52:30"],[49.98675,"2022-01-29 13:52:31"],[49.98526,"2022-01-29 13:52:32"],[49.98434,"2022-01-29 13:52:33"],[49.9852,"2022-01-29 13:52:34"],[49.98623,"2022-01-29 13:52:35"],[49.98533,"2022-01-29 13:52:36"],[49.9841,"2022-01-29 13:52:37"],[49.98389,"2022-01-29 13:52:38"],[49.9838,"2022-01-29 13:52:39"],[49.98388,"2022-01-29 13:52:40"]],"target":"median_frequency"}]This text will be hidden

What do I have to do so that it can be displayed as a sensor?

Please excuse my bad english.

Many greetings
Tobias

Isn’t there really no solution for the above mentioned problem?
I’ve the same problem. :frowning:

Of course there is: the OP just happened not to get an answer.

Please show the response you’re getting (as the OP did) and which data you would like extracted from it.

For the first frequency number from the OP’s data, you can do:

value_template: "{{ value_json[0]['datapoints'][0][0] }}"

which says:

  • take the first element of the response (the bit in the outermost [ ])
  • take the datapoints key
  • look at the first element of that (next set of [ ])
  • look at the first element of that (final set of [ ])

and the response should be 49.99564.

Testing in the template editor, copying in the OP’s data as value_json:

If you want to do something else (like get the timestamp of the lowest frequency, for example), all this can be done. Just be clear about what you want.

1 Like

Thx for your response.

I’ve found an other solution which works!

1 Like