From d1fb024708553ec5a53b474d3f325ed2562f64cd Mon Sep 17 00:00:00 2001 From: DanielHaefliger Date: Fri, 5 Dec 2025 08:30:33 +0100 Subject: [PATCH] no message --- Abrechnung/module.php | 81 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 66 insertions(+), 15 deletions(-) diff --git a/Abrechnung/module.php b/Abrechnung/module.php index 7dedaeb..faadbd1 100644 --- a/Abrechnung/module.php +++ b/Abrechnung/module.php @@ -192,24 +192,74 @@ private function CalculateAllPowerCosts($powerMeters, $tariffs, $from, $to) $expTotal = 0.0; $slot = []; - // 2a. Deltas je Zähler des Users - foreach ($meters as $name => $mm) { - $impDelta = 0.0; - $expDelta = 0.0; + // 2a. Deltas je Zähler des Users + IPS_LogMessage("ABR", "---- DELTA-Berechnung für Intervall " . date("H:i", $ts) . " - " . date("H:i", $slotEnd) . " ----"); - if (!empty($mm['importVar']) && IPS_VariableExists((int)$mm['importVar'])) { - $impDelta = $this->getDeltaFromArchive((int)$mm['importVar'], $ts, $slotEnd); - } - if (!empty($mm['exportVar']) && IPS_VariableExists((int)$mm['exportVar'])) { - $expDelta = $this->getDeltaFromArchive((int)$mm['exportVar'], $ts, $slotEnd); - } + foreach ($meters as $name => $mm) { - if ($impDelta > 0.0 || $expDelta > 0.0) { - $slot[$name] = ['imp' => $impDelta, 'exp' => $expDelta]; - $impTotal += $impDelta; - $expTotal += $expDelta; - } + IPS_LogMessage("ABR", " Prüfe Zähler: $name"); + IPS_LogMessage("ABR", " ImportVar=" . ($mm['importVar'] ?? 'NULL')); + IPS_LogMessage("ABR", " ExportVar=" . ($mm['exportVar'] ?? 'NULL')); + + $impDelta = 0.0; + $expDelta = 0.0; + + // --- IMPORT --- + if (!empty($mm['importVar'])) { + + $varId = (int)$mm['importVar']; + + if (!IPS_VariableExists($varId)) { + IPS_LogMessage("ABR", " ⚠ ImportVar $varId existiert NICHT!"); + } else { + + IPS_LogMessage("ABR", " → ImportDelta: getDeltaFromArchive($varId, $ts, $slotEnd)"); + + $impDelta = $this->getDeltaFromArchive($varId, $ts, $slotEnd); + + IPS_LogMessage("ABR", " Ergebnis ImportDelta=$impDelta"); } + } + + // --- EXPORT --- + if (!empty($mm['exportVar'])) { + + $varId = (int)$mm['exportVar']; + + if (!IPS_VariableExists($varId)) { + IPS_LogMessage("ABR", " ⚠ ExportVar $varId existiert NICHT!"); + } else { + + IPS_LogMessage("ABR", " → ExportDelta: getDeltaFromArchive($varId, $ts, $slotEnd)"); + + $expDelta = $this->getDeltaFromArchive($varId, $ts, $slotEnd); + + IPS_LogMessage("ABR", " Ergebnis ExportDelta=$expDelta"); + } + } + + // --- Ergebnis für diesen Zähler --- + IPS_LogMessage("ABR", " → Zähler $name: impDelta=$impDelta | expDelta=$expDelta"); + + if ($impDelta > 0.0 || $expDelta > 0.0) { + + IPS_LogMessage("ABR", " ✔ Delta > 0 → wird für Intervall übernommen"); + + $slot[$name] = [ + 'imp' => $impDelta, + 'exp' => $expDelta + ]; + + $impTotal += $impDelta; + $expTotal += $expDelta; + + } else { + IPS_LogMessage("ABR", " ✘ Delta = 0 → wird ignoriert"); + } + } + + IPS_LogMessage("ABR", "---- Ende DELTA-Berechnung: impTotal=$impTotal | expTotal=$expTotal ----"); + if ($impTotal == 0.0 && $expTotal == 0.0) { continue; // für diesen User in diesem Intervall nichts passiert @@ -460,6 +510,7 @@ private function GetCalculatedPowerCosts($userId) return $closest ?? floatval(GetValue($varId)); } + private function getDeltaFromArchive(int $varId, int $tStart, int $tEnd): float { $startValue = $this->GetValueAt($varId, $tStart, false); // Wert davor/zu Beginn