From 25630326c75e0398664444dd45e0d898fc4effdc Mon Sep 17 00:00:00 2001 From: "belevo\\mh" Date: Wed, 17 Dec 2025 08:23:24 +0100 Subject: [PATCH] no message --- Energy_Pie/module.php | 46 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/Energy_Pie/module.php b/Energy_Pie/module.php index 45de3cf..410f306 100644 --- a/Energy_Pie/module.php +++ b/Energy_Pie/module.php @@ -173,6 +173,52 @@ private function RecalculateAndPush(): void } } + + private function readDelta($varId, $tStart, $tEnd) + { + if (!is_int($tStart)) { + $tStart = strtotime($tStart); + } + if (!is_int($tEnd)) { + $tEnd = strtotime($tEnd); + } + + $archiveID = @IPS_GetInstanceListByModuleID('{43192F0B-135B-4CE7-A0A7-1475603F3060}')[0]; + if (!$archiveID || !IPS_VariableExists($varId)) { + return 0.0; + } + + $values = @AC_GetLoggedValues($archiveID, $varId, $tStart - 86400, $tEnd + 86400, 0); + if (empty($values)) { + return 0.0; + } + + usort($values, fn($a, $b) => (int)$a['TimeStamp'] <=> (int)$b['TimeStamp']); + $vStart = null; + $vEnd = null; + + foreach ($values as $v) { + if ($v['TimeStamp'] <= $tStart) { + $vStart = $v['Value']; + } + if ($v['TimeStamp'] <= $tEnd) { + $vEnd = $v['Value']; + } + if ($v['TimeStamp'] > $tEnd) { + break; + } + } + + if ($vStart === null) { + $vStart = (float)GetValue($varId); + } + if ($vEnd === null) { + $vEnd = (float)GetValue($varId); + } + + $diff = $vEnd - $vStart; + return ($diff < 0) ? 0.0 : $diff; + } /** * Buttons for quick navigation. */