Done
I first created 3 items in OH, so I cna also use the data in the OH charts
Number solcast_pv_estimate "Forecast pv_estimate" (solcast_home) ["Point"]
Number solcast_pv_estimate10 "Forecast pv_estimate10" (solcast_home) ["Point"]
Number solcast_pv_estimate90 "Forecast pv_estimate90" (solcast_home) ["Point"]
For the DSL rule, I assume you also have the Channel configured which contains the RAW data. the rule is triggered everytime the item changes
String solcast_home_raw_json_response "Raw JSON Response" (solcast_home) ["Point"] { channel="solarforecast:sc-plane:solcast_home:solcast_PV:raw" }
rule:
// import solcast_home_raw_json_response
val forecastJSON = solcast_home_raw_json_response.state.toString
//logInfo("Forecast.Solcast", forecastJSON)
// influx uri
val String influxdb_uri = "http://xxx.xxx.x.x:xxxx/write?db=openhab_db&precision=s"
// json parse
var String forecasts_entries = transform("JSONPATH", "$..forecasts", forecastJSON)
forecasts_entries = forecasts_entries.replace("[","").replace("]","").replace("{","").replace("}","NEXT")
var Integer count = forecasts_entries.split("NEXT,").length()
//logInfo("Forecast.Solcast", "-" + forecasts_entries.toString + "-")
//logInfo("Forecast.Solcast", "number of entries: " + count.toString)
var Integer x = 0
var influx_content = ""
while (x < count ) {
//logInfo("Forecast.Solcast", x.toString)
var String forecasts = forecasts_entries.split("NEXT,").get(x)
forecasts = "{" + forecasts.replace("NEXT","") + "}"
//logInfo("Forecast.Solcast", forecasts.toString)
val period_end = transform("JSONPATH", "$.period_end", forecasts)
val pv_estimate = transform("JSONPATH", "$.pv_estimate", forecasts)
val pv_estimate10 = transform("JSONPATH", "$.pv_estimate10", forecasts)
val pv_estimate90 = transform("JSONPATH", "$.pv_estimate90", forecasts)
//val formatter = java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
val formatter = java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.'0000000Z'") //2023-05-12T12:00:00.0000000Z
var period_end_formatted = LocalDateTime.parse(period_end, formatter).atZone(ZoneId.systemDefault())
var int timezoneAdd = 0
if (period_end_formatted.toString.contains("+01:00")) {
timezoneAdd = 1
}
else if (period_end_formatted.toString.contains("+02:00")) {
timezoneAdd = 2
}
period_end_formatted = period_end_formatted.plusHours(timezoneAdd) // add hour for timezone if not correct
//logInfo("Forecast.Solcast", period_end_formatted.toString + ": " + pv_estimate)
val period_end_formatted_seconds = period_end_formatted.toEpochSecond
influx_content = influx_content + "solcast_pv_estimate value=" + pv_estimate + " " + period_end_formatted_seconds.toString +"\n"
influx_content = influx_content + "solcast_pv_estimate10 value=" + pv_estimate10 + " " + period_end_formatted_seconds.toString +"\n"
influx_content = influx_content + "solcast_pv_estimate90 value=" + pv_estimate90 + " " + period_end_formatted_seconds.toString +"\n"
x++
}
//logInfo("Forecast.Solcast", influx_content)
// send to influx
influx_content = influx_content.substring(0, influx_content.length()-2)
var responds = sendHttpPostRequest(influxdb_uri, "--data-binary", influx_content, 3000)
logInfo("Forecast.Solcast", "Influx responds {}", responds)
In the rule I play a bit with the timezone, because it’s not correct for me (although my local settings are correct in OH)