diff --git a/Energy_Pie/module.html b/Energy_Pie/module.html
index fd5c82e..4e1952c 100644
--- a/Energy_Pie/module.html
+++ b/Energy_Pie/module.html
@@ -25,6 +25,7 @@
@@ -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));
@@ -81,6 +83,15 @@
} else {
renderValues({});
}
+
+if (data.debug) {
+ const p = data.debug.prod, f = data.debug.feed, g = data.debug.grid;
+ elDebug.textContent =
+ `Logs: Prod(count=${p?.count ?? 0}) Feed(count=${f?.count ?? 0}) Grid(count=${g?.count ?? 0})`;
+ } else {
+ elDebug.textContent = '';
+ }
+
}
// Nur diese vier Werte anzeigen (fixe Reihenfolge)
diff --git a/Energy_Pie/module.php b/Energy_Pie/module.php
index 410f306..ca74b0b 100644
--- a/Energy_Pie/module.php
+++ b/Energy_Pie/module.php
@@ -121,6 +121,11 @@ private function RecalculateAndPush(): void
'Einspeisung' => (float)$feed,
'Netz' => (float)$grid,
'Hausverbrauch'=> (float)$house
+ ],
+ 'debug' => [
+ 'prod' => $dbgProd,
+ 'feed' => $dbgFeed,
+ 'grid' => $dbgGrid
]
];
@@ -174,17 +179,21 @@ private function RecalculateAndPush(): void
}
- private function readDelta($varId, $tStart, $tEnd)
+ private function readDelta(int $varId, int $tStart, int $tEnd, ?array &$dbg = null): float
{
- if (!is_int($tStart)) {
- $tStart = strtotime($tStart);
- }
- if (!is_int($tEnd)) {
- $tEnd = strtotime($tEnd);
+ $dbg = [
+ 'varId' => $varId,
+ 'count' => 0,
+ 'vStart' => null,
+ 'vEnd' => null
+ ];
+
+ if ($varId <= 0 || !IPS_VariableExists($varId)) {
+ return 0.0;
}
- $archiveID = @IPS_GetInstanceListByModuleID('{43192F0B-135B-4CE7-A0A7-1475603F3060}')[0];
- if (!$archiveID || !IPS_VariableExists($varId)) {
+ $archiveID = IPS_GetInstanceListByModuleID('{43192F0B-135B-4CE7-A0A7-1475603F3060}')[0] ?? 0;
+ if ($archiveID <= 0) {
return 0.0;
}
@@ -193,32 +202,40 @@ private function RecalculateAndPush(): void
return 0.0;
}
- usort($values, fn($a, $b) => (int)$a['TimeStamp'] <=> (int)$b['TimeStamp']);
+ 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'];
+
$vStart = null;
$vEnd = null;
foreach ($values as $v) {
- if ($v['TimeStamp'] <= $tStart) {
- $vStart = $v['Value'];
+ $ts = (int)$v['TimeStamp'];
+ if ($ts <= $tStart) {
+ $vStart = (float)$v['Value'];
}
- if ($v['TimeStamp'] <= $tEnd) {
- $vEnd = $v['Value'];
+ if ($ts <= $tEnd) {
+ $vEnd = (float)$v['Value'];
}
- if ($v['TimeStamp'] > $tEnd) {
+ if ($ts > $tEnd) {
break;
}
}
- if ($vStart === null) {
- $vStart = (float)GetValue($varId);
- }
- if ($vEnd === null) {
- $vEnd = (float)GetValue($varId);
- }
+ // Wenn kein Wert vor Start/Ende gefunden wurde -> nimm ersten/letzten Logwert
+ if ($vStart === null) $vStart = $first;
+ if ($vEnd === null) $vEnd = $last;
+
+ $dbg['vStart'] = $vStart;
+ $dbg['vEnd'] = $vEnd;
$diff = $vEnd - $vStart;
- return ($diff < 0) ? 0.0 : $diff;
+ return ($diff < 0) ? 0.0 : (float)$diff;
}
+
/**
* Buttons for quick navigation.
*/
@@ -271,11 +288,7 @@ private function RecalculateAndPush(): void
return checkdate($m, $d, $y);
}
- // Optional helper for the "actions" test button in form.json
- public function TestPush(): void
- {
- $this->RecalculateAndPush();
- }
+
}
?>
\ No newline at end of file