Solar Forecast PV

Thanks for this binding. I was already looking for a way to do some solar predictions.
Grabbing the json via http binding was offcourse also an option, but this simplifies the whole process.

I created a rule which is triggered when the jsonraw channel changes to create some graphs (inspired by this post)

// import ForecastSolarPV_RawJSONResponse
val forecastJSON = ForecastSolarPV_RawJSONResponse.state.toString
//logInfo("ForecastSolar", forecastJSON)
// influx uri
val String influxdb_uri = "http://192.168.0.4:8086/write?db=openhab_db&precision=s"

// ZonedDateTime
val ZonedDateTime todayStart = now.withHour(0).withMinute(0).withSecond(0).withNano(0)
val today = now.getDayOfMonth()
val month = now.getMonthValue()
val year = now.getYear()
val hour = now.getHour()
  
//logInfo("ForecastSolar", "currentHour " + currentHour)
  
// json parse
var String watts = transform("JSONPATH", "$.result.watt_hours", forecastJSON) //watts or watt_hours
//logInfo("ForecastSolar", "-" + watts.toString + "-")

// loop over entries
var Integer x = 0
var influx_content = ""
while (x < watts.split(",").length() ) {
  val entry = watts.split(", ").get(x).replace("{","").replace("}","")
  val time = entry.split("=").get(0).toString
  val value = (Double::parseDouble(entry.split("=").get(1)))/1000 // watts to kWh
    
  val formatter = java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
  val dateTime = LocalDateTime.parse(time, formatter).atZone(ZoneId.systemDefault())
  val dateTime_seconds = (dateTime.toEpochSecond)
  val dateHour = dateTime.getHour()
  val dateDay = dateTime.getDayOfMonth()
  //logInfo("ForecastSolar", "-" + dateTime_seconds.toString + "-")
  
  // filter 0 values & hours in the past
  if ((value != 0 && dateHour > hour && dateDay == today) || (value != 0 && dateDay > today)) {
    //logInfo("ForecastSolar", "-" + dateTime.toString + "-")
    influx_content = influx_content + "solarforecast watt_hours=" + value + " " + dateTime_seconds.toString +"\n"
  }
  x++
}

// send to influx
influx_content = influx_content.substring(0, influx_content.length()-2)
//logInfo("ForecastSolar", influx_content.toString)
var responds = sendHttpPostRequest(influxdb_uri, "--data-binary", influx_content, 3000)
logInfo("test", "Influx responds {}", responds)

in Grafana ot looks like this

3 Likes