diff --git a/Energy_Pie/module.html b/Energy_Pie/module.html index 50516e0..d57f92c 100644 --- a/Energy_Pie/module.html +++ b/Energy_Pie/module.html @@ -25,6 +25,7 @@
Werte
+
@@ -36,6 +37,7 @@ const elNext = document.getElementById('next'); const elValues = document.getElementById('values'); const elPeriod = document.getElementById('period'); + const elDebug = document.getElementById('debug'); // Range ändern -> sofort rechnen elRange.addEventListener('change', () => requestAction('SetRange', elRange.value)); @@ -77,6 +79,23 @@ // Nur die 4 gewünschten Werte anzeigen (fixe Reihenfolge) renderValues(data.values || {}); + + if (data.debug) { + const p = data.debug.prod || {}; + const f = data.debug.feed || {}; + const g = data.debug.grid || {}; + elDebug.textContent = + `Prod(var=${p.varId}, arch=${p.archiveId}, count=${p.count}) | ` + + `Feed(var=${f.varId}, arch=${f.archiveId}, count=${f.count}) | ` + + `Grid(var=${g.varId}, arch=${g.archiveId}, count=${g.count})`; + } else { + elDebug.textContent = ''; + } + + + + + }; function renderValues(values) { diff --git a/Energy_Pie/module.php b/Energy_Pie/module.php index 36cb3b7..786f93d 100644 --- a/Energy_Pie/module.php +++ b/Energy_Pie/module.php @@ -104,13 +104,17 @@ private function RecalculateAndPush(): void [$tStart, $tEnd] = $this->getRange($range, $date); // Debug-Container initialisieren (sonst "Undefined variable") - $dbgProd = null; - $dbgFeed = null; - $dbgGrid = null; + $dbgProd = []; + $dbgFeed = []; + $dbgGrid = []; - $prod = $this->readDelta($this->ReadPropertyInteger('VarProduction'), $tStart, $tEnd, $dbgProd); - $feed = $this->readDelta($this->ReadPropertyInteger('VarFeedIn'), $tStart, $tEnd, $dbgFeed); - $grid = $this->readDelta($this->ReadPropertyInteger('VarGrid'), $tStart, $tEnd, $dbgGrid); + $prodVar = $this->ReadPropertyInteger('VarProduction'); + $feedVar = $this->ReadPropertyInteger('VarFeedIn'); + $gridVar = $this->ReadPropertyInteger('VarGrid'); + + $prod = $this->readDelta($prodVar, $tStart, $tEnd, $dbgProd); + $feed = $this->readDelta($feedVar, $tStart, $tEnd, $dbgFeed); + $grid = $this->readDelta($gridVar, $tStart, $tEnd, $dbgGrid); $house = $prod - $feed + $grid; if ($house < 0) $house = 0.0; @@ -183,11 +187,14 @@ private function RecalculateAndPush(): void } - private function readDelta(int $varId, int $tStart, int $tEnd, ?array &$dbg = null): float + private function readDelta(int $varId, int $tStart, int $tEnd, array &$dbg): float { $dbg = [ 'varId' => $varId, + 'archiveId' => 0, 'count' => 0, + 'first' => null, + 'last' => null, 'vStart' => null, 'vEnd' => null ]; @@ -197,6 +204,8 @@ private function RecalculateAndPush(): void } $archiveID = IPS_GetInstanceListByModuleID('{43192F0B-135B-4CE7-A0A7-1475603F3060}')[0] ?? 0; + $dbg['archiveId'] = $archiveID; + if ($archiveID <= 0) { return 0.0; } @@ -209,15 +218,15 @@ private function RecalculateAndPush(): void usort($values, static fn($a, $b) => (int)$a['TimeStamp'] <=> (int)$b['TimeStamp']); $dbg['count'] = count($values); - // Fallback: erster/letzter Eintrag im Fenster - $first = (float)$values[0]['Value']; - $last = (float)$values[count($values)-1]['Value']; + $dbg['first'] = (float)$values[0]['Value']; + $dbg['last'] = (float)$values[count($values)-1]['Value']; $vStart = null; $vEnd = null; foreach ($values as $v) { $ts = (int)$v['TimeStamp']; + if ($ts <= $tStart) { $vStart = (float)$v['Value']; } @@ -229,9 +238,9 @@ private function RecalculateAndPush(): void } } - // Wenn kein Wert vor Start/Ende gefunden wurde -> nimm ersten/letzten Logwert - if ($vStart === null) $vStart = $first; - if ($vEnd === null) $vEnd = $last; + // Wenn kein Wert vor Start/Ende gefunden wurde, nimm ersten/letzten im Fenster + if ($vStart === null) $vStart = $dbg['first']; + if ($vEnd === null) $vEnd = $dbg['last']; $dbg['vStart'] = $vStart; $dbg['vEnd'] = $vEnd; @@ -240,6 +249,7 @@ private function RecalculateAndPush(): void return ($diff < 0) ? 0.0 : (float)$diff; } + /** * Buttons for quick navigation. */