Ich habe heute mal meine 4x2 HDMI Matrix als IR angelernt und da hat mich interessiert wie ich an die Befehle komme. Ist bei IR/BlueTooth/External nicht ganz so einfach.
Einmal benötigt man
curl_setopt($ch, CURLOPT_URL, ‚http://‘.$IP2.‚/api/remotes?kind=‘ . $Kind . ‚&page=‘.$Page.‚&limit=100‘)
um an generelle Informationen wie UID und Name zu kommen.
Für jede UID muss man noch
curl_setopt($gfi, CURLOPT_URL, ‚http://‘.$IP.‚/api/remotes/‘ . $UID);
abfragen um an [„options“][„simple_commands“] zu kommen. Hier noch mein Script das Remotes anlegt und darin dann wieder Verzeichnisse für BlueTooth, IR und External mit vielen Informationen.
<?php
// cURL-Session initialisieren
$Key1 = GetValue(22717);
$IP1 = '192.168.178.227';
$Key2 = GetValue(17539);
$IP2 = '192.168.178.228';
if (!GetValue(43134)) return;
//if (!GetValue(44614)) return;
$Kinds =array("1" => "BT", "2" => "IR", "3" => "EXTERNAL");
// Kategorie Remotes erzeugen
$RootID = @IPS_GetObjectIDByName("Remotes", IPS_GetParent($_IPS['SELF']));
if ($RootID == false){
$RootID = IPS_CreateCategory(); // Kategorie anlegen
IPS_SetName($RootID, "Remotes"); // Kategorie benennen
IPS_SetParent($RootID, IPS_GetParent($_IPS['SELF'])); // Kategorie einsortieren unter dem Objekt
}
// cURL-Session initialisieren
foreach ($Kinds as $Kind){
$Page = 1;
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $Key2,
'accept: application/json'
]);
// Kategorie Remotes erzeugen
$ParentID = @IPS_GetObjectIDByName("Remotes " . $Kind, $RootID);
if ($ParentID == false){
$ParentID = IPS_CreateCategory(); // Kategorie anlegen
IPS_SetName($ParentID, "Remotes " . $Kind); // Kategorie benennen
IPS_SetParent($ParentID, $RootID); // Kategorie einsortieren unter dem Objekt
}
while (true){
curl_setopt($ch, CURLOPT_URL, 'http://'.$IP2.'/api/remotes?kind=' . $Kind . '&page='.$Page.'&limit=100');
$response = curl_exec($ch);
$Entities = array();
$Entities = json_decode($response,true);
if ((is_null($Entities)) || (count($Entities) == 0)) break;
//var_dump($Entities);
//return;
$Page++;
foreach ($Entities as $Entity){
if (array_key_exists("de", $Entity["name"])){
$Parent = @IPS_GetObjectIDByName($Entity["name"]["de"], $ParentID);
if ($Parent == false){
$Parent = IPS_CreateCategory(); // Kategorie anlegen
IPS_SetName($Parent, $Entity["name"]["de"]); // Kategorie benennen
IPS_SetParent($Parent, $ParentID); // Kategorie einsortieren unter dem Objekt
}
}
else if (array_key_exists("en", $Entity["name"])){
$Parent = @IPS_GetObjectIDByName($Entity["name"]["en"], $ParentID);
if ($Parent == false){
$Parent = IPS_CreateCategory(); // Kategorie anlegen
IPS_SetName($Parent, $Entity["name"]["en"]); // Kategorie benennen
IPS_SetParent($Parent, $ParentID); // Kategorie einsortieren unter dem Objekt
}
}
if (isset($Entity["entity_id"]) && isset($Entity["entity_type"])){
$UIDID = @IPS_GetObjectIDByName("UID", $Parent);
if ($UIDID == false){
$UIDID = IPS_CreateVariable(3); // Stringvariable anlegen
IPS_SetPosition($UIDID, 10); // Stringvariable positionieren
IPS_SetName($UIDID, "UID"); // Stringvariable benennen
IPS_SetParent($UIDID, $Parent); // Stringvariable einsortieren unter dem Objekt
}
SetValue($UIDID, $Entity["entity_id"]);
$TypeID = @IPS_GetObjectIDByName("Type", $Parent);
if ($TypeID == false){
$TypeID = IPS_CreateVariable(3); // Stringvariable anlegen
IPS_SetPosition($TypeID, 20); // Stringvariable positionieren
IPS_SetName($TypeID, "Type"); // Stringvariable benennen
IPS_SetParent($TypeID, $Parent); // Stringvariable einsortieren unter dem Objekt
}
SetValue($TypeID, $Entity["entity_type"]);
}
if (isset($Entity["options"]["kind"])){
$Kind = @IPS_GetObjectIDByName("Kind", $Parent);
if ($Kind == false){
$Kind = IPS_CreateVariable(3); // Stringvariable anlegen
IPS_SetPosition($Kind, 10); // Stringvariable positionieren
IPS_SetName($Kind, "Kind"); // Stringvariable benennen
IPS_SetParent($Kind, $Parent); // Stringvariable einsortieren unter dem Objekt
}
SetValue($Kind, $Entity["options"]["kind"]);
}
if (isset($Entity["features"])){
foreach ($Entity["features"] as $Feature){
$FeaturesID = @IPS_GetObjectIDByName("Features", $Parent);
if ($FeaturesID == false){
$FeaturesID = IPS_CreateVariable(3); // Stringvariable anlegen
IPS_SetPosition($FeaturesID, 30); // Stringvariable positionieren
IPS_SetName($FeaturesID, "Features"); // Stringvariable benennen
IPS_SetParent($FeaturesID, $Parent); // Stringvariable einsortieren unter dem Objekt
}
$Features = json_encode($Entity["features"]);
SetValue($FeaturesID, $Features);
}
}
if (isset($Entity["options"]["simple_commands"])){
$SimpleCommandsID = @IPS_GetObjectIDByName("SimpleCommands", $Parent);
if ($SimpleCommandsID == false){
$SimpleCommandsID = IPS_CreateVariable(3); // Stringvariable anlegen
IPS_SetPosition($SimpleCommandsID, 40); // Stringvariable positionieren
IPS_SetName($SimpleCommandsID, "SimpleCommands"); // Stringvariable benennen
IPS_SetParent($SimpleCommandsID, $Parent); // Stringvariable einsortieren unter dem Objekt
}
$SimpleCommands = json_encode($Entity["options"]["simple_commands"]);
SetValue($SimpleCommandsID, $SimpleCommands);
}
if ($Entity["entity_type"] == "macro"){
if (isset($Entity["options"]["sequence"])){
$MacrosID = @IPS_GetObjectIDByName("Commands", $Parent);
if ($MacrosID == false){
$MacrosID = IPS_CreateVariable(3); // Stringvariable anlegen
IPS_SetPosition($MacrosID, 50); // Stringvariable positionieren
IPS_SetName($MacrosID, "Commands"); // Stringvariable benennen
IPS_SetParent($MacrosID, $Parent); // Stringvariable einsortieren unter dem Objekt
}
$string = '';
foreach ($Entity["options"]["sequence"] as $Sequence){
if (isset($Sequence["command"])){
$string .= $Sequence["command"]["cmd_id"] . ' , ';
}
}
SetValue($MacrosID, $string);
}
}
$StateID = @IPS_GetObjectIDByName("State", $Parent);
if ($StateID == false){
$StateID = IPS_CreateVariable(3); // Stringvariable anlegen
IPS_SetPosition($StateID, 50); // Stringvariable positionieren
IPS_SetName($StateID, "State"); // Stringvariable benennen
IPS_SetParent($StateID, $Parent); // Stringvariable einsortieren unter dem Objekt
}
SetValue($StateID, $Entity["attributes"]["state"]);
GetFurtherInformation($Entity["entity_id"], $Parent, $IP2, $Key2);
}
}
// cURL-Session schließen
curl_close($ch);
}
function GetFurtherInformation($UID, $Parent, $IP, $Key){
$gfi = curl_init();
curl_setopt($gfi, CURLOPT_RETURNTRANSFER, true);
curl_setopt($gfi, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $Key,
'accept: application/json'
]);
curl_setopt($gfi, CURLOPT_URL, 'http://'.$IP.'/api/remotes/' . $UID);
$response = curl_exec($gfi);
$Infos = array();
$Infos = json_decode($response,true);
//var_dump($Infos);
if (isset($Infos["options"]["simple_commands"])){
$SimpleCommandsID = @IPS_GetObjectIDByName("Simple Commands", $Parent);
if ($SimpleCommandsID == false){
$SimpleCommandsID = IPS_CreateVariable(3); // Stringvariable anlegen
IPS_SetName($SimpleCommandsID, "Simple Commands"); // Stringvariable benennen
IPS_SetParent($SimpleCommandsID, $Parent); // Stringvariable einsortieren unter dem Objekt
}
$string = '';
foreach ($Infos["options"]["simple_commands"] as $SimpleCommand){
$string .= $SimpleCommand . ' , ';
}
SetValue($SimpleCommandsID, $string);
}
curl_close($gfi);
}
?>
Viel Spaß Ralf