Na,
da habe ich was angerichtet, als NOP:D
Ich habe das damals mal versucht als install zu verpacken, bin aber erfreut, wenn Ihr es erweitert.
Die letzte Version (ist nicht alles drin ! :
<?
// Variablen-Definitionen
$VAR_Dummy ='Sony Bravia TV 2014';
$VAR_Profile ='Sony_TV';
$VAR_Profile2 ='Sony_Standby';
$VarNames[0] = array('name'=>'KanalNr', 'type'=>3, 'hidden'=>false, 'profil'=>'~String', 'position'=> -99, 'default_value'=>'',);
$VarNames[1] = array('name'=>'Kanal', 'type'=>3, 'hidden'=>false, 'profil'=>'~String', 'position'=> -98, 'default_value'=>'',);
$VarNames[2] = array('name'=>'Sendung', 'type'=>3, 'hidden'=>false, 'profil'=>'~String', 'position'=> -97, 'default_value'=>'',);
$VarNames[3] = array('name'=>'Sony_Tv', 'type'=>1, 'hidden'=>false, 'profil'=>$VAR_Profile, 'position'=> -100, 'default_value'=>0,);
$VarNames[4] = array('name'=>'Cookie', 'type'=>3, 'hidden'=>false, 'profil'=>'~String', 'position'=> -90, 'default_value'=>'',);
$VarNames[5] = array('name'=>'TVCode', 'type'=>3, 'hidden'=>false, 'profil'=>'~String', 'position'=> -91, 'default_value'=>'',);
$VarNames[6] = array('name'=>'my_device', 'type'=>3, 'hidden'=>false, 'profil'=>'~String', 'position'=> -96, 'default_value'=>'',);
$VarNames[7] = array('name'=>'my_nick', 'type'=>3, 'hidden'=>false, 'profil'=>'~String', 'position'=> -95, 'default_value'=>'',);
$VarNames[8] = array('name'=>'my_uuid', 'type'=>3, 'hidden'=>false, 'profil'=>'~String', 'position'=> -94, 'default_value'=>'',);
$VarNames[9] = array('name'=>'Tv-IP', 'type'=>3, 'hidden'=>false, 'profil'=>'~String', 'position'=> -93, 'default_value'=>'',);
$VarNames[10] = array('name'=>'Tv-MAC fur WOL', 'type'=>3, 'hidden'=>false, 'profil'=>'~String', 'position'=> -92, 'default_value'=>'',);
$VarNames[11] = array('name'=>'Status', 'type'=>1, 'hidden'=>false, 'profil'=>$VAR_Profile2, 'position'=> -92, 'default_value'=>0,);
// Skript-Definitionen
$SkriptNames[0] = array('name'=>'Anmeldung',);
$SkriptNames[1] = array('name'=>'Cookie holen',);
$SkriptNames[2] = array('name'=>'Kanal anzeigen',);
$SkriptNames[3] = array('name'=>'Sony FB',);
$SkriptNames[4] = array('name'=>'SonyAktion',);
$SkriptNames[5] = array('name'=>'Sony_Steuerung',);
$SkriptNames[6] = array('name'=>'Ping',);
function CreateScriptByName($ScriptNAME, $ParentID, $ScriptTEXT)
{
global $IPS_SELF,$ScriptID;
$ScriptID = @IPS_GetScriptIDByName($ScriptNAME, $ParentID);
if ($ScriptID == 0){
$ScriptID = IPS_CreateScript(0);
IPS_SetName($ScriptID, $ScriptNAME);
IPS_SetParent($ScriptID, $ParentID);
IPS_SetInfo($ScriptID, "This script was created by: #$IPS_SELF#");
$ScriptPath = $ScriptID.".ips.php"; //Skriptdatei
IPS_SetScriptFile($ScriptID, $ScriptPath);
IPS_SetHidden($ScriptID, false);
IPS_SetScriptContent($ScriptID, $ScriptTEXT);
}
}
// übergeordnete Instanz identifizieren
$Parent = IPS_GetParent($_IPS['SELF']);
$ParentModul = IPS_GetObject($Parent);
// Auto-Update (überprüft, ob alle Skripte im Baum vorhanden sind
for($i=0;$i<count($SkriptNames);$i++)
{
if(@IPS_GetObjectIDByName($SkriptNames[$i]['name'], IPS_GetParent($_IPS['SELF'])) == false)
{
$Update_s = true; // Update-Status auf true setzen
$i = 9999; // Abbruch der Schleife bei fehlendem Objekt
}
else
{
$Update_s = false; // alle Objekte vorhanden -> Update-Status auf false setzen
}
}
// Auto-Update (überprüft, ob alle Var's im Baum vorhanden sind
for($i=0;$i<count($VarNames);$i++)
{
if(@IPS_GetObjectIDByName($VarNames[$i]['name'], IPS_GetParent($_IPS['SELF'])) == false)
{
$Update_v = true; // Update-Status auf true setzen
$i = 9999; // Abbruch der Schleife bei fehlendem Objekt
}
else
{
$Update_v = false; // alle Objekte vorhanden -> Update-Status auf false setzen
}
}
if(($Update_s == true) or ($Update_v == true))
{
$Update = true; // Update-Status auf true setzen
$i = 9999; // Abbruch der Schleife bei fehlendem Objekt
}
else
{
$Update = false; // alle Objekte vorhanden -> Update-Status auf false setzen
}
// Sony Auswertelogik
if(($ParentModul['ObjectType'] == 1) && ($ParentModul['ObjectName'] == $VAR_Dummy) && ($Update == false))
{
// Variablen identifizieren
$KanalNr_ID = IPS_GetObjectIDByName($VarNames[0]['name'], IPS_GetParent($_IPS['SELF']));
$Kanal_ID = IPS_GetObjectIDByName($VarNames[1]['name'], IPS_GetParent($_IPS['SELF']));
$Sendung_ID = IPS_GetObjectIDByName($VarNames[2]['name'], IPS_GetParent($_IPS['SELF']));
$SonyTv_ID = IPS_GetObjectIDByName($VarNames[3]['name'], IPS_GetParent($_IPS['SELF']));
$my_device_ID = IPS_GetObjectIDByName($VarNames[6]['name'], IPS_GetParent($_IPS['SELF']));
$my_nick_ID = IPS_GetObjectIDByName($VarNames[7]['name'], IPS_GetParent($_IPS['SELF']));
$Tmy_uuid_ID = IPS_GetObjectIDByName($VarNames[8]['name'], IPS_GetParent($_IPS['SELF']));
$TV_MAC_ID = IPS_GetObjectIDByName($VarNames[9]['name'], IPS_GetParent($_IPS['SELF']));
$TV_IP_ID = IPS_GetObjectIDByName($VarNames[10]['name'], IPS_GetParent($_IPS['SELF']));
$Status_ID = IPS_GetObjectIDByName($VarNames[11]['name'], IPS_GetParent($_IPS['SELF']));
// IPS Werte auslesen
// $KanalNr = getValueString($KanalNr_ID);
// $Kanal_ID = getValueString($Kanal_ID);
// $Sendung_ID = getValueString($Sendung_ID);
}
#######################################################################################################################################
// Install-Routinen
elseif($_IPS['SENDER'] == 'Execute')
{
// Profil Sony_TV anlegen
if (IPS_VariableProfileExists($VAR_Profile)) IPS_DeleteVariableProfile($VAR_Profile);
IPS_CreateVariableProfile($VAR_Profile, 1);
IPS_SetVariableProfileValues($VAR_Profile, 0, 0, 0); //PName, Minimal, Maximal, Schrittweite
IPS_SetVariableProfileAssociation($VAR_Profile, 0, "PowerOn", "", 0); //P-Name, Value, Assotiation, Icon, Color
IPS_SetVariableProfileAssociation($VAR_Profile, 1, "PowerOff", "", 0); //P-Name, Value, Assotiation, Icon, Color
IPS_SetVariableProfileAssociation($VAR_Profile, 2, "Red", "", 0xFF0000); //P-Name, Value, Assotiation, Icon, Color
IPS_SetVariableProfileAssociation($VAR_Profile, 3, "Green", "", 0x00FF00); //P-Name, Value, Assotiation, Icon, Color
IPS_SetVariableProfileAssociation($VAR_Profile, 4, "Yellow", "", 0xFFFF00); //P-Name, Value, Assotiation, Icon, Color
IPS_SetVariableProfileAssociation($VAR_Profile, 5, "Blue", "", 0x0000FF); //P-Name, Value, Assotiation, Icon, Color
IPS_SetVariableProfileAssociation($VAR_Profile, 6, "Up", "", 0); //P-Name, Value, Assotiation, Icon, Color
IPS_SetVariableProfileAssociation($VAR_Profile, 7, "Left", "", 0); //P-Name, Value, Assotiation, Icon, Color
IPS_SetVariableProfileAssociation($VAR_Profile, 8, "Right", "", 0); //P-Name, Value, Assotiation, Icon, Color
IPS_SetVariableProfileAssociation($VAR_Profile, 9, "Down", "", 0); //P-Name, Value, Assotiation, Icon, Color
IPS_SetVariableProfileAssociation($VAR_Profile, 10, "OK", "", 0); //P-Name, Value, Assotiation, Icon, Color
IPS_SetVariableProfileAssociation($VAR_Profile, 11, "?", "", 0); //P-Name, Value, Assotiation, Icon, Color
IPS_SetVariableProfileAssociation($VAR_Profile, 12, "Vol+", "", 0); //P-Name, Value, Assotiation, Icon, Color
IPS_SetVariableProfileAssociation($VAR_Profile, 13, "Vol-", "", 0); //P-Name, Value, Assotiation, Icon, Color
IPS_SetVariableProfileAssociation($VAR_Profile, 14, "Mute", "", 0); //P-Name, Value, Assotiation, Icon, Color
IPS_SetVariableProfileAssociation($VAR_Profile, 15, "1", "", 0); //P-Name, Value, Assotiation, Icon, Color
IPS_SetVariableProfileAssociation($VAR_Profile, 16, "2", "", 0); //P-Name, Value, Assotiation, Icon, Color
IPS_SetVariableProfileAssociation($VAR_Profile, 17, "3", "", 0); //P-Name, Value, Assotiation, Icon, Color
IPS_SetVariableProfileAssociation($VAR_Profile, 18, "4", "", 0); //P-Name, Value, Assotiation, Icon, Color
IPS_SetVariableProfileAssociation($VAR_Profile, 19, "5", "", 0); //P-Name, Value, Assotiation, Icon, Color
IPS_SetVariableProfileAssociation($VAR_Profile, 20, "6", "", 0); //P-Name, Value, Assotiation, Icon, Color
IPS_SetVariableProfileAssociation($VAR_Profile, 21, "7", "", 0); //P-Name, Value, Assotiation, Icon, Color
IPS_SetVariableProfileAssociation($VAR_Profile, 22, "8", "", 0); //P-Name, Value, Assotiation, Icon, Color
IPS_SetVariableProfileAssociation($VAR_Profile, 23, "9", "", 0); //P-Name, Value, Assotiation, Icon, Color
IPS_SetVariableProfileAssociation($VAR_Profile, 24, "0", "", 0); //P-Name, Value, Assotiation, Icon, Color
IPS_SetVariableProfileAssociation($VAR_Profile, 25, "Exit", "", 0); //P-Name, Value, Assotiation, Icon, Color
IPS_SetVariableProfileAssociation($VAR_Profile, 26, "?", "", 0); //P-Name, Value, Assotiation, Icon, Color
if (IPS_VariableProfileExists($VAR_Profile2)) IPS_DeleteVariableProfile($VAR_Profile2);
IPS_CreateVariableProfile($VAR_Profile2, 1);
IPS_SetVariableProfileValues($VAR_Profile2, 0, 0, 0); //PName, Minimal, Maximal, Schrittweite
IPS_SetVariableProfileAssociation($VAR_Profile2, 0, "Off", "", 0xFF0000); //P-Name, Value, Assotiation, Icon, Color
IPS_SetVariableProfileAssociation($VAR_Profile2, 2, "On", "", 0x00FF00); //P-Name, Value, Assotiation, Icon, Color
IPS_SetVariableProfileAssociation($VAR_Profile2, 1, "Standby", "", 0xFFFF00); //P-Name, Value, Assotiation, Icon, Color
if((($ParentModul['ObjectType'] != 1) && ($ParentModul['ObjectName'] != $VAR_Dummy)) || ($Update == true))
{
if(($ParentModul['ObjectType'] != 1) && ($ParentModul['ObjectName'] != $VAR_Dummy))
{
// Dummy-Instanz anlegen und Script drunterhängen
$ModulID = IPS_CreateInstance("{485D0419-BE97-4548-AA9C-C083EB82E61E}");
IPS_SetName($ModulID, $VAR_Dummy);
IPS_SetParent($ModulID, $Parent);
IPS_SetParent($_IPS['SELF'], $ModulID);
IPS_SetHidden($_IPS['SELF'], true);
IPS_ApplyChanges($ModulID);
}
///////////////////////////////////////////////////////////////////////
// Skripte anlegen
$Aktion ='<?
if($_IPS["SENDER"] == "WebFront")
{
SetValue($_IPS["VARIABLE"], $_IPS["VALUE"]);
}
?>';
CreateScriptByName('SonyAktion',IPS_GetParent($_IPS['SELF']),$Aktion);
IPS_SetHidden($ScriptID, true);
$aktion_skript=$ScriptID;
////////////////////////////////////////////////////////////////////////////////
$Sony_text='<?
$Parent = IPS_GetParent($_IPS[\'SELF\']);
$ParentModul = IPS_GetObject($Parent);
// Variablen identifizieren
$Cookie_ID = IPS_GetObjectIDByName(\'Cookie\', IPS_GetParent($_IPS[\'SELF\']));
$tv_ip_ID = IPS_GetObjectIDByName(\'Tv-IP\', IPS_GetParent($_IPS[\'SELF\']));
$mac_ID = IPS_GetObjectIDByName(\'Tv-MAC fur WOL\', IPS_GetParent($_IPS[\'SELF\']));
// IPS Werte auslesen
$cookie=getValueString($Cookie_ID);
$tvip=getValueString($tv_ip_ID);
$mac=getValueString($mac_ID);
$addr=\'255.255.255.255\';
$did = 1;
$controllerinfo = json_decode(\'{"id":10,"result":[{"bundled":true,"type":"RM-J1100"}
,[{"name":"PowerOff","value":"AAAAAQAAAAEAAAAvAw=="}
,{"name":"Input","value":"AAAAAQAAAAEAAAAlAw=="}
,{"name":"GGuide","value":"AAAAAQAAAAEAAAAOAw=="}
,{"name":"EPG","value":"AAAAAgAAAKQAAABbAw=="}
,{"name":"Favorites","value":"AAAAAgAAAHcAAAB2Aw=="}
,{"name":"Display","value":"AAAAAQAAAAEAAAA6Aw=="}
,{"name":"Home","value":"AAAAAQAAAAEAAABgAw=="}
,{"name":"Options","value":"AAAAAgAAAJcAAAA2Aw=="}
,{"name":"Return","value":"AAAAAgAAAJcAAAAjAw=="}
,{"name":"Up","value":"AAAAAQAAAAEAAAB0Aw=="}
,{"name":"Down","value":"AAAAAQAAAAEAAAB1Aw=="}
,{"name":"Right","value":"AAAAAQAAAAEAAAAzAw=="}
,{"name":"Left","value":"AAAAAQAAAAEAAAA0Aw=="}
,{"name":"Confirm","value":"AAAAAQAAAAEAAABlAw=="}
,{"name":"Red","value":"AAAAAgAAAJcAAAAlAw=="}
,{"name":"Green","value":"AAAAAgAAAJcAAAAmAw=="}
,{"name":"Yellow","value":"AAAAAgAAAJcAAAAnAw=="}
,{"name":"Blue","value":"AAAAAgAAAJcAAAAkAw=="}
,{"name":"Num1","value":"AAAAAQAAAAEAAAAAAw=="}
,{"name":"Num2","value":"AAAAAQAAAAEAAAABAw=="}
,{"name":"Num3","value":"AAAAAQAAAAEAAAACAw=="}
,{"name":"Num4","value":"AAAAAQAAAAEAAAADAw=="}
,{"name":"Num5","value":"AAAAAQAAAAEAAAAEAw=="}
,{"name":"Num6","value":"AAAAAQAAAAEAAAAFAw=="}
,{"name":"Num7","value":"AAAAAQAAAAEAAAAGAw=="}
,{"name":"Num8","value":"AAAAAQAAAAEAAAAHAw=="}
,{"name":"Num9","value":"AAAAAQAAAAEAAAAIAw=="}
,{"name":"Num0","value":"AAAAAQAAAAEAAAAJAw=="}
,{"name":"Num11","value":"AAAAAQAAAAEAAAAKAw=="}
,{"name":"Num12","value":"AAAAAQAAAAEAAAALAw=="}
,{"name":"VolumeUp","value":"AAAAAQAAAAEAAAASAw=="}
,{"name":"VolumeDown","value":"AAAAAQAAAAEAAAATAw=="}
,{"name":"Mute","value":"AAAAAQAAAAEAAAAUAw=="}
,{"name":"ChannelUp","value":"AAAAAQAAAAEAAAAQAw=="}
,{"name":"ChannelDown","value":"AAAAAQAAAAEAAAARAw=="}
,{"name":"SubTitle","value":"AAAAAgAAAJcAAAAoAw=="}
,{"name":"ClosedCaption","value":"AAAAAgAAAKQAAAAQAw=="}
,{"name":"Enter","value":"AAAAAQAAAAEAAAALAw=="}
,{"name":"DOT","value":"AAAAAgAAAJcAAAAdAw=="}
,{"name":"Analog","value":"AAAAAgAAAHcAAAANAw=="}
,{"name":"Teletext","value":"AAAAAQAAAAEAAAA/Aw=="}
,{"name":"Exit","value":"AAAAAQAAAAEAAABjAw=="}
,{"name":"Analog2","value":"AAAAAQAAAAEAAAA4Aw=="}
,{"name":"*AD","value":"AAAAAgAAABoAAAA7Aw=="}
,{"name":"Digital","value":"AAAAAgAAAJcAAAAyAw=="}
,{"name":"Analog?","value":"AAAAAgAAAJcAAAAuAw=="}
,{"name":"BS","value":"AAAAAgAAAJcAAAAsAw=="}
,{"name":"CS","value":"AAAAAgAAAJcAAAArAw=="}
,{"name":"BSCS","value":"AAAAAgAAAJcAAAAQAw=="}
,{"name":"Ddata","value":"AAAAAgAAAJcAAAAVAw=="}
,{"name":"PicOff","value":"AAAAAQAAAAEAAAA+Aw=="}
,{"name":"Tv_Radio","value":"AAAAAgAAABoAAABXAw=="}
,{"name":"Theater","value":"AAAAAgAAAHcAAABgAw=="}
,{"name":"SEN","value":"AAAAAgAAABoAAAB9Aw=="}
,{"name":"InternetWidgets","value":"AAAAAgAAABoAAAB6Aw=="}
,{"name":"InternetVideo","value":"AAAAAgAAABoAAAB5Aw=="}
,{"name":"Netflix","value":"AAAAAgAAABoAAAB8Aw=="}
,{"name":"SceneSelect","value":"AAAAAgAAABoAAAB4Aw=="}
,{"name":"Mode3D","value":"AAAAAgAAAHcAAABNAw=="}
,{"name":"iManual","value":"AAAAAgAAABoAAAB7Aw=="}
,{"name":"Audio","value":"AAAAAQAAAAEAAAAXAw=="}
,{"name":"Wide","value":"AAAAAgAAAKQAAAA9Aw=="}
,{"name":"Jump","value":"AAAAAQAAAAEAAAA7Aw=="}
,{"name":"PAP","value":"AAAAAgAAAKQAAAB3Aw=="}
,{"name":"MyEPG","value":"AAAAAgAAAHcAAABrAw=="}
,{"name":"ProgramDescription","value":"AAAAAgAAAJcAAAAWAw=="}
,{"name":"WriteChapter","value":"AAAAAgAAAHcAAABsAw=="}
,{"name":"TrackID","value":"AAAAAgAAABoAAAB+Aw=="}
,{"name":"TenKey","value":"AAAAAgAAAJcAAAAMAw=="}
,{"name":"AppliCast","value":"AAAAAgAAABoAAABvAw=="}
,{"name":"acTVila","value":"AAAAAgAAABoAAAByAw=="}
,{"name":"DeleteVideo","value":"AAAAAgAAAHcAAAAfAw=="}
,{"name":"PhotoFrame","value":"AAAAAgAAABoAAABVAw=="}
,{"name":"TvPause","value":"AAAAAgAAABoAAABnAw=="}
,{"name":"KeyPad","value":"AAAAAgAAABoAAAB1Aw=="}
,{"name":"Media","value":"AAAAAgAAAJcAAAA4Aw=="}
,{"name":"SyncMenu","value":"AAAAAgAAABoAAABYAw=="}
,{"name":"Forward","value":"AAAAAgAAAJcAAAAcAw=="}
,{"name":"Play","value":"AAAAAgAAAJcAAAAaAw=="}
,{"name":"Rewind","value":"AAAAAgAAAJcAAAAbAw=="}
,{"name":"Prev","value":"AAAAAgAAAJcAAAA8Aw=="}
,{"name":"Stop","value":"AAAAAgAAAJcAAAAYAw=="}
,{"name":"Next","value":"AAAAAgAAAJcAAAA9Aw=="}
,{"name":"Rec","value":"AAAAAgAAAJcAAAAgAw=="}
,{"name":"Pause","value":"AAAAAgAAAJcAAAAZAw=="}
,{"name":"Eject","value":"AAAAAgAAAJcAAABIAw=="}
,{"name":"FlashPlus","value":"AAAAAgAAAJcAAAB4Aw=="}
,{"name":"FlashMinus","value":"AAAAAgAAAJcAAAB5Aw=="}
,{"name":"TopMenu","value":"AAAAAgAAABoAAABgAw=="}
,{"name":"PopUpMenu","value":"AAAAAgAAABoAAABhAw=="}
,{"name":"RakurakuStart","value":"AAAAAgAAAHcAAABqAw=="}
,{"name":"OneTouchTimeRec","value":"AAAAAgAAABoAAABkAw=="}
,{"name":"OneTouchView","value":"AAAAAgAAABoAAABlAw=="}
,{"name":"OneTouchRec","value":"AAAAAgAAABoAAABiAw=="}
,{"name":"OneTouchStop","value":"AAAAAgAAABoAAABjAw=="}
,{"name":"DUX","value":"AAAAAgAAABoAAABzAw=="}
,{"name":"FootballMode","value":"AAAAAgAAABoAAAB2Aw=="}
,{"name":"Social","value":"AAAAAgAAABoAAAB0Aw=="}
] ]}\',true);
$codes = array();
foreach($controllerinfo[\'result\'] as $k => $v) {
foreach($v as $code) {
if (isset($code[\'name\'])) {
$codes[$code[\'name\']] = $code[\'value\'];
}
}
}
function sendCommand($key) {
global $codes;
$data = \'<?xml version="1.0"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>\';
$data .= \'<u:X_SendIRCC xmlns:u="urn:schemas-sony-com:service:IRCC:1">
<IRCCCode>\'.$codes[$key].\'</IRCCCode>
</u:X_SendIRCC>\';
$data .= \'</s:Body>
</s:Envelope>\';
sendCurlPost(\'/sony/IRCC\',$data);
}
function sendCurlPost($url,$data, $auth = false) {
global $cookie, $tvip;
$headers = array();
// $cookie = "auth=e708c3f8033c42f46681c01aa5155eb451f00c88bb7969a2380a9c31eaabb48f";
$headers[] = "Cookie: " . $cookie;
$headers[] = "Content-Type: text/xml; charset=UTF-8";
$headers[] = "Content-Length: " . strlen($data);
$ch = curl_init(\'http://\'. $tvip . $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
return curl_exec($ch);
}
function WakeOnLan($mac, $addr) {
$addr_byte = explode(\':\', $mac);
$hw_addr = \'\';
for ($a=0; $a < 6; $a++) $hw_addr .= chr(hexdec($addr_byte[$a]));
$msg = chr(255).chr(255).chr(255).chr(255).chr(255).chr(255);
for ($a = 1; $a <= 16; $a++) $msg .= $hw_addr;
$s = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
if ($s == false) {
echo "Error creating socket!
";
echo "Error code is \'".socket_last_error($s)."\' - " . socket_strerror(socket_last_error($s));
return false;
} else {
$opt_ret = socket_set_option($s, 1, 6, TRUE);
if($opt_ret < 0) {
echo "setsockopt() failed, error: " . strerror($opt_ret) . "
";
return false;
}
$e = socket_sendto($s, $msg, strlen($msg), 0, $addr, 2050);
socket_close($s);
return true;
}
}
?>';
CreateScriptByName('Sony_Steuerung',IPS_GetParent($_IPS['SELF']),$Sony_text);
IPS_SetHidden($ScriptID, true);
$aktion_steuerung=$ScriptID;
////////////////////////////////////////////////////////////////////////////////
$Sony_text='<?
$Parent = IPS_GetParent($_IPS[\'SELF\']);
$ParentModul = IPS_GetObject($Parent);
// Variablen identifizieren
$tv_ip_ID = IPS_GetObjectIDByName(\'Sony_Steuerung\', IPS_GetParent($_IPS[\'SELF\']));
include IPS_GetKernelDir().\'scripts/\'.$tv_ip_ID.\'.ips.php\';
$addr = "255.255.255.255"; // Broadcast adresse für WOL
$_befehl = "";
if($_IPS["SENDER"] == "WebFront")
{
SetValue($_IPS["VARIABLE"], $_IPS["VALUE"]);
// print($_IPS["Value"]);
}
$_control = ($_IPS["VALUE"]);
if ($_control === 0){
WakeOnLan($mac, $addr);
} else
{
if ($_control === 1) ($_befehl="PowerOff");
if ($_control === 2) ($_befehl="Red" );
if ($_control === 3) ($_befehl="Green" );
if ($_control === 4) ($_befehl="Yellow" );
if ($_control === 5) ($_befehl="Blue" );
if ($_control === 6) ($_befehl="Up" );
if ($_control === 7) ($_befehl="Left" );
if ($_control === 8) ($_befehl="Right" );
if ($_control === 9) ($_befehl="Down" );
if ($_control === 10)($_befehl="Confirm" );
if ($_control === 11)($_befehl="" );
if ($_control === 12)($_befehl="VolumeDown" );
if ($_control === 13)($_befehl="VolumeUp" );
if ($_control === 14)($_befehl="Mute" );
if ($_control === 15)($_befehl="Num1" );
if ($_control === 16)($_befehl="Num2" );
if ($_control === 17)($_befehl="Num3" );
if ($_control === 18)($_befehl="Num4" );
if ($_control === 19)($_befehl="Num5" );
if ($_control === 20)($_befehl="Num6" );
if ($_control === 21)($_befehl="Num7" );
if ($_control === 22)($_befehl="Num8" );
if ($_control === 23)($_befehl="Num9" );
if ($_control === 24)($_befehl="Num0" );
if ($_control === 25)($_befehl="Exit" );
if ($_control === 26)($_befehl="" );
sendCommand($_befehl);
}
?>';
CreateScriptByName('Sony FB',IPS_GetParent($_IPS['SELF']),$Sony_text);
IPS_SetHidden($ScriptID, true);
$aktion_FB=$ScriptID;
$Sony_text='<?
$Parent = IPS_GetParent($_IPS[\'SELF\']);
$ParentModul = IPS_GetObject($Parent);
// Variablen identifizieren
$tv_ip_ID = IPS_GetObjectIDByName(\'Tv-IP\', IPS_GetParent($_IPS[\'SELF\']));
$my_device_ID = IPS_GetObjectIDByName(\'my_device\', IPS_GetParent($_IPS[\'SELF\']));
$my_nick_ID = IPS_GetObjectIDByName(\'my_nick\', IPS_GetParent($_IPS[\'SELF\']));
$my_uuid_ID = IPS_GetObjectIDByName(\'my_uuid\', IPS_GetParent($_IPS[\'SELF\']));
$TVCode_ID = IPS_GetObjectIDByName(\'TVCode\', IPS_GetParent($_IPS[\'SELF\']));
$Cookie_ID = IPS_GetObjectIDByName(\'Cookie\', IPS_GetParent($_IPS[\'SELF\']));
// IPS Werte auslesen
// IPS Werte auslesen
$tv_ip=getValueString($tv_ip_ID);
$my_device=GetValueString ($my_device_ID);
$my_nick=GetValueString ($my_nick_ID );
$my_uuid=GetValueString ($my_uuid_ID );
$TVCode=GetValueString ($TVCode_ID );
$cookie= getValueString($Cookie_ID);
# use only A-Z a-z 0-9 for device. Probably. Havent checked.
// Start anlernen
$url =\'/sony/accessControl\';
$data=\'{"method":"actRegister","params":[{"clientid":"\'.$my_nick.\':\'.$my_uuid.\'","nickname":"\'.$my_nick.\' (\'.$my_device.\')","level":"private"},[{"value":"yes","function":"WOL"}]],"id":8,"version":"1.0"}\';
$ch = curl_init(\'http://\'. $tv_ip . $url);
curl_setopt($ch, CURLOPT_USERAGENT,"curl 7.26.0");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
$ausgabe = curl_exec($ch);
curl_close($ch);
//echo $ausgabe.chr(10);
// Hier auf Eingabe vom Code warten (WebFront)
$tv_key =\'Neu\';
SetValueString ($TVCode_ID , $tv_key);
$i = 0;
while( $tv_key === \'Neu\')
{
$tv_key=GetValueString ($TVCode_ID);
// echo $tv_key;
IPS_sleep(1000);
$i++;
if( $i == 40 )break;
}
// Key senden
$tv_key=GetValueString ($TVCode_ID);
//echo $tv_key;
$tv_key=\':\'.$tv_key;
$tv_challenge = base64_encode($tv_key);
$tv_auth_header=\'Authorization: Basic \'.$tv_challenge;
//echo $tv_auth_header.chr(10);
$headers = array();
$headers[]=$tv_auth_header;
$ch = curl_init(\'http://\'. $tv_ip . $url);
curl_setopt($ch, CURLOPT_USERAGENT,"curl 7.26.0");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HEADER, true);
$ausgabe = curl_exec($ch);
//echo $ausgabe.chr(10);
curl_close($ch);
list($headers, $response) = explode("
", $ausgabe, 2);
$headers = explode("
", $headers);
foreach($headers as $header) {
if (stripos($header, \'Set-Cookie:\') !== false) {
// echo $header.chr(10);
$header = substr($header,0,strpos($header,";"));
$auth = strstr($header, "a");
// echo $auth;
SetValueString ($Cookie_ID , $auth );
}
}
?>';
CreateScriptByName('Anmeldung',IPS_GetParent($_IPS['SELF']),$Sony_text);
//$aktion_FB=$ScriptID;
$Sony_text='<?
$Parent = IPS_GetParent($_IPS[\'SELF\']);
$ParentModul = IPS_GetObject($Parent);
// Variablen identifizieren
$Cookie_ID = IPS_GetObjectIDByName(\'Cookie\', IPS_GetParent($_IPS[\'SELF\']));
$tv_ip_ID = IPS_GetObjectIDByName(\'Tv-IP\', IPS_GetParent($_IPS[\'SELF\']));
$mac_ID = IPS_GetObjectIDByName(\'Tv-MAC fur WOL\', IPS_GetParent($_IPS[\'SELF\']));
$KanalNr_ID = IPS_GetObjectIDByName(\'KanalNr\', IPS_GetParent($_IPS[\'SELF\']));
$Kanal_ID = IPS_GetObjectIDByName(\'Kanal\', IPS_GetParent($_IPS[\'SELF\']));
$Sendung_ID = IPS_GetObjectIDByName(\'Sendung\', IPS_GetParent($_IPS[\'SELF\']));
// IPS Werte auslesen
$cookie=getValueString($Cookie_ID);
$tv_ip=getValueString($tv_ip_ID);
$mac=getValueString($mac_ID);
$url =\'/sony/avContent\';
$data = \'{"method":"getPlayingContentInfo","params":[""],"id":1,"version":"1.0"}\';
$headers = array();
$headers[] = "Cookie: " . $cookie;
$ch = curl_init(\'http://\'. $tv_ip . $url);
curl_setopt($ch, CURLOPT_USERAGENT,"curl 7.26.0");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HEADER, false); //Header abgeschaltet
$ausgabe = curl_exec($ch);
//echo $ausgabe.chr(10);
curl_close($ch);
$error = 0;
$json_a = json_decode($ausgabe,true);
if (isset($json_a["error"])) {
SetValueString($Kanal_ID ,$json_a["error"][1]);
SetValueString($Sendung_ID ,\' \');
SetValueString($KanalNr_ID ,\' \');
}
else
{
//echo $json_a["result"][0]["programTitle"];
//echo $json_a["result"][0]["title"];
SetValueString($Kanal_ID , utf8_decode($json_a["result"][0]["title"]));
SetValueString($Sendung_ID ,utf8_decode($json_a["result"][0]["programTitle"]));
SetValueString($KanalNr_ID ,utf8_decode($json_a["result"][0]["dispNum"]));
}
?>';
CreateScriptByName('Kanal anzeigen',IPS_GetParent($_IPS['SELF']),$Sony_text);
//$aktion_FB=$ScriptID;
$Sony_text='<?
$Parent = IPS_GetParent($_IPS[\'SELF\']);
$ParentModul = IPS_GetObject($Parent);
// Variablen identifizieren
$tv_ip_ID = IPS_GetObjectIDByName(\'Tv-IP\', IPS_GetParent($_IPS[\'SELF\']));
$my_device_ID = IPS_GetObjectIDByName(\'my_device\', IPS_GetParent($_IPS[\'SELF\']));
$my_nick_ID = IPS_GetObjectIDByName(\'my_nick\', IPS_GetParent($_IPS[\'SELF\']));
$my_uuid_ID = IPS_GetObjectIDByName(\'my_uuid\', IPS_GetParent($_IPS[\'SELF\']));
$TVCode_ID = IPS_GetObjectIDByName(\'TVCode\', IPS_GetParent($_IPS[\'SELF\']));
$Cookie_ID = IPS_GetObjectIDByName(\'Cookie\', IPS_GetParent($_IPS[\'SELF\']));
// IPS Werte auslesen
// IPS Werte auslesen
$tv_ip=getValueString($tv_ip_ID);
$my_device=GetValueString ($my_device_ID);
$my_nick=GetValueString ($my_nick_ID );
$my_uuid=GetValueString ($my_uuid_ID );
$TVCode=GetValueString ($TVCode_ID );
$cookie= getValueString($Cookie_ID);
// Start anlernen
$url =\'/sony/accessControl\';
//[["actRegister",["{\"clientid\":\"string\",\"nickname\":\"string\",\"level\":\"string\"}","{\"function\":\"string\",\"value\":\"string\"}*"],[],"1.0"],["getMethodTypes",["string"],["string","string*","string*","string"],"1.0"],["getVersions",[],["string*"],"1.0"]]}
$data=\'{"method":"actRegister","params":[{"clientid":"\'.$my_nick.\':\'.$my_uuid.\'","nickname":"\'.$my_nick.\' (\'.$my_device.\')","level":"private"},[{"value":"yes","function":"WOL"}]],"id":8,"version":"1.0"}\';
$headers = array();
$ch = curl_init(\'http://\'. $tv_ip . $url);
curl_setopt($ch, CURLOPT_USERAGENT,"curl 7.26.0");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HEADER, true);
$ausgabe = curl_exec($ch);
//echo $ausgabe.chr(10);
curl_close($ch);
$json_a = json_decode($ausgabe,true);
//var_dump ($json_a);
if (isset($json_a["error"])) {
}
else
{
list($headers, $response) = explode("
", $ausgabe, 2);
$headers = explode("
", $headers);
foreach($headers as $header) {
if (stripos($header, \'Set-Cookie:\') !== false) {
// echo $header.chr(10);
$header = substr($header,0,strpos($header,";"));
$auth = strstr($header, "a");
// echo $auth;
SetValueString ($Cookie_ID , $auth );
}
}
}
?>';
CreateScriptByName('Cookie holen',IPS_GetParent($_IPS['SELF']),$Sony_text);
$Sony_text='<?
$Parent = IPS_GetParent($_IPS[\'SELF\']);
$ParentModul = IPS_GetObject($Parent);
// Variablen identifizieren
global $skript_ID;
$skript_ID = IPS_GetObjectIDByName(\'Kanal anzeigen\', IPS_GetParent($_IPS[\'SELF\']));
//var_dump($skript_ID);
// Variablen identifizieren
$tv_ip_ID = IPS_GetObjectIDByName(\'Tv-IP\', IPS_GetParent($_IPS[\'SELF\']));
$status_ID = IPS_GetObjectIDByName(\'Status\', IPS_GetParent($_IPS[\'SELF\']));
$kanal_ID = IPS_GetObjectIDByName(\'Kanal\', IPS_GetParent($_IPS[\'SELF\']));
$tvip=getValueString($tv_ip_ID);
//IPS_RunScript($skript_ID);
function ping($host,$port=80,$timeout=1)
{
$fsock = @fsockopen($host, $port, $errno, $errstr, $timeout);
if ( ! $fsock )
{
return false;;
}
else
{
return true;
}
}
$up=ping($tvip);
if ($up == false) {
SetValue($status_ID , 0);
}
else {
IPS_RunScript($skript_ID);
$inhalt=getValueString($kanal_ID);
//var_dump ($inhalt);
if ($inhalt == "not power-on") {
SetValue($status_ID , 1);
}
else
{
SetValue($status_ID , 2);
}
}
?>';
CreateScriptByName('Ping',IPS_GetParent($_IPS['SELF']),$Sony_text);
IPS_SetHidden($ScriptID, true);
IPS_SetScriptTimer($ScriptID, 5);
///////////////////////////////////////////////////////////////////////////////
// Variablen anlegen - wenn nicht vorhanden
// 1. vorhandene Vars auslesen
$ModulID = IPS_GetParent($_IPS['SELF']);
for($i=0;$i<count($VarNames);$i++)
{
if(@IPS_GetObjectIDByName($VarNames[$i]['name'], IPS_GetParent($_IPS['SELF'])) == false)
{
$VarID = IPS_CreateVariable($VarNames[$i]['type']);
IPS_SetName($VarID, $VarNames[$i]['name']);
IPS_SetHidden($VarID, $VarNames[$i]['hidden']);
IPS_SetPosition($VarID, $VarNames[$i]['position']);
IPS_SetParent($VarID, $ModulID);
SetValue($VarID, $VarNames[$i]['default_value']);
}
// Profile zuweisen
$VarID = IPS_GetObjectIDByName($VarNames[$i]['name'], IPS_GetParent($_IPS['SELF']));
IPS_SetVariableCustomProfile($VarID, $VarNames[$i]['profil']);
// Aktion zuweisen
IPS_SetVariableCustomAction($VarID,$aktion_skript);
}
$my_device_ID = IPS_GetObjectIDByName($VarNames[6]['name'], IPS_GetParent($_IPS['SELF']));
$my_nick_ID = IPS_GetObjectIDByName($VarNames[7]['name'], IPS_GetParent($_IPS['SELF']));
$my_uuid_ID = IPS_GetObjectIDByName($VarNames[8]['name'], IPS_GetParent($_IPS['SELF']));
$TV_MAC_ID = IPS_GetObjectIDByName($VarNames[9]['name'], IPS_GetParent($_IPS['SELF']));
$TV_IP_ID = IPS_GetObjectIDByName($VarNames[10]['name'], IPS_GetParent($_IPS['SELF']));
SetValueString ($my_device_ID , 'BananaPi2' );
SetValueString ($my_nick_ID , 'IPS' );
SetValueString ($my_uuid_ID , '17' );
SetValueString ($TV_MAC_ID , '192.168.1.61' );
SetValueString ($TV_IP_ID , 'FC:F1:52:72:7E:A3' );
$KanalNr_ID = IPS_GetObjectIDByName($VarNames[0]['name'], IPS_GetParent($_IPS['SELF']));
$Kanal_ID = IPS_GetObjectIDByName($VarNames[1]['name'], IPS_GetParent($_IPS['SELF']));
$Sendung_ID = IPS_GetObjectIDByName($VarNames[2]['name'], IPS_GetParent($_IPS['SELF']));
$Status_ID = IPS_GetObjectIDByName($VarNames[11]['name'], IPS_GetParent($_IPS['SELF']));
$SonyTv_ID = IPS_GetObjectIDByName($VarNames[3]['name'], IPS_GetParent($_IPS['SELF']));
$Cookie_ID = IPS_GetObjectIDByName($VarNames[4]['name'], IPS_GetParent($_IPS['SELF']));
IPS_SetVariableCustomAction($SonyTv_ID,$aktion_FB);
IPS_SetVariableCustomAction($KanalNr_ID,0);
IPS_SetVariableCustomAction($Kanal_ID,0);
IPS_SetVariableCustomAction($Sendung_ID,0);
IPS_SetVariableCustomAction($Status_ID,0);
IPS_SetVariableCustomAction($Cookie_ID,0);
}
echo "#9999 IPS Sony: Install ready (neue Objekte angelegt)
";
}
else
{
echo "Script #".$_IPS['SELF']." Sony: ohne Ergebnis gelaufen (keine Objekte gefunden/Objekte fehlerhaft
";
}
?>
Bitte verbessern !
Habe im Moment zu viele andere private Baustellen…:mad:
Rest per Mail oder Lifezugrif nach Absprache …