diff --git a/Belevo_PV_Visu/module.html b/Belevo_PV_Visu/module.html
index e69de29..01ff2e1 100644
--- a/Belevo_PV_Visu/module.html
+++ b/Belevo_PV_Visu/module.html
@@ -0,0 +1,65 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Belevo_PV_Visu/module.php b/Belevo_PV_Visu/module.php
index 280c23e..723b8c2 100644
--- a/Belevo_PV_Visu/module.php
+++ b/Belevo_PV_Visu/module.php
@@ -1,126 +1,126 @@
-RegisterPropertyInteger("Reservate", 0);
- $this->RegisterPropertyInteger("GetAmount", 0);
- $this->RegisterPropertyInteger("HTMLBox", 0);
- $this->RegisterVariableInteger("ReservationAmount", "ReservationAmount", '', 0);
- $this->RegisterVariableBoolean("AmountIsReserved", "AmountIsReserved", '', false);
+ // vier Properties, in denen später die vier Zähler-Variablen gewählt werden
+ $this->RegisterPropertyInteger('VarProduction', 0);
+ $this->RegisterPropertyInteger('VarConsumption', 0);
+ $this->RegisterPropertyInteger('VarFeedIn', 0);
+ $this->RegisterPropertyInteger('VarGrid', 0);
+ // HTML-SDK aktivieren
+ $this->SetVisualizationType(3);
}
- public function ApplyChanges()
+ public function GetConfigurationForm(): string
{
- parent::ApplyChanges();
- $this->SetHTMLContent();
- }
-
- private function SetHTMLContent()
- {
- $apiKey = "pk_test_51Qkr79LJAcsNrpivA90lt7ULEzyXKR8l0pAqTBgfeuAIWlsLS4A3BdIBITc9UooFANbImvlJQ2F2jOZ0X5j8GI7Q00hNNasvQm"; // Test-API-Schlüssel
-
- $html = "
-
-
-
- Google Pay mit Stripe
-
-
-
-
-
-
- Google Pay Integration mit Stripe
-
-
-
-
-";
-
- SetValue($this->ReadPropertyInteger("HTMLBox"), $html);
+ 'actions' => []
+ ]);
}
-}
\ No newline at end of file
+
+ /**
+ * Wird automatisch aufgerufen, wenn die Visu die Tile anfordert
+ */
+ public function GetVisualizationTile(int $InstanceID): string
+ {
+ $file = __DIR__ . '/module.html';
+ if (!file_exists($file)) {
+ return '';
+ }
+ // Übersetzungen einbinden
+ return $this->Translate(file_get_contents($file));
+ }
+
+ /**
+ * JS-requestAction ruft das auf, um frische Daten anzufordern
+ */
+ public function RequestAction(string $Ident, $Value): void
+ {
+ if ($Ident === 'update') {
+ $this->Update();
+ } else {
+ throw new Exception('Unknown Ident');
+ }
+ }
+
+ /**
+ * Berechnet die Tages-Summen und sendet sie an die Visu
+ */
+ private function Update(): void
+ {
+ $start = strtotime('today 00:00');
+ $end = time();
+ $prod = $this->GetDailyTotal($this->ReadPropertyInteger('VarProduction'), $start, $end);
+ $cons = $this->GetDailyTotal($this->ReadPropertyInteger('VarConsumption'), $start, $end);
+ $feed = $this->GetDailyTotal($this->ReadPropertyInteger('VarFeedIn'), $start, $end);
+ $grid = $this->GetDailyTotal($this->ReadPropertyInteger('VarGrid'), $start, $end);
+
+ // Quoten berechnen
+ $prodCons = $prod > 0 ? ($cons / $prod) * 100 : 0;
+ $prodFeed = $prod > 0 ? ($feed / $prod) * 100 : 0;
+ $consPV = $cons > 0 ? (min($cons, $prod) / $cons) * 100 : 0;
+ $consGrid = $cons > 0 ? ($grid / $cons) * 100 : 0;
+
+ $data = [
+ 'prodCons' => round($prodCons, 2),
+ 'prodFeed' => round($prodFeed, 2),
+ 'consPV' => round($consPV, 2),
+ 'consGrid' => round($consGrid, 2),
+ 'value' => [
+ 'prod' => round($prod, 2),
+ 'cons' => round($cons, 2),
+ 'feed' => round($feed, 2),
+ 'grid' => round($grid, 2)
+ ]
+ ];
+ $this->UpdateVisualizationTile($data);
+ }
+
+ /**
+ * Ruft den Tages-Gesamtwert aus dem Archiv ab (tägliche Aggregation)
+ */
+ private function GetDailyTotal(int $varID, int $start, int $end): float
+ {
+ if ($varID <= 0) {
+ return 0.0;
+ }
+ // Erste Archive-Instanz finden
+ $archives = IPS_GetInstanceListByModuleID('{43192F11-5B02-4B5D-9B53-8B4DBD4769E9}');
+ if (empty($archives)) {
+ return 0.0;
+ }
+ $archiveID = $archives[0];
+ // AC_GetAggregatedValues( InstanzID, VarID, AggregationLevel(1=Täglich), Start, Ende, Limit=1 )
+ $values = AC_GetAggregatedValues($archiveID, $varID, 1, $start, $end, 1);
+ if (empty($values)) {
+ return 0.0;
+ }
+ // Bei Counter-Variablen enthält 'Avg' die Summe der Deltas
+ return (float)$values[0]['Avg'];
+ }
+}