Hi,
our (rather) fair and decent national electric grid operator Fingrid (in Finland) gives away lot of information for free via open API (of course you paid it already in your electric bill). They have forecast for electricity shortage on three minute timeslices, output is XML or JSON, depending which one you want. Fingrid open API requires personal API token, but you can make 10000 requests a day, which should be enough for most. API and response use UTC-time and all times are formatted as YYYY-MM-DDThh:mm:ssZ
I managed to create sensor (curl / JSON) that returns single value for testing purposes:
name: Fingrid forecast
scan_interval: 3600
command: "curl -X GET --header 'Accept: application/json' --header 'x-api-key: my_very_personal_api_key_goes_here' 'https://api.fingrid.fi/v1/variable/336/events/json?start_time=2022-12-17T06%3A00%3A00Z&end_time=2022-12-17T06%3A03%3A00Z'"
and response for three minute period (sensor state) is single value:
[{"value":0,"start_time":"2022-12-17T06:01:00+0000","end_time":"2022-12-17T06:01:00+0000"}]
Now, my questions:
- how to pass starting time attribute with current time and end time as current time + 12h for example?
- response has always “value”:0 if no blackouts are expected and other numeric values, if blackouts are expected, numeric state varies by severity. If there’s other state than 0, I’d like to pick first and last response with different value than 0 and their timestamps. I have no need for middle timestamps, because there will be electricity shortage. How to template this first and last value and their timestamps?
Thanks in advance, this may not be complicated, but I’m not expert in templates, even if can do basics.
EDIT:
Add some useful links for Fingrid API
General description on Fingrid API - Fingridin avoin data API - Fingridin avoin data)
URL generator / validator for Fingrid API Swagger UI (fingrid.fi)
Dataset descriptions and their IDs used for requests Dataset - Fingridin avoin data