no message
This commit is contained in:
@@ -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
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@@ -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);');
|
||||
@@ -24,21 +26,35 @@ class PV_Forecast extends IPSModule
|
||||
|
||||
$this->SetVisualizationType(1);
|
||||
|
||||
$mode = $this->ReadPropertyString("RefreshMode");
|
||||
|
||||
if ($mode === "interval") {
|
||||
// 🔁 Intervall-Modus
|
||||
$mins = max(1, (int)$this->ReadPropertyInteger("RefreshMinutes"));
|
||||
$this->SetTimerInterval("UpdateForecastTimer", $mins * 60 * 1000);
|
||||
$this->SetTimerInterval(
|
||||
"UpdateForecastTimer",
|
||||
$mins * 60 * 1000
|
||||
);
|
||||
} else {
|
||||
// ⏰ Tageszeit-Modus
|
||||
$this->SetTimerInterval(
|
||||
"UpdateForecastTimer",
|
||||
60 * 1000 // jede Minute prüfen
|
||||
);
|
||||
}
|
||||
|
||||
$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}");
|
||||
|
||||
Reference in New Issue
Block a user