From 394b797e84c0160b1b1b0b28d0b5b9af0cba0e53 Mon Sep 17 00:00:00 2001 From: "belevo\\mh" Date: Wed, 17 Dec 2025 10:19:41 +0100 Subject: [PATCH] no message --- Energy_Pie/module.php | 45 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/Energy_Pie/module.php b/Energy_Pie/module.php index cdf6ee8..605908a 100644 --- a/Energy_Pie/module.php +++ b/Energy_Pie/module.php @@ -121,6 +121,30 @@ private function RecalculateAndPush(): void $feed = $this->readDelta($this->ReadPropertyInteger('VarFeedIn'), $tStart, $tEnd, $dbgFeed); $grid = $this->readDelta($this->ReadPropertyInteger('VarGrid'), $tStart, $tEnd, $dbgGrid); + + $hasData = (($dbgProd['count'] ?? 0) > 0) || (($dbgFeed['count'] ?? 0) > 0) || (($dbgGrid['count'] ?? 0) > 0); + + if (!$hasData && $range !== 'total') { + // nimm Produktion als Referenz für "letzte Daten" + $lastTs = $this->getLastLogTimestamp($this->ReadPropertyInteger('VarProduction')); + + if ($lastTs > 0) { + $this->WriteAttributeString(self::ATTR_DATE, date('Y-m-d', $lastTs)); + + // Range neu berechnen für dieses Datum + $date = $this->ReadAttributeString(self::ATTR_DATE); + [$tStart, $tEnd] = $this->getRange($range, $date); + + // Deltas nochmal holen (jetzt sollte count>0 werden) + $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); + + $hasData = (($dbgProd['count'] ?? 0) > 0) || (($dbgFeed['count'] ?? 0) > 0) || (($dbgGrid['count'] ?? 0) > 0); + } + } + + $house = $prod - $feed + $grid; if ($house < 0) $house = 0.0; @@ -129,6 +153,7 @@ private function RecalculateAndPush(): void 'date' => $date, 'tStart' => $tStart, 'tEnd' => $tEnd, + 'hasData' => $hasData, 'values' => [ 'Produktion' => (float)$prod, 'Einspeisung' => (float)$feed, @@ -246,6 +271,26 @@ private function RecalculateAndPush(): void return ($diff < 0) ? 0.0 : (float)$diff; } + private function getLastLogTimestamp(int $varId): int + { + if ($varId <= 0 || !IPS_VariableExists($varId)) { + return 0; + } + + $archiveID = IPS_GetInstanceListByModuleID('{43192F0B-135B-4CE7-A0A7-1475603F3060}')[0] ?? 0; + if ($archiveID <= 0) { + return 0; + } + + // Hole den letzten Eintrag (0..now, limit=1 -> der neueste) + $values = @AC_GetLoggedValues($archiveID, $varId, 0, time(), 1); + if (empty($values)) { + return 0; + } + + // Bei limit=1 kommt genau ein Eintrag (der neueste) + return (int)$values[0]['TimeStamp']; + }