Forecast.solar read data values from json

I would like to read in the values from the forecast.solar website in order to determine the sun’s strongest hours of the day.
The JSON looks something like this:

{
   "result":{
      "watts":{
         "2022-02-21 07:18:00":0,
         "2022-02-21 07:39:00":57,
         "2022-02-21 08:00:00":281,
         "2022-02-21 09:00:00":533,
         "2022-02-21 10:00:00":655,
         "2022-02-21 11:00:00":747,
         "2022-02-21 12:00:00":776,
         "2022-02-21 13:00:00":485,
         "2022-02-21 14:00:00":273,
         "2022-02-21 15:00:00":252,
         "2022-02-21 16:00:00":215,
         "2022-02-21 17:00:00":108,
         "2022-02-21 17:30:00":21,
         "2022-02-21 18:00:00":0,
         "2022-02-22 07:16:00":0,
         "2022-02-22 07:38:00":32,
         "2022-02-22 08:00:00":154,
         "2022-02-22 09:00:00":230,
         "2022-02-22 10:00:00":270,
         "2022-02-22 11:00:00":323,
         "2022-02-22 12:00:00":355,
         "2022-02-22 13:00:00":342,
         "2022-02-22 14:00:00":298,
         "2022-02-22 15:00:00":235,
         "2022-02-22 16:00:00":171,
         "2022-02-22 17:00:00":95,
         "2022-02-22 17:31:00":20,
         "2022-02-22 18:01:00":0
      },
      "watt_hours":{
         "2022-02-21 07:18:00":0,
         "2022-02-21 07:39:00":20,
         "2022-02-21 08:00:00":118,
         "2022-02-21 09:00:00":651,
         "2022-02-21 10:00:00":1306,
         "2022-02-21 11:00:00":2053,
         "2022-02-21 12:00:00":2829,
         "2022-02-21 13:00:00":3314,
         "2022-02-21 14:00:00":3587,
         "2022-02-21 15:00:00":3839,
         "2022-02-21 16:00:00":4054,
         "2022-02-21 17:00:00":4162,
         "2022-02-21 17:30:00":4173,
         "2022-02-21 18:00:00":4173,
         "2022-02-22 07:16:00":0,
         "2022-02-22 07:38:00":12,
         "2022-02-22 08:00:00":68,
         "2022-02-22 09:00:00":298,
         "2022-02-22 10:00:00":568,
         "2022-02-22 11:00:00":891,
         "2022-02-22 12:00:00":1246,
         "2022-02-22 13:00:00":1588,
         "2022-02-22 14:00:00":1886,
         "2022-02-22 15:00:00":2121,
         "2022-02-22 16:00:00":2292,
         "2022-02-22 17:00:00":2387,
         "2022-02-22 17:31:00":2398,
         "2022-02-22 18:01:00":2398
      },
      "watt_hours_day":{
         "2022-02-21":4173,
         "2022-02-22":2398
      }
   },
   "message":{
      "code":0,
      "type":"success",
      "text":"",
      "info":{
         "latitude":11.1111,
         "longitude":12.222,
         "place":"PLZ Stadt, DE",
         "timezone":"Europe/Berlin"
      },
      "ratelimit":{
         "period":3600,
         "limit":12,
         "remaining":0
      }
   }
}

What I need is the time of the two to three sun strongest hours a day. In these hours I want to control different processes via Openhab. I have now tried a few things with JSONPATH, but do not really get anywhere. What is the best way to approach the problem?

Christian

A sorting problem then?
Might be able to adapt -

Yes a sorting problem, but also an extraction problem.
I want to extract the time strongest time…

So in the example

     "2022-02-21 11:00:00":747,
     "2022-02-21 12:00:00":776,

which means I would have to extract 11am as the start time.

I want to write this time into an item to use this time again in rules.

Yes. How far have you got with it? I would advise reading all the data into a single String Item so that you can do your complex processing in the rules language of your choice.

That’s what I did. I read the JSON data into a string item via HTTP binding.

Okay. Have you applied the techniques from the example? For clarity, it gets a list of time stamps and a separate list of values. Timestamp in list position N belongs to value N. Next we blend those into key-value pairs in a single “array”. Next sort that array by your criteria.

If you work directly in javascript, there should be an advantage avoiding that preparatory processing with JSON.

The list looks like the example above in the first post. This is in the string value of the item.
unformatted it looks like this:

