no message

This commit is contained in:
belevo\mh
2026-01-21 08:08:07 +01:00
parent 63912b3606
commit 1207792810

View File

@@ -25,12 +25,19 @@ class PV_Forecast_plotmemory extends IPSModule
$this->RegisterPropertyString("SnapshotTime", "23:59"); // HH:MM $this->RegisterPropertyString("SnapshotTime", "23:59"); // HH:MM
$this->RegisterPropertyInteger("KeepDays", 30); $this->RegisterPropertyInteger("KeepDays", 30);
// Important: Prevent tile from triggering URL fetch (strict daily behavior)
$this->RegisterPropertyBoolean("AllowTileFetchIfEmpty", false);
// Timer // Timer
$this->RegisterTimer("UpdateForecastTimer", 0, 'IPS_RequestAction($_IPS["TARGET"], "UpdateForecast", 0);'); $this->RegisterTimer("UpdateForecastTimer", 0, 'IPS_RequestAction($_IPS["TARGET"], "UpdateForecast", 0);');
$this->RegisterTimer("SnapshotTimer", 0, 'IPS_RequestAction($_IPS["TARGET"], "SnapshotTick", 0);'); $this->RegisterTimer("SnapshotTimer", 0, 'IPS_RequestAction($_IPS["TARGET"], "SnapshotTick", 0);');
// WebHook endpoint // WebHook endpoint
$this->RegisterHook("/hook/solcastcompare_plotmemory"); $this->RegisterHook("/hook/solcastcompare_plotmemory");
// Persisted run markers (survive restarts)
$this->RegisterAttributeInteger("LastDailyRunForecast", 0);
$this->RegisterAttributeInteger("LastDailySnapshotRun", 0);
} }
public function ApplyChanges() public function ApplyChanges()
@@ -46,7 +53,7 @@ class PV_Forecast_plotmemory extends IPSModule
$mins = max(1, (int)$this->ReadPropertyInteger("RefreshMinutes")); $mins = max(1, (int)$this->ReadPropertyInteger("RefreshMinutes"));
$this->SetTimerInterval("UpdateForecastTimer", $mins * 60 * 1000); $this->SetTimerInterval("UpdateForecastTimer", $mins * 60 * 1000);
} else { } else {
// daily check each minute // daily: check each minute
$this->SetTimerInterval("UpdateForecastTimer", 60 * 1000); $this->SetTimerInterval("UpdateForecastTimer", 60 * 1000);
} }
@@ -56,8 +63,6 @@ class PV_Forecast_plotmemory extends IPSModule
} else { } else {
$this->SetTimerInterval("SnapshotTimer", 0); $this->SetTimerInterval("SnapshotTimer", 0);
} }
$this->RegisterHook("/hook/solcastcompare");
} }
public function RequestAction($Ident, $Value) public function RequestAction($Ident, $Value)
@@ -98,13 +103,13 @@ class PV_Forecast_plotmemory extends IPSModule
$now = time(); $now = time();
$nowSec = ((int)date("H", $now) * 3600) + ((int)date("i", $now) * 60); $nowSec = ((int)date("H", $now) * 3600) + ((int)date("i", $now) * 60);
$lastRun = (int)$this->GetBuffer("LastDailyRunForecast"); $lastRun = (int)$this->ReadAttributeInteger("LastDailyRunForecast");
$today0 = strtotime("today"); $today0 = strtotime("today");
if ($nowSec >= $targetSec && $lastRun < $today0) { if ($nowSec >= $targetSec && $lastRun < $today0) {
$this->SendDebug("Scheduler", "Taegliches Forecast-Update (" . $timeStr . ")", 0); $this->SendDebug("Scheduler", "Taegliches Forecast-Update (" . $timeStr . ")", 0);
$this->UpdateForecast(); $this->UpdateForecast();
$this->SetBuffer("LastDailyRunForecast", (string)$now); $this->WriteAttributeInteger("LastDailyRunForecast", $now);
} }
} }
@@ -126,7 +131,8 @@ class PV_Forecast_plotmemory extends IPSModule
$now = time(); $now = time();
$nowSec = ((int)date("H", $now) * 3600) + ((int)date("i", $now) * 60); $nowSec = ((int)date("H", $now) * 3600) + ((int)date("i", $now) * 60);
$lastRun = (int)$this->GetBuffer("LastDailySnapshotRun"); // IMPORTANT: use Snapshot marker, not Forecast marker
$lastRun = (int)$this->ReadAttributeInteger("LastDailySnapshotRun");
$today0 = strtotime("today"); $today0 = strtotime("today");
if ($nowSec >= $targetSec && $lastRun < $today0) { if ($nowSec >= $targetSec && $lastRun < $today0) {
@@ -140,7 +146,7 @@ class PV_Forecast_plotmemory extends IPSModule
$this->CreateDailySnapshotForDate(new DateTime('today', new DateTimeZone(date_default_timezone_get()))); $this->CreateDailySnapshotForDate(new DateTime('today', new DateTimeZone(date_default_timezone_get())));
$this->CleanupOldSnapshots(); $this->CleanupOldSnapshots();
$this->SetBuffer("LastDailySnapshotRun", (string)$now); $this->WriteAttributeInteger("LastDailySnapshotRun", $now);
} }
} }
@@ -188,7 +194,9 @@ class PV_Forecast_plotmemory extends IPSModule
public function GetVisualizationTile(): string public function GetVisualizationTile(): string
{ {
if ($this->GetBuffer("ForecastRaw") === "") { // Strict daily mode: do NOT fetch from URL when tile is opened.
// If you really want this fallback, enable AllowTileFetchIfEmpty.
if ($this->GetBuffer("ForecastRaw") === "" && $this->ReadPropertyBoolean("AllowTileFetchIfEmpty")) {
$this->UpdateForecast(); $this->UpdateForecast();
} }
@@ -451,7 +459,6 @@ class PV_Forecast_plotmemory extends IPSModule
$forecastJson = json_encode($payload["series"]["forecast"] ?? []); $forecastJson = json_encode($payload["series"]["forecast"] ?? []);
$actualJson = json_encode($payload["series"]["actual"] ?? []); $actualJson = json_encode($payload["series"]["actual"] ?? []);
// Hinweis: nutzt Highcharts CDN. (Wenn du offline öffnen willst, sag Bescheid, dann liefern wir highcharts.js lokal mit.)
return '<!doctype html> return '<!doctype html>
<html lang="de"> <html lang="de">
<head> <head>
@@ -554,7 +561,7 @@ class PV_Forecast_plotmemory extends IPSModule
echo "No snapshots found"; echo "No snapshots found";
return; return;
} }
$kunde = trim($this->ReadPropertyString("kunde"));
$kunde = trim($this->ReadPropertyString("kunde")); $kunde = trim($this->ReadPropertyString("kunde"));
if ($kunde === "") { if ($kunde === "") {
$kunde = "unbekannt"; $kunde = "unbekannt";
@@ -565,10 +572,10 @@ class PV_Forecast_plotmemory extends IPSModule
header("Content-Type: application/zip"); header("Content-Type: application/zip");
header( header(
'Content-Disposition: attachment; filename="pv_plots_' . 'Content-Disposition: attachment; filename="pv_plots_' .
$kundeSafe . '_' . $kundeSafe . '_' .
$this->InstanceID . '_' . $this->InstanceID . '_' .
$days . 'days.zip"' $days . 'days.zip"'
); );
header("Content-Length: " . filesize($zipPath)); header("Content-Length: " . filesize($zipPath));