function CreateVariable($Name, $Type, $Value, $Ident = '', $ParentID = 0) { echo "CreateVariable: ( {$Name}, {$Type}, {$Value}, {$Ident}, {$ParentID} ) \n"; if ('' != $Ident) { $VarID = @IPS_GetObjectIDByIdent($Ident, $ParentID); if (false !== $VarID) { SetVariable($VarID, $Type, $Value); return; } } $VarID = @IPS_GetObjectIDByName($Name, $ParentID); if (false !== $VarID) { $Obj = IPS_GetObject($VarID); if (2 == $Obj['ObjectType']) { $Var = IPS_GetVariable($VarID); if ($Type == $Var['VariableValue']['ValueType']) { SetVariable($VarID, $Type, $Value); return; } } } $VarID = IPS_CreateVariable($Type); IPS_SetParent($VarID, $ParentID); IPS_SetName($VarID, $Name); if ('' != $Ident) { IPS_SetIdent($VarID, $Ident); } SetVariable($VarID, $Type, $Value); }
public function createGroupWithID($name, $id, $parentID) { $group = @IPS_GetObjectIDByIdent($id, $parentID); if (!$group) { $group = IPS_CreateCategory(); IPS_SetName($group, $name); IPS_SetParent($group, $parentID); IPS_SetIdent($group, $id); $variable = IPS_CreateVariable(0); IPS_SetParent($variable, $group); IPS_SetName($variable, "Turn on"); IPS_SetIdent($variable, "state_" . $id); SetValue($variable, true); $variable = IPS_CreateVariable(1); IPS_SetParent($variable, $group); IPS_SetName($variable, "Delay"); IPS_SetIdent($variable, "delay_" . $id); SetValue($variable, 3600); $childs = IPS_CreateCategory(); IPS_SetName($childs, "Links"); IPS_SetParent($childs, $group); IPS_SetIdent($childs, "childs_" . $id); } return $group; }
/** * @public * * Initialisierung eines IPSComponentShutter_FS20 Objektes * * @param integer $instanceId InstanceId des FS20 Devices */ public function __construct($instanceId) { $this->instanceId = IPSUtil_ObjectIDByPath($instanceId); $this->isRunningId = @IPS_GetObjectIDByIdent('isrunning', $this->instanceId); if($this->isRunningId===false) { $this->isRunningId = IPS_CreateVariable(0); IPS_SetParent($this->isRunningId, $this->instanceId); IPS_SetName($this->isRunningId, 'IsRunning'); IPS_SetIdent($this->isRunningId, 'isrunning'); IPS_SetInfo($this->isRunningId, "This Variable was created by Script IPSComponentShutter_FS20"); } }
function CheckVariable($name, $vartyp, $profile, $parentID) { $InstanzID = @IPS_GetVariableIDByName($name, $parentID); if ($InstanzID === false) { $InstanzID = IPS_CreateVariable($vartyp); IPS_SetName($InstanzID, $name); // Instanz benennen IPS_SetParent($InstanzID, $parentID); IPS_SetVariableCustomProfile($InstanzID, $profile); } //echo "ID: ".$InstanzID." ".$name."\n"; return $InstanzID; }
private function CreateVariableByIdent($id, $ident, $name, $type, $profile = "") { $vid = @IPS_GetObjectIDByIdent($ident, $id); if ($vid === false) { $vid = IPS_CreateVariable($type); IPS_SetParent($vid, $id); IPS_SetName($vid, $name); IPS_SetIdent($vid, $ident); if ($profile != "") { IPS_SetVariableCustomProfile($vid, $profile); } } return $vid; }
protected function CreateAndUpdateVariable($variableType, $variableName, $value, $parent, $ident) { $existingVariableId = @IPS_GetObjectIDByIdent($ident, $parent); if (!$existingVariableId) { $newVariableId = IPS_CreateVariable($variableType); IPS_SetName($newVariableId, $variableName); SetValue($newVariableId, $value); IPS_SetParent($newVariableId, $parent); IPS_SetIdent($newVariableId, $ident); return $newVariableId; } else { SetValue($existingVariableId, $value); return $existingVariableId; } }
$HMDevice = GetOrCreateHMDevice($Rooms[utf8_decode((string) $Channel->Room[0]['Name'])], utf8_decode((string) $Channel['Name']), (string) $Channel['Address'], $Protocol, $HMParent); // Jetzt zusätzliche Elemente Erzeugen if (array_key_exists(utf8_decode((string) $Channel['ChnLabel']), $AddOnMappings)) { $AddOnMapping = $AddOnMappings[utf8_decode((string) $Channel['ChnLabel'])]; foreach ($AddOnMapping as $ident => $Var) { $VarId = IPS_CreateVariable($Var['VarTyp']); IPS_SetParent($VarId, $HMDevice); IPS_SetName($VarId, $ident); IPS_SetIdent($VarId, $ident); } $Mapping = array_merge($Mapping, $AddOnMapping); } if (array_key_exists('forceDP', $Mapping)) { foreach ($Mapping['forceDP'] as $ident => $VarTyp) { if (@IPS_GetObjectIDByIdent($ident, $HMDevice) === false) { $VarId = IPS_CreateVariable($VarTyp); IPS_SetParent($VarId, $HMDevice); IPS_SetName($VarId, $ident); IPS_SetIdent($VarId, $ident); } HM_RequestStatus($HMDevice, $ident); } } $Childs = IPS_GetChildrenIDs($HMDevice); if (count($Childs) == 0) { echo "Gerät mit der Addresse " . (string) $Channel['Address'] . " hat keine Datenpunkte." . PHP_EOL; echo " Gerät mit Namen '" . utf8_decode((string) $Channel['Name']) . "' wird wieder gelöscht." . PHP_EOL; echo "--------------------------------------------------------------------" . PHP_EOL; IPS_DeleteInstance($HMDevice); continue; }
/** * constructor * * second constructor: create the variable in symcon if it does not exist * * @param string $name name of the variable * @param integer $type IPS datatype * @param integer $parent id of the variables parent, this defines where the variable will be created * @param mixed $value initially set a variable value * @param IPSVariableProfile $profile variable profile for this variable * @param boolean $enableLogging enables or disables the ips functionality to log variable changes in a database * @param integer $archiveId instance id of the archive control (usually located in IPS\core) * @param integer $aggregationType logging aggregation: 0 = gauge, 1 = counter * @param boolean $debug enables / disables debug information * * @throws Exception if the parameter \$profile is not an IPSVariableProfile datatype * @access public */ private function __construct2($name, $type, $parent, $profile = NULL, $enableLogging = false, $archiveId = NULL, $aggregationType = 0, $debug = false) { if (isset($profile) && !$profile instanceof IPSVariableProfile) { throw new Exception("Parameter \$profile must be an instance of IPSVariableProfile! \$name of the variable is '{$name}'"); } $this->name = $name; $this->type = $type; $this->parent = $parent; $this->profile = $profile; $this->enableLogging = $enableLogging; $this->archiveId = $archiveId; $this->aggregationType = $aggregationType; $this->debug = $debug; $this->id = @IPS_GetVariableIDByName($name, $parent); if ($this->id == false) { if ($this->debug) { echo "INFO - create IPS variable {$name}\n"; } $this->id = IPS_CreateVariable($this->type); IPS_SetName($this->id, $name); IPS_SetParent($this->id, $parent); IPS_SetInfo($this->id, "this variable was created by script " . $_IPS['SELF'] . " which is part of the ips-library (https://github.com/florianprobst/ips-library)"); if (isset($profile)) { IPS_SetVariableCustomProfile($this->id, $profile->getName()); } $this->verifyVariableLogging(); } }
/** * RegisterVariableByParent * @param integer $ParentID * @param string $Ident * @param string $Name * @param integer $Type * @param string $Profile * @param integer $Position * @return integer */ private function RegisterVariableByParent($ParentID, $Ident, $Name, $Type, $Profile = "", $Position = 0) { if ($Profile !== "") { //prefer system profiles if (IPS_VariableProfileExists("~" . $Profile)) { $Profile = "~" . $Profile; } if (!IPS_VariableProfileExists($Profile)) { throw new Exception("Profile with name " . $Profile . " does not exist"); } } //search for already available variables with proper ident $vid = @IPS_GetObjectIDByIdent($Ident, $ParentID); //properly update variableID if ($vid === false) { $vid = 0; } //we have a variable with the proper ident. check if it fits if ($vid > 0) { //check if we really have a variable if (!IPS_VariableExists($vid)) { throw new Exception("Ident with name " . $Ident . " is used for wrong object type"); } //bail out //check for type mismatch if (IPS_GetVariable($vid)["VariableType"] != $Type) { //mismatch detected. delete this one. we will create a new below IPS_DeleteVariable($vid); //this will ensure, that a new one is created $vid = 0; } } //we need to create one if ($vid === 0) { $vid = IPS_CreateVariable($Type); //configure it IPS_SetParent($vid, $ParentID); IPS_SetIdent($vid, $Ident); IPS_SetName($vid, $Name); IPS_SetPosition($vid, $Position); //IPS_SetReadOnly($vid, true); } //update variable profile. profiles may be changed in module development. //this update does not affect any custom profile choices IPS_SetVariableCustomProfile($vid, $Profile); return $vid; }
function Variable_GetOrSet($name, $parent, $value) { global $Logging; $VarID = @IPS_GetVariableIDByName($name, $parent); if (!$VarID) { if ($name == "Name" or $name == "Marke" or $name == "ID" or $name == "Anschrift") { $VarID = IPS_CreateVariable(3); } elseif ($name == "Geöffnet_von" or $name == "Geöffnet_bis") { $VarID = IPS_CreateVariable(3); $ProfilName = "GeoffnetVonBis_Tankstelle_TK"; if (!IPS_VariableProfileExists($ProfilName)) { IPS_CreateVariableProfile($ProfilName, 3); IPS_SetVariableProfileText($ProfilName, "", " Uhr"); IPS_SetVariableProfileIcon($ProfilName, "Clock"); } IPS_SetVariableCustomProfile($VarID, $ProfilName); } elseif ($name == "Geöffnet") { $VarID = IPS_CreateVariable(0); $ProfilName = "Geoeffnet_Tankstelle_TK"; if (!IPS_VariableProfileExists($ProfilName)) { IPS_CreateVariableProfile($ProfilName, 0); IPS_SetVariableProfileAssociation($ProfilName, 0, "Geschlossen", "", -1); IPS_SetVariableProfileAssociation($ProfilName, 1, "Geöffnet", "", -1); IPS_SetVariableProfileIcon($ProfilName, "Information"); } IPS_SetVariableCustomProfile($VarID, $ProfilName); } elseif ($name == "Distanz") { $VarID = IPS_CreateVariable(2); $ProfilName = "Distanz_Tankstelle_TK"; if (!IPS_VariableProfileExists($ProfilName)) { IPS_CreateVariableProfile($ProfilName, 2); IPS_SetVariableProfileText($ProfilName, "", "km"); IPS_SetVariableProfileDigits($ProfilName, 1); IPS_SetVariableProfileIcon($ProfilName, "Distance"); } IPS_SetVariableCustomProfile($VarID, $ProfilName); } elseif ($name == "Preis" or $name == "Preis_E5" or $name == "Preis_E10" or $name == "Preis_Diesel") { if ($value === NULL) { return; } $VarID = IPS_CreateVariable(2); $ProfilName = "Euro_Tankstelle_TK"; if (!IPS_VariableProfileExists($ProfilName)) { IPS_CreateVariableProfile($ProfilName, 2); IPS_SetVariableProfileText($ProfilName, "", "€"); IPS_SetVariableProfileDigits($ProfilName, 3); IPS_SetVariableProfileIcon($ProfilName, "Euro"); } IPS_SetVariableCustomProfile($VarID, $ProfilName); if ($Logging) { $ArchiveHandlerID = IPS_GetInstanceListByModuleID('{43192F0B-135B-4CE7-A0A7-1475603F3060}')[0]; AC_SetLoggingStatus($ArchiveHandlerID, $VarID, true); IPS_ApplyChanges($ArchiveHandlerID); } } IPS_SetName($VarID, $name); IPS_SetParent($VarID, $parent); } SetValue($VarID, $value); }