{"result":{"watts":{"2022-02-21 07:18:00":0,"2022-02-21 07:39:00":57,"2022-02-21 08:00:00":281,"2022-02-21 09:00:00":533,"2022-02-21 10:00:00":655,"2022-02-21 11:00:00":747,"2022-02-21 12:00:00":776,"2022-02-21 13:00:00":485,"2022-02-21 14:00:00":273,"2022-02-21 15:00:00":252,"2022-02-21 16:00:00":215,"2022-02-21 17:00:00":108,"2022-02-21 17:30:00":21,"2022-02-21 18:00:00":0,"2022-02-22 07:16:00":0,"2022-02-22 07:38:00":32,"2022-02-22 08:00:00":154,"2022-02-22 09:00:00":230,"2022-02-22 10:00:00":270,"2022-02-22 11:00:00":323,"2022-02-22 12:00:00":355,"2022-02-22 13:00:00":342,"2022-02-22 14:00:00":298,"2022-02-22 15:00:00":235,"2022-02-22 16:00:00":171,"2022-02-22 17:00:00":95,"2022-02-22 17:31:00":20,"2022-02-22 18:01:00":0},"watt_hours":{"2022-02-21 07:18:00":0,"2022-02-21 07:39:00":20,"2022-02-21 08:00:00":118,"2022-02-21 09:00:00":651,"2022-02-21 10:00:00":1306,"2022-02-21 11:00:00":2053,"2022-02-21 12:00:00":2829,"2022-02-21 13:00:00":3314,"2022-02-21 14:00:00":3587,"2022-02-21 15:00:00":3839,"2022-02-21 16:00:00":4054,"2022-02-21 17:00:00":4162,"2022-02-21 17:30:00":4173,"2022-02-21 18:00:00":4173,"2022-02-22 07:16:00":0,"2022-02-22 07:38:00":12,"2022-02-22 08:00:00":68,"2022-02-22 09:00:00":298,"2022-02-22 10:00:00":568,"2022-02-22 11:00:00":891,"2022-02-22 12:00:00":1246,"2022-02-22 13:00:00":1588,"2022-02-22 14:00:00":1886,"2022-02-22 15:00:00":2121,"2022-02-22 16:00:00":2292,"2022-02-22 17:00:00":2387,"2022-02-22 17:31:00":2398,"2022-02-22 18:01:00":2398},"watt_hours_day":{"2022-02-21":4173,"2022-02-22":2398}},"message":{"code":0,"type":"success","text":"","info":{"latitude":xxxxxx,"longitude":xxxxxxx,"place":"PLZ , DE","timezone":"Europe/Berlin"},"ratelimit":{"period":3600,"limit":12,"remaining":0}}}

What I tried with JSONPATH to clean up the values first.
JSONPATH
$.result.watts
The result is then:

{
   "2022-02-21 07:18:00" : 0,
   "2022-02-21 07:39:00" : 57,
   "2022-02-21 08:00:00" : 281,
   "2022-02-21 09:00:00" : 533,
   "2022-02-21 10:00:00" : 655,
   "2022-02-21 11:00:00" : 747,
   "2022-02-21 12:00:00" : 776,
   "2022-02-21 13:00:00" : 485,
   "2022-02-21 14:00:00" : 273,
   "2022-02-21 15:00:00" : 252,
   "2022-02-21 16:00:00" : 215,
   "2022-02-21 17:00:00" : 108,
   "2022-02-21 17:30:00" : 21,
   "2022-02-21 18:00:00" : 0,
   "2022-02-22 07:16:00" : 0,
   "2022-02-22 07:38:00" : 32,
   "2022-02-22 08:00:00" : 154,
   "2022-02-22 09:00:00" : 230,
   "2022-02-22 10:00:00" : 270,
   "2022-02-22 11:00:00" : 323,
   "2022-02-22 12:00:00" : 355,
   "2022-02-22 13:00:00" : 342,
   "2022-02-22 14:00:00" : 298,
   "2022-02-22 15:00:00" : 235,
   "2022-02-22 16:00:00" : 171,
   "2022-02-22 17:00:00" : 95,
   "2022-02-22 17:31:00" : 20,
   "2022-02-22 18:01:00" : 0
}

But now I lack the approach siw I proceed with it further.

Okay, that’s a long string. You can split strings on say a comma, into an array of substrings. You can split the substrings on say colon into date-value pairs. Looks like you might have to watch out for newline characters embedded in your data though.

Could you show me an example? Unfortunately, I lack the approach how to implement this.

just a naive heads-up: why not manipulate the not-so-well-thought-of JSON and add a structure, so you can simply use “sort”-functions within a JS object? You then have to “only” split the watts-values and then create a more usable JSON-structure?

{
   "result":{
      "watts":{
         "2022-02-21 07:18:00":0,
         "2022-02-21 07:39:00":57,
         "2022-02-21 08:00:00":281,
...

I would rewrite this into:

{
   "result":{
      "watts":{
         "2022-02-21 07:18:00": {"yield":0},
         "2022-02-21 07:39:00": {"yield":57},
         "2022-02-21 08:00:00": {"yield":281},
         "2022-02-21 09:00:00": {"yield":533}
         ...
      }
   }
}

then you can extract the result.watts values and use a sort within the JS object?

I already did show you an example, but it is in DSL rules language and you have not yet admitted what language you wold prefer.

I am not familiar with OH, but if other formats can be parsed better, there are also CSV and XML as response types.

https://doc.forecast.solar/doku.php?id=api#content_type