die Funktion „FetchReedStates“ sucht alle STM250-Instanzen im System ab, und outputtet eine schön formattierte Tabelle welche den Zustand (offen oder geschlossen) und einige andere Parameter zeigt. Die Tabelle kann als HTML-Element in WebFront integriert werden, oder anderweitig bearbeitet werden. Alle der Tabelle zugrunde liegenden Daten sind im 2-dimensionalen array „$ReedStates“ enthalten.
In meinem Falle dient dies dazu, zu eruieren, welche Türe/Fenster offen sind. Meine Alarmanlage wird nur dann aktiviert, wenn alles zu ist.
<?php
FetchReedStates('none');
function FetchReedStates($CategoryId)
{
$ReedStates = array();
$ReedState = array();
$counter = 0;
$modulGuidsToAdd = array
(
//"{FA1479DE-C0C1-433D-98BC-EA7C298D1AA5}", // STM100
"{B01DE819-EA69-4FC1-91AB-4D9FF8D55370}" // STM250
);
foreach($modulGuidsToAdd as $modulGuid)
{
$moduleIds = IPS_GetInstanceListByModuleID($modulGuid);
foreach($moduleIds as $modulId)
{
$ReedState['ObjectId'] = $modulId;
$ReedState['ObjectLocation'] = IPS_GetLocation($modulId);
$ReedState['ObjectName'] = IPS_GetName($modulId);
foreach (IPS_GetChildrenIDs($modulId) as $ReedChild)
{
if (IPS_GetName($ReedChild)=="Status")
{
$ReedChildVariable = IPS_GetVariable($ReedChild);
if ($ReedChildVariable['VariableValue']['ValueBoolean'])
{$ReedState['ObjectValue'] = "closed";}
else
{$ReedState['ObjectValue'] = "open";};
$ReedState['ObjectLastUpdate'] =
$ReedChildVariable['VariableUpdated'];
$ReedState['ObjectLastUpdateFormatted'] =
date('Y-M-d H.i:s', $ReedChildVariable['VariableUpdated']);
}
else $ReedState['ObjectValue'] = '';
}
$ReedStates[$counter] = $ReedState;
$counter +=1;
}
}
BetterTable($ReedStates);
}
//---------------------------------------
function BetterTable($twoDimArray)
{
$i = 0;
echo "<table>
<table class='BetterTable' border='1'>";
echo "<tr>";
echo '<td>Line #
</td>';
foreach ($twoDimArray[0] as $fieldName => $fieldValue)
{
echo '<td>'.$fieldName. '</td>';
}echo '</tr>';
$i = 0;
foreach ($twoDimArray as $rowName => $rowValue)
{
if ($i%2 == 0)
Echo "<tr bgcolor=\"#d0d0d0\" >";
else
Echo "<tr bgcolor=\"#eeeeee\">";
$fields = count($twoDimArray[$i]);
$y = 0;
echo '<td>'.$i. '</td>';
foreach ($rowValue as $fieldName => $fieldValue)
{
echo '<td>'.$fieldValue. '</td>';
$y = $y + 1;
}
echo '</tr>';
$i = $i + 1;
}
echo '</table>';
}
?>