no message

This commit is contained in:
belevo\mh
2026-01-20 10:18:51 +01:00
parent 5db059fc51
commit 33667256ec
2 changed files with 75 additions and 39 deletions

View File

@@ -1,38 +1,27 @@
{
"elements": [
{
"type": "ValidationTextBox",
"name": "URL",
"caption": "Solcast URL"
},
{
"type": "SelectVariable",
"name": "ActualVariableID",
"caption": "Ist-Produktion Variable (Leistung, ideal W oder kW)"
"type": "Select",
"name": "RefreshMode",
"caption": "Aktualisierungsmodus",
"options": [
{ "caption": "Alle X Minuten", "value": "interval" },
{ "caption": "Einmal täglich (Uhrzeit)", "value": "daily" }
]
},
{
"type": "NumberSpinner",
"name": "RefreshMinutes",
"caption": "Refresh (Minuten)",
"caption": "Intervall (Minuten)",
"minimum": 1,
"maximum": 240
"maximum": 240,
"visible": true
},
{
"type": "CheckBox",
"name": "ActualIsWatt",
"caption": "Istwerte sind in Watt (in kW umrechnen)"
}
],
"actions": [
{
"type": "Button",
"caption": "Forecast jetzt aktualisieren",
"onClick": "IPS_RequestAction($id, 'UpdateForecast', 0);"
},
{
"type": "Label",
"caption": "Hinweis: Istwerte werden aus dem Archiv gelesen. Variable muss im Archiv geloggt werden."
"type": "TimeSpinner",
"name": "RefreshTime",
"caption": "Tägliche Uhrzeit",
"visible": true
}
]
}

View File

@@ -10,7 +10,9 @@ class PV_Forecast extends IPSModule
$this->RegisterPropertyString("URL", "");
$this->RegisterPropertyInteger("ActualVariableID", 0);
$this->RegisterPropertyString("RefreshMode", "interval"); // interval | daily
$this->RegisterPropertyInteger("RefreshMinutes", 5);
$this->RegisterPropertyInteger("RefreshTime", 6 * 3600); // 06:00 in Sekunden
$this->RegisterPropertyBoolean("ActualIsWatt", true);
$this->RegisterTimer("UpdateForecastTimer", 0, 'IPS_RequestAction($_IPS["TARGET"], "UpdateForecast", 0);');
@@ -18,27 +20,41 @@ class PV_Forecast extends IPSModule
$this->RegisterHook("/hook/solcastcompare");
}
public function ApplyChanges()
{
parent::ApplyChanges();
public function ApplyChanges()
{
parent::ApplyChanges();
$this->SetVisualizationType(1);
$this->SetVisualizationType(1);
$mins = max(1, (int)$this->ReadPropertyInteger("RefreshMinutes"));
$this->SetTimerInterval("UpdateForecastTimer", $mins * 60 * 1000);
$mode = $this->ReadPropertyString("RefreshMode");
if ($mode === "interval") {
// 🔁 Intervall-Modus
$mins = max(1, (int)$this->ReadPropertyInteger("RefreshMinutes"));
$this->SetTimerInterval(
"UpdateForecastTimer",
$mins * 60 * 1000
);
} else {
// ⏰ Tageszeit-Modus
$this->SetTimerInterval(
"UpdateForecastTimer",
60 * 1000 // jede Minute prüfen
);
}
$this->RegisterHook("/hook/solcastcompare");
}
$this->RegisterHook("/hook/solcastcompare");
}
public function RequestAction($Ident, $Value)
{
switch ($Ident) {
case "UpdateForecast":
$this->UpdateForecast();
break;
default:
throw new Exception("Unknown Ident: " . $Ident);
if ($Ident === "UpdateForecast") {
$this->HandleScheduledUpdate();
return;
}
throw new Exception("Unknown Ident: " . $Ident);
}
private function UpdateForecast()
@@ -218,6 +234,37 @@ class PV_Forecast extends IPSModule
return (is_array($list) && count($list) > 0) ? (int)$list[0] : 0;
}
private function HandleScheduledUpdate()
{
$mode = $this->ReadPropertyString("RefreshMode");
if ($mode === "interval") {
// 🔁 immer aktualisieren
$this->UpdateForecast();
return;
}
// ⏰ Tageszeit-Modus
$targetSec = (int)$this->ReadPropertyInteger("RefreshTime");
$now = time();
// Sekunden seit Mitternacht
$nowSec =
(int)date("H", $now) * 3600 +
(int)date("i", $now) * 60;
// Schon heute gelaufen?
$lastRun = (int)$this->GetBuffer("LastDailyRun");
$today = strtotime("today");
if ($nowSec >= $targetSec && $lastRun < $today) {
$this->SendDebug("Scheduler", "Tägliches Update ausgelöst", 0);
$this->UpdateForecast();
$this->SetBuffer("LastDailyRun", (string)$now);
}
}
private function RegisterHook(string $Hook)
{
$ids = IPS_GetInstanceListByModuleID("{015A6EB8-D6E5-4B93-B496-0D3FAD4D0E6E}");