Hallo HM-Gemeinde,
da babba so enttäuscht war habe ich doch an meinem Projekt weiter gebastelt und habe dank Horst, der eine Funktion im HM-Request-Skript benutzt, auch eine Lösung gefunden.
Als erstes muß auf der CCU der XML-API-Patch installiert werde da ansonsten die Funktionen nicht zur Verfügung stehen.
Nun das Skript an einen Wunschort, bevorzugt in eine eigenen Kategorie.
<?
// ***** Array der Devices aus der CCU einlesen *****
$table_content = "";
$ccu_xml = array();
$ccu_xml = file_get_contents("http://192.168.0.7/config/xmlapi/devicelist.cgi"); //IP der CCU anpassen
$ccu_datei = IPS_GetKernelDir()."hm_device.xml";
// Datei öffnen, wenn nicht vorhanden dann wird die Datei erstellt.
$handler = fOpen($ccu_datei , "w+");
fWrite($handler , $ccu_xml); // Dateiinhalt in die Datei schreiben
fclose($handler);
$devices = simplexml_load_file($ccu_datei);
$object = IPS_GetObject($IPS_SELF);
$parentID = $object['ParentID'];
if($IPS_SENDER == "Execute") {
IPS_SetHidden($IPS_SELF, true);
// Ereignis für Skript erstellen falls nicht vorhanden
$EreignisID = @IPS_GetEventIDByName("Event", $IPS_SELF);
if ($EreignisID == false) {
$eid = IPS_CreateEvent(1); // Ausgelöstes Ereignis
//IPS_SetEventTrigger($eid, 0, $DS2450_Port0); // Bei Änderung von Variable
IPS_SetEventCyclic($eid, 2, 1, 0, 0, 0, 0);
IPS_SetEventCyclicTimeBounds($eid, mktime(0, 2, 0), 0);
IPS_SetParent($eid, $IPS_SELF); // Ereignis zuordnen
IPS_SetName($eid, "Event"); // Ereignis umbennen
IPS_SetEventActive($eid, true); // Ereignis aktivieren
}
else {
echo "Ereignis bereits erstellt";
}
}
echo "<table border=0 align='center'>";
$table = "<table border=0>";
echo "<tr><td align='center'><b>IPS-Ort</td><td><b>IPS-Instanz</td><td align='center'><b>HM-Name</td><td align='center'><b>HM-ID</td><td align='center'><b>Typ</td></tr>";
$table_header = "<tr bgcolor='#242D3A' height='25px'><td align='center'><b>IPS-Ort</td><td><b>IPS-Instanz</td><td align='center'><b>HM-Name</td><td align='center'><b>HM-ID</td><td align='center'><b>Typ</td></tr>";
for($i=0; $i < $devices->count(); $i++ ) {
for($x=0; $x < $devices->device[$i]->channel->count(); $x++) {
$ips_id = GetInstanceIDFromHMID($devices->device[$i]->channel[$x]['address']);
$ips_loc = IPS_GetLocation($ips_id);
if($ips_id > 0) {
echo "<tr><td>";
$table_start = "<tr bgcolor='#3D516D'><td>";
echo $ips_loc."</td><td align='center'>"
.$ips_id."</td><td>"
.($devices->device[$i]->channel[$x]['name'])."</td><td> "
.($devices->device[$i]->channel[$x]['address'])."</td><td>"
.($devices->device[$i]->channel[$x]['direction'])."</td>"
;
$table_inhalt = $ips_loc."</td><td align='center'>"
.$ips_id."</td><td>"
.($devices->device[$i]->channel[$x]['name'])."</td><td> "
.($devices->device[$i]->channel[$x]['address'])."</td><td>"
.($devices->device[$i]->channel[$x]['direction'])."</td>"
;
echo "</tr>";
$table_end = "</tr>";
$table_content = $table_content.$table_start.$table_inhalt.$table_end;
}
}
}
echo "</table>";
$table_footer = "</table>";
$table_ausgabe = $table.$table_header.$table_content.$table_footer;
SetValue(CreateVariableByName($parentID, 'HM-Inventur', 3, '~HTMLBox'), $table_ausgabe);
function GetInstanceIDFromHMID($sid)
{
$ids = IPS_GetInstanceListByModuleID("{EE4A81C6-5C90-4DB7-AD2F-F6BBD521412E}");
foreach($ids as $id)
{
$a = HM_GetAddress($id);
$b = $sid;
if($a == $b)
{
return $id;
}
}
return 0;
}
function CreateVariableByName ($id, $name, $type, $profile = "")
{
global $IPS_SELF;
$vid = @IPS_GetVariableIDByName($name, $id);
if ($vid === false)
{
$vid = IPS_CreateVariable($type);
IPS_SetParent($vid, $id);
IPS_SetName($vid, $name);
IPS_SetInfo($vid, "this variable was created by script #$IPS_SELF");
if ($profile !== "") { IPS_SetVariableCustomProfile($vid, $profile); }
}
return $vid;
}
?>
Einzig die IP-Adresse der CCU muß in Zeile 5 angepasst werden.
Die Typenzuordnung sowie die Farben müssen bei Bedarf selbst angepasst werden. Auch die Formatierung der Tabelle ist nur für die Schnelle gedacht.
Viel Spaß an die CCU´ler