Wie kann ich...?
Viele dieser Skripte verwenden spezielle IP-Symcon Funktionen.
Bitte nutzen Sie die Befehlsreferenz/Modulreferenz, wenn Sie die genaue Funktionsweise verstehen wollen.
... ein Gerät einschalten und nach z.B. 60 Sekunden wieder aussschalten?
if($_IPS['SENDER'] == "TimerEvent")
{
//Aus Befehl
...
//Timer ausschalten
IPS_SetScriptTimer($IPS_SELF, 0);
} else {
//An Befehl
...
//Timer anschalten
IPS_SetScriptTimer($IPS_SELF, 60);
}
... eine Liste der Modulnamen samt GUID bekommen?
foreach(IPS_GetModuleList
() as $mid){ $m = IPS_GetModule
($mid); echo $mid."=".$m['ModuleName']."\n";}
... eine Instanz aus PHP konfigurieren?
//Eigenschaft verändern
WWWReader_SetPage($id,"http://www.google.de");
//Änderung abspeichern
IPS_ApplyChanges($id);
//Neue URL abrufen
WWWReader_UpdatePage($id);
... die Anzahl der Sekunden herausfinden, die ein ScriptTimer noch abwartet?
echo GetTimeRemaining
($IPS_SELF); //Von sich selbst herausfindenfunction GetTimeRemaining
($id){ $eid=@IPS_GetEventIDByName
("ScriptTimer", $id); if($eid === false) { return -1; } else { $e=IPS_GetEvent
($eid); if($e['NextRun'] == 0) { return -1; } else { return $e['NextRun'] - microtime(true); } }}
... UpdateTime in einer eigenen String Variable ausgeben (1 Skript - n Variablen)
//Event auswertenif($IPS_SENDER != "Variable") return;SetValue
(CreateVariableIDByName
($IPS_VARIABLE, 'Updated', 3), date("d.m.y H:i:s"));function CreateVariableIDByName
($id, $name, $type){ 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"); } return $vid;}
... aus PHP einen Timer & Variable anlegen?
Wenn das Skript ausgeführt wird, legt es einen Timer an der alle 6 Stunden startet und dann eine Variable mit der jeweiligen Tageszeit als Wert zwischen 0-3 in die Variable ablegt.
//HINWEIS://~~~~~~~~//Dieses Script richtet sicht automatisch ein, wenn es ausgeführt wird////-> Es wird abhängig von der Tageszeit eine Variable gesetzt (0-3)// 0 = 0-6// 1 = 6-12// 2 = 12-18// 3 = 19-24//-----------------------------------------------------------------------------//Ab diesem Punkt muss nichts verändert werden//-----------------------------------------------------------------------------if($_IPS['SENDER'] == "Execute"){ $eventid = @IPS_GetEventIDByName
("Timer", $IPS_SELF); if($eventid === false) { $eventid = IPS_CreateEvent
(1); //Cyclic IPS_SetEventActive
($eventid, true); IPS_SetName
($eventid, "Timer"); IPS_SetEventScript
($eventid, $IPS_SELF); IPS_SetEventCyclic
($eventid, 0, 0, 0, 0, 3, 6); } $variableid = @IPS_GetVariableIDByName
("Daytime", $IPS_SELF); if($variableid === false) { $variableid = IPS_CreateVariable
(1); IPS_SetName
($variableid, "Daytime"); IPS_SetParent
($variableid, $IPS_SELF); }}SetValue
(IPS_GetVariableIDByName
("Daytime", $IPS_SELF), floor(date("H") / 6));
... eine Datei aus dem Internet herunterladen?
$remoteImage = "http://www.ipsymcon.de/images/smarthome200.jpg";$localImage = IPS_GetKernelDir
()."\\media\\bild.jpg";//Downloaden$content = @file_get_contents($remoteImage);if((strpos($http_response_header[0], "200") === false)) { return;}//Speichernfile_put_contents
( $localImage, $content );
... einen Ordner rekrusiv in die MediaPlayer Playlist laden?
function WAC_PlayDir
($id, $dir){ function ReadRecursive
($dir, $subdir = "") { $result = Array(); $files = scandir
($dir."/".$subdir); foreach($files as $file) { if(($file != ".") && ($file != "..")){ if(is_dir($dir."/".$subdir."/".$file)) { $res = ReadRecursive
($dir, $subdir."/".$file); $result = array_merge($res, $result); } else { $filedir = $subdir."/".$file; $filedir = substr($filedir, 1, strlen($filedir)); $result[] = $filedir; } } } return $result; } $allowed = Array("mp3", "wma"); $files = ReadRecursive
($dir);//Den Zufallsgenerator von PHP verwenden//shuffle($files); WAC_ClearPlaylist
($id); foreach($files as $file) { $ext = pathinfo($dir."/".$file, PATHINFO_EXTENSION
); if(in_array(strtolower($ext), $allowed)) { WAC_AddFile
($id, $dir."/".$file); } } WAC_Play
($id);}
... ein Variablenprofil exportieren?
getVariableProfileCreationCode
("~Temperature.FHT");getVariableProfileCreationCode
("~Temperature.FHT", "TemperatureTest");// erster Funktionsparameter: Profilname, zweiter Parameter (optional): neuer Profilnamefunction getVariableProfileCreationCode
($profileName, $newProfileName = ""){ $profile = IPS_GetVariableProfile
($profileName); if ($profile !== false) { $profileName = (strlen($newProfileName) > 0) ?
$newProfileName : $profileName; echo 'IPS_CreateVariableProfile("'.$profileName.'", '.$profile['ProfileType'].');'."\n"; echo 'IPS_SetVariableProfileText("'.$profileName.'", "'.$profile['Prefix'].'", "'.$profile['Suffix'].'");'."\n"; echo 'IPS_SetVariableProfileValues("'.$profileName.'", '.$profile['MinValue'].', '.$profile['MaxValue'].', '.$profile['StepSize'].');'."\n"; echo 'IPS_SetVariableProfileDigits("'.$profileName.'", '.$profile['Digits'].');'."\n"; echo 'IPS_SetVariableProfileIcon("'.$profileName.'", "'.$profile['Icon'].'");'."\n"; foreach ($profile['Associations'] as $association) { echo 'IPS_SetVariableProfileAssociation("'.$profileName.'", '.$association['Value'].', "'.$association['Name'].'", "'.$association['Icon'].'", "'.$association['Color'].'");'."\n"; } echo "\n"; }}