Ich würde das am ehesten so lösen gibt aber bestimmt auch andere Möglichkeiten.
[ul]
[li]Booelan Variable erstellen für Schaltzustand mit Profile ~Switch
[/li][li]Integer Variable erstellen zum Abspeichern der Gesamtlaufzeit
[/li][li]Float Variable erstellen zum Abspeichern des Verbrauchs
[/li][/ul]
Dann erstellst Du ein Skript das Dir die Schaltzustand Variable aktualisiert
$state = GetValue(22222 /*[Dateneingang]*/); // Integer Variable die die Werte 0 oder 30 enthält
$switchstate = GetValue(33333 /*[Schaltzustand]*/); // Neu angelegte Boolean Variable mit Type ~Switch
if($state == 0 && $switchstate == true)
{
SetValue(33333 /*[Schaltzustand]*/, false);
}
elseif($state == 30 && $switchstate == false)
{
SetValue(33333 /*[Schaltzustand]*/, true);
}
Auf das Skript legst Du ein Ereignis bei Variablenaktualisierung der Integer Variable (Dateneingang).
Jetzt aktivierst Du bei der Boolean Variable Logging ( Alle Variablenänderungen aufzeichnen) dann wird jedes An / Aus aufgezeichnet.
Wenn Du jetzt wissen willst wieviel Öl verbraucht wurde musst Du nur schauen wie lange die Boolean Variable im Einschaltzustand war.
z.B. mit
<?
$starttime = strtotime("today 00:00"); // Startzeit der Auswertung in dem Fall heute 0 Uhr muss angepasst werden.
$ArchiveID = IPS_GetInstanceListByModuleID('{43192F0B-135B-4CE7-A0A7-1475603F3060}')[0]; // Archiv Handler ID wird automatisch ausgelesen
$State_VarID = 33333 /*[Schaltzustand]*/; // Objekt ID der geloggten Boolean Schaltvariable
//Alle heutigen Datensätze abfragen
$LogDatenAR = AC_GetLoggedValues($ArchiveID, $State_VarID, $starttime, time(), 0);
$Count = 0;
$duration = 0;
$timestampon = 0;
$timestampoff = 0;
foreach ($LogDatenAR as $LogWert)
{
$timestampcurrent = $LogWert['TimeStamp'];
if ($LogWert['Value'] == 1)
{
$timestampon = $timestampcurrent;
if ($duration == 0 && $timestampoff == 0)
{
$timestampoff = time();
}
$intervall = abs($timestampoff - $timestampon);
$duration = $duration + $intervall;
$Count++;
$timestampon = 0;
$timestampoff = 0;
}
elseif ($LogWert['Value'] == 0 && $timestampon != 0)
{
$intervall = abs($timestampcurrent - $timestampon);
$duration = $duration + $intervall;
}
elseif ($LogWert['Value'] == 0 && $timestampon == 0)
{
$timestampoff = $timestampcurrent;
}
}
function intervall($sek) {
$i = sprintf('%d Tag%s, %d Stunde%s,'.
' %d Minute%s und %d Sekunde%s',
$sek / 86400,
floor($sek / 86400) != 1 ? 'e':'',
$sek / 3600 % 24,
floor($sek / 3600 % 24) != 1 ? 'n':'',
$sek / 60 % 60,
floor($sek / 60 % 60) != 1 ? 'n':'',
$sek % 60,
floor($sek % 60) != 1 ? 'n':''
);
return $i;
}
$formattedduration = intervall($duration);
echo "Es wurden ".$Count." Schaltvorgänge registriert.
Die Anschaltzeit hatte eine Gesamtdauer von ".$formattedduration." (= ".$duration." Sekunden).
";
// Verbrauch 1,72l/h.
$consumption = $duration * (1.72 / 3600);
echo "Es wurden ".round($consumption, 2)." Liter Öl verbraucht.";
SetValue(28065 /*[Verbrauch]*/, $consumption);
SetValue(11011 /*[Gesamtlaufzeit]*/, $duration);
?>
Musst Du mal ausprobieren ob da was Sinnvolles rauskommt.