no message
This commit is contained in:
@@ -121,6 +121,30 @@ private function RecalculateAndPush(): void
|
|||||||
$feed = $this->readDelta($this->ReadPropertyInteger('VarFeedIn'), $tStart, $tEnd, $dbgFeed);
|
$feed = $this->readDelta($this->ReadPropertyInteger('VarFeedIn'), $tStart, $tEnd, $dbgFeed);
|
||||||
$grid = $this->readDelta($this->ReadPropertyInteger('VarGrid'), $tStart, $tEnd, $dbgGrid);
|
$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;
|
$house = $prod - $feed + $grid;
|
||||||
if ($house < 0) $house = 0.0;
|
if ($house < 0) $house = 0.0;
|
||||||
|
|
||||||
@@ -129,6 +153,7 @@ private function RecalculateAndPush(): void
|
|||||||
'date' => $date,
|
'date' => $date,
|
||||||
'tStart' => $tStart,
|
'tStart' => $tStart,
|
||||||
'tEnd' => $tEnd,
|
'tEnd' => $tEnd,
|
||||||
|
'hasData' => $hasData,
|
||||||
'values' => [
|
'values' => [
|
||||||
'Produktion' => (float)$prod,
|
'Produktion' => (float)$prod,
|
||||||
'Einspeisung' => (float)$feed,
|
'Einspeisung' => (float)$feed,
|
||||||
@@ -246,6 +271,26 @@ private function RecalculateAndPush(): void
|
|||||||
return ($diff < 0) ? 0.0 : (float)$diff;
|
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'];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user