diff --git a/PV_Forecast/module.php b/PV_Forecast/module.php index cb93288..4000592 100644 --- a/PV_Forecast/module.php +++ b/PV_Forecast/module.php @@ -208,35 +208,38 @@ class PV_Forecast extends IPSModule private function GetForecastSeriesFilteredUtc(int $startUtcTs, int $endUtcTs): array { $raw = $this->GetBuffer("ForecastRaw"); - if ($raw === "") { - return []; - } + if ($raw === "") return []; $data = json_decode($raw, true); - if (!is_array($data) || !isset($data["estimated_actuals"]) || !is_array($data["estimated_actuals"])) { + if (!is_array($data)) return []; + + // forecast endpoint: "forecasts" + if (isset($data["forecasts"]) && is_array($data["forecasts"])) { + $rows = $data["forecasts"]; + } elseif (isset($data["estimated_actuals"]) && is_array($data["estimated_actuals"])) { + // fallback live endpoint + $rows = $data["estimated_actuals"]; + } else { return []; } $series = []; - foreach ($data["estimated_actuals"] as $row) { + foreach ($rows as $row) { if (!isset($row["period_end"], $row["pv_power_rooftop"])) continue; - // period_end ist UTC ("Z") - $ts = strtotime($row["period_end"]); + $ts = strtotime($row["period_end"]); // UTC wegen Z if ($ts === false) continue; - // Filter: "heute lokal" als UTC-Grenzen if ($ts < $startUtcTs || $ts >= $endUtcTs) continue; - // Solcast: kW - $val = (float)$row["pv_power_rooftop"]; - $series[] = [$ts * 1000, $val]; + $series[] = [$ts * 1000, (float)$row["pv_power_rooftop"]]; } usort($series, fn($a, $b) => $a[0] <=> $b[0]); return $series; } + // ----------------- Series: Actual (Archive) ----------------- private function GetActualSeriesFromArchive(int $startTs, int $endTs, int $bucketSeconds, int $nowTs): array