Das folgende Skript ermöglicht ViewJet-Besitzern das menüartiges Anzeigen von Variablen und Skripten und ggf. das Ausführen und Verändern dieser ganz ohne Skriptkonfiguration.
How To Do: Anleitung mit SWF - Filmen
<?php
/*
* =================== ViewJet Anzeige- und Kontroll-Skript ===================
*
* erforderlich: IP-Symcon >= 2.2
*
* Zur Installation dieses Skript unter einer ViewJet-Instanz kopieren
* und ausführen. Hinterher können beliebige Variablen, Skripte und Links auf
* ebensolche in der vom Skript automatisch neu erstellten Kategorie "Objects"
* angelegt werden. Diese werden anhand ihrer Variablenprofile und Aktionen
* (wie im WebFront) dargestellt und änder-/ausführbar gemacht.
*
* ===================================================== (C) IP-Symcon 2010 ===
*/
if (IPS_SemaphoreEnter($IPS_SELF."Handler", 1000))
{
$instanceID = IPS_GetParent($IPS_SELF);
$keyUpID = IPS_GetStatusVariableID($instanceID, 'Key1');
$keyDownID = IPS_GetStatusVariableID($instanceID, 'Key2');
$keyEnterID = IPS_GetStatusVariableID($instanceID, 'Key3');
IPS_SetHidden($IPS_SELF, true);
$categoryID = @IPS_GetCategoryIDByName("Objects", $IPS_SELF);
if ($categoryID === false)
{
$categoryID = IPS_CreateCategory();
IPS_SetName($categoryID, "Objects");
IPS_SetParent($categoryID, $IPS_SELF);
}
$variableEventID = @IPS_GetEventIDByName("Variable Event", $IPS_SELF);
if ($variableEventID === false)
{
$variableEventID = IPS_CreateEvent(0);
IPS_SetName($variableEventID, "Variable Event");
IPS_SetParent($variableEventID, $IPS_SELF);
IPS_SetEventActive($variableEventID, true);
}
if (@IPS_GetEventIDByName("Key Up Event", $IPS_SELF) === false)
{
$eventID = IPS_CreateEvent(0);
IPS_SetName($eventID, "Key Up Event");
IPS_SetParent($eventID, $IPS_SELF);
IPS_SetEventTrigger($eventID, 0, $keyUpID);
IPS_SetEventActive($eventID, true);
}
if (@IPS_GetEventIDByName("Key Down Event", $IPS_SELF) === false)
{
$eventID = IPS_CreateEvent(0);
IPS_SetName($eventID, "Key Down Event");
IPS_SetParent($eventID, $IPS_SELF);
IPS_SetEventTrigger($eventID, 0, $keyDownID);
IPS_SetEventActive($eventID, true);
}
if (@IPS_GetEventIDByName("Key Enter Event", $IPS_SELF) === false)
{
$eventID = IPS_CreateEvent(0);
IPS_SetName($eventID, "Key Enter Event");
IPS_SetParent($eventID, $IPS_SELF);
IPS_SetEventTrigger($eventID, 0, $keyEnterID);
IPS_SetEventActive($eventID, true);
}
$objectNumberID = CreateVariableByName($IPS_SELF, "Object Number", 1, "");
$activeRowID = CreateVariableByName($IPS_SELF, "Row Number", 1, "");
$tempValueID = CreateVariableByName($IPS_SELF, "Temporary Value", 2, "");
$objectIDs = IPS_GetChildrenIDs($categoryID);
if (count($objectIDs) == 0)
{
PJ_LCDText($instanceID, 1, "Objektkategorie");
PJ_LCDText($instanceID, 2, "ist leer!");
}
else
{
$objects = array();
foreach ($objectIDs as $id)
{
$obj = getObject($id);
if ($obj['ObjectType'] == 2 || $obj['ObjectType'] == 3)
{
$objects[] = $obj;
}
}
usort($objects, "compareObjects");
$activeRow = GetValueInteger($activeRowID);
switchObject(max(0, min(count($objectIDs) - 1, GetValueInteger($objectNumberID))));
if ($IPS_SENDER == "Variable")
{
if ($IPS_VARIABLE == $keyUpID)
{
if ($activeRow == 0 && $objectNumber > 0)
{
switchObject($objectNumber - 1);
}
else if ($activeRow == 1)
{
if ($variable["VariableType"] == 0)
{
$tempValue = 0;
}
else if ($variable["VariableType"] == 1 || $variable["VariableType"] == 2)
{
if (count($variable["VariableProfile"]["Associations"]) > 0)
{
for ($i = count($variable["VariableProfile"]["Associations"]) - 1; $i >= 0; $i--)
{
$association = $variable["VariableProfile"]["Associations"][$i];
if ($tempValue > $association["Value"])
{
$tempValue = $association["Value"];
break;
}
}
}
else
{
$tempValue = max($variable["VariableProfile"]["MinValue"], $tempValue - $variable["VariableProfile"]["StepSize"]);
}
}
$variable["VariableValue"] = $tempValue;
}
}
else if ($IPS_VARIABLE == $keyDownID)
{
if ($activeRow == 0 && $objectNumber + 1 < count($objectIDs))
{
switchObject($objectNumber + 1);
}
else if ($activeRow == 1)
{
if ($variable["VariableType"] == 0)
{
$tempValue = 1;
}
else if ($variable["VariableType"] == 1 || $variable["VariableType"] == 2)
{
if (count($variable["VariableProfile"]["Associations"]) > 0)
{
for ($i = 0; $i < count($variable["VariableProfile"]["Associations"]); $i++)
{
$association = $variable["VariableProfile"]["Associations"][$i];
if ($tempValue < $association["Value"])
{
$tempValue = $association["Value"];
break;
}
}
}
else
{
$tempValue = min($variable["VariableProfile"]["MaxValue"], $tempValue + $variable["VariableProfile"]["StepSize"]);
}
}
$variable["VariableValue"] = $tempValue;
}
}
else if ($IPS_VARIABLE == $keyEnterID)
{
if ($variable != null)
{
if ($activeRow == 0 && $hasAction)
{
$activeRow = 1;
}
else if ($activeRow == 1)
{
if ($tempValue != $variable['VariableValue'])
{
if ($variable["VariableCustomAction"] > 0)
{
$vars = array();
$vars['IPS_SENDER'] = "ViewJet";
$vars['IPS_VARIABLE'] = $object['RealObjectID'];
$vars['IPS_VALUE'] = (double)$tempValue;
$vars['IPS_INSTANCE'] = $instanceID;
if ($object['RealObjectID'] != $object['ObjectID']) { $vars['IPS_LINK'] = $object['ObjectID']; }
IPS_RunScriptEx(getLinkedID($variable["VariableCustomAction"]), $vars);
}
else
{
IPS_RequestAction(IPS_GetParent($object['RealObjectID']), $variable["VariableIdent"], (double)$tempValue);
}
PJ_SwitchLED($instanceID, 3, true);
IPS_Sleep(250);
PJ_SwitchLED($instanceID, 3, false);
}
$activeRow = 0;
}
}
else
{
$vars = array();
$vars['IPS_SENDER'] = "ViewJet";
$vars['IPS_INSTANCE'] = $instanceID;
$vars['REMOTE_ADDR'] = $_SERVER['REMOTE_ADDR'];
if ($object['RealObjectID'] != $object['ObjectID']) { $vars['IPS_LINK'] = $object['ObjectID']; }
IPS_RunScriptEx($object['RealObjectID'], $vars);
PJ_SwitchLED($instanceID, 3, true);
IPS_Sleep(250);
PJ_SwitchLED($instanceID, 3, false);
}
}
}
$hasPreviousValue = ($tempValue > $variable['VariableProfile']['MinValue']);
$hasNextValue = ($tempValue < $variable['VariableProfile']['MaxValue']);
if (count($variable['VariableProfile']['Associations']) > 0)
{
$hasPreviousValue = $tempValue > $variable['VariableProfile']['Associations'][0]['Value'];
$hasNextValue = $tempValue < $variable['VariableProfile']['Associations'][count($variable['VariableProfile']['Associations']) - 1]['Value'];
}
$titleLeft = ($objectNumber < 1) ? " " : (($activeRow == 0) ? chr(127) : "<");
$titleRight = ($objectNumber + 1 >= count($objectIDs)) ? " " : (($activeRow == 0) ? chr(126) : ">");
$title = $titleLeft.formatText($object["ObjectName"]).$titleRight;
$text = "";
if ($object['ObjectType'] == 2)
{
$text = getAssociatedValue($variable, $tempValue);
$textLeft = (!$hasAction || !$hasPreviousValue) ? " " : (($activeRow == 1) ? chr(127) : "<");
$textRight = (!$hasAction || !$hasNextValue) ? " " : (($activeRow == 1) ? chr(126) : ">");
$text = $textLeft.formatText($text).$textRight;
}
else
{
$text = ">".formatText("ausführen")."<";
}
PJ_LCDText($instanceID, 1, $title);
PJ_LCDText($instanceID, 2, $text);
SetValueInteger($activeRowID, $activeRow);
SetValueInteger($objectNumberID, $objectNumber);
SetValueFloat($tempValueID, (float)$tempValue);
}
IPS_SemaphoreLeave($IPS_SELF."Handler");
}
function formatText ($text)
{
$text = str_replace("ß", chr(226), $text);
$text = str_replace("°", chr(223), $text);
$text = str_replace("ä", chr(225), $text);
$text = str_replace("ö", chr(239), $text);
$text = str_replace("ü", chr(245), $text);
return sprintf("%-14.14s", sprintf("%".(7 + floor(strlen($text) / 2))."s", $text));
}
function getIPSVariable ($id)
{
$variableID = $id;
$linkedVariableID = getLinkedID($variableID);
$variable = IPS_GetVariable($linkedVariableID);
$variable['VariableType'] = $variable['VariableValue']['ValueType'];
$variable['VariableValue'] = GetValue($linkedVariableID);
$variable['ObjectName'] = IPS_GetName($variableID);
$variable['VariableHasAction'] = false;
$variable['IsStatusVariable'] = false;
$variable['VariableInstanceID'] = 0;
$variable['VariableIdent'] = "";
$profileName = IPS_VariableProfileExists($variable['VariableProfile']) ? $variable['VariableProfile'] : "";
if (strlen($variable['VariableCustomProfile']) > 0 && IPS_VariableProfileExists($variable['VariableCustomProfile']))
{
$profileName = $variable['VariableCustomProfile'];
}
$variable['VariableProfile'] = array();
if (strlen($profileName) > 0)
{
$variableProfile = IPS_GetVariableProfile($profileName);
$variable['VariableProfile'] = $variableProfile;
if ($variable['VariableType'] == 0) { $variable['VariableProfile']['MaxValue'] = 1; }
$variable['VariableHasAction'] = $variable['VariableCustomAction'] > 0;
$variableParentID = IPS_GetParent($linkedVariableID);
$variableParent = IPS_GetObject($variableParentID);
if ($variableParent["ObjectType"] == 1)
{
$statusVariableIdents = IPS_GetStatusVariableIdents($variableParentID);
foreach ($statusVariableIdents as $ident)
{
if ($linkedVariableID == IPS_GetStatusVariableID($variableParentID, $ident))
{
$variable['IsStatusVariable'] = true;
$variable['VariableInstanceID'] = $variableParentID;
$variable['VariableIdent'] = $ident;
$statusVariable = IPS_GetStatusVariable($variable['VariableInstanceID'], $variable['VariableIdent']);
$variable['VariableHasAction'] = $variable['VariableHasAction'] ? true : ($statusVariable['VariableUseAction'] && $statusVariable['VariableHasAction']);
break;
}
}
}
}
return $variable;
}
function getLinkedID ($ObjectID)
{
if (IPS_ObjectExists($ObjectID))
{
$obj = IPS_GetObject($ObjectID);
if ($obj['ObjectType'] === 6)
{
$link = IPS_GetLink($ObjectID);
$ObjectID = $link['LinkChildID'];
}
}
return $ObjectID;
}
function getAssociatedValue ($object, $value, $useAssociations = true, $printValue = null)
{
if ($object["VariableProfile"]["ProfileName"] == "~UnixTimestamp") { return date("d.m.y H:i:s", $value); }
$printValue = ($printValue === null) ? $value : $printValue;
$last = null;
if ($useAssociations)
{
foreach ($object["VariableProfile"]["Associations"] as $i)
{
if ($value >= $i["Value"])
{
if ($i["Name"] !== "")
{
$last = $i;
}
else
{
$last = null;
}
}
else
{
break;
}
}
}
if ($last !== null)
{
$value = sprintf($last["Name"], $printValue);
}
else if (!is_string($value))
{
if (trim($object["VariableProfile"]["Suffix"]) == "%")
{
$value = ($value / ($object["VariableProfile"]["MaxValue"] - $object["VariableProfile"]["MinValue"])) * 100;
}
$value = sprintf("%.".$object["VariableProfile"]["Digits"]."f", $value);
}
$result = $object["VariableProfile"]["Prefix"].$value.$object["VariableProfile"]["Suffix"];
return $result;
}
function getObject ($ObjectID)
{
if (!IPS_ObjectExists($ObjectID)) { return false; }
$object = IPS_GetObject($ObjectID);
if ($object['ObjectType'] == 6)
{
$link = IPS_GetLink($ObjectID);
if (!IPS_ObjectExists($link['LinkChildID'])) { return false; }
$linkObject = $object;
$object = IPS_GetObject($link['LinkChildID']);
$object['RealObjectID'] = $object['ObjectID'];
$object['ObjectIcon'] = ($linkObject['ObjectIcon'] != "") ? $linkObject['ObjectIcon'] : $object['ObjectIcon'];
$object['ObjectID'] = $ObjectID;
$object['ObjectInfo'] = $linkObject['ObjectInfo'];
$object['ObjectIsHidden'] = $linkObject['ObjectIsHidden'];
$object['ObjectName'] = $linkObject['ObjectName'];
$object['ObjectPosition'] = $linkObject['ObjectPosition'];
$object['ParentID'] = $linkObject['ParentID'];
}
else
{
$object['RealObjectID'] = $ObjectID;
}
return $object;
}
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;
}
function compareObjects ($a, $b)
{
$comp = ($a['ObjectPosition'] < $b['ObjectPosition']) ? -1 : (($a['ObjectPosition'] == $b['ObjectPosition']) ? 0 : 1);
if ($comp == 0)
{
if (isset($a['ObjectType']))
{
$comp = ($a['ObjectType'] < $b['ObjectType']) ? -1 : (($a['ObjectType'] == $b['ObjectType']) ? 0 : 1);
}
if ($comp == 0)
{
$comp = strcmp($a['ObjectName'], $b['ObjectName']);
if ($comp == 0)
{
$comp = $a['ObjectID'] > $b['ObjectID'];
}
}
}
return $comp;
}
function switchObject ($num)
{
global $objectNumber, $objects, $object, $variable, $hasAction, $tempValue, $tempValueID, $variableEventID, $activeRow;
$objectNumber = $num;
$object = $objects[$objectNumber];
if ($object['ObjectType'] == 2)
{
$variable = getIPSVariable($object['ObjectID']);
$hasAction = ($variable['VariableType'] < 3) && $variable['VariableHasAction'];
$tempValue = ($activeRow == 0) ? $variable["VariableValue"] : GetValue($tempValueID);
IPS_SetEventTrigger($variableEventID, 1, getLinkedID($object['ObjectID']));
IPS_SetEventActive($variableEventID, true);
}
else
{
$variable = null;
$hasAction = true;
$tempValue = 0;
IPS_SetEventActive($variableEventID, false);
}
}
?>
Das nachfolgende Skript erlaubt zusätzlich eine Meldung auf beliebig viele ViewJet Displays zu verschicken.
<?
/*
* =================== ViewJet Melde-Skript ===================
*
* erforderlich: IP-Symcon >= 2.2
*
* Zur Installation dieses Skript an einem beliebigen Ort in IP-Symcon erstellen
* und ausführen. Hinterher können beliebige ViewJet-Instanzen auf
* ebensolche in der vom Skript automatisch neu erstellten Kategorie "Objects"
* verlinkt werden. An die verlinkten Displays wird dann bei änderung der Message Variable
* der Text gesendet und eine LED gesetzt. Das Anzeige und Kontroll Skript wird
* dann bis zum erneuten Tastendruck deaktiviert.
*
* ===================================================== (C) IP-Symcon 2010 ===
*/
if($IPS_SENDER == "Execute")
{
IPS_SetHidden($IPS_SELF, true);
$categoryID = @IPS_GetCategoryIDByName("Objects", $IPS_SELF);
if ($categoryID === false)
{
$categoryID = IPS_CreateCategory();
IPS_SetName($categoryID, "Objects");
IPS_SetParent($categoryID, $IPS_SELF);
}
$messageID = CreateVariableByName($IPS_SELF, "Message", 3, "");
if (@IPS_GetEventIDByName("Message Event", $IPS_SELF) === false)
{
$eventID = IPS_CreateEvent(0);
IPS_SetName($eventID, "Message Event");
IPS_SetParent($eventID, $IPS_SELF);
IPS_SetEventTrigger($eventID, 0, $messageID);
IPS_SetEventActive($eventID, true);
}
}
else if($IPS_SENDER == "Variable")
{
$categoryID = @IPS_GetCategoryIDByName("Objects", $IPS_SELF);
if ($categoryID === false)
return;
$objs = IPS_GetChildrenIDs($categoryID);
foreach($objs as $obj)
{
$obj = IPS_GetObject($obj);
if($obj['ObjectType'] == 6)
{
$link = IPS_GetLink($obj['ObjectID']);
PJ_SwitchLED($link['LinkChildID'],1,True);
PJ_LCDText($link['LinkChildID'],1, $IPS_VALUE);
PJ_LCDText($link['LinkChildID'],2, date("d.m.y H:i"));
PJ_Beep($link['LinkChildID'], 1);
$lcdobjs = IPS_GetChildrenIDs($link['LinkChildID']);
foreach($lcdobjs as $lcdobj)
{
$lcdobj = IPS_GetObject($lcdobj);
if($lcdobj['ObjectType'] == 3)
{
$eid = IPS_GetEventIDByName("Variable Event", $lcdobj['ObjectID']);
if(!($eid === false))
{
IPS_SetEventActive($eid,False);
}
}
}
}
}
}
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;
}
?>