public function RequestRead() { $Address = 0x0 + ($this->ReadPropertyInteger("Phase") - 1) * 2; $Volt = $this->SendDataToParent(json_encode(array("DataID" => "{E310B701-4AE7-458E-B618-EC13A1A6F6A8}", "Function" => 3, "Address" => $Address, "Quantity" => 2, "Data" => ""))); if ($Volt === false) { return; } $Volt = unpack("n*", substr($Volt, 2)); $Address = 0xc + ($this->ReadPropertyInteger("Phase") - 1) * 2; $Ampere = $this->SendDataToParent(json_encode(array("DataID" => "{E310B701-4AE7-458E-B618-EC13A1A6F6A8}", "Function" => 3, "Address" => $Address, "Quantity" => 2, "Data" => ""))); if ($Ampere === false) { return; } $Ampere = unpack("n*", substr($Ampere, 2)); $Address = 0x12 + ($this->ReadPropertyInteger("Phase") - 1) * 2; $Watt = $this->SendDataToParent(json_encode(array("DataID" => "{E310B701-4AE7-458E-B618-EC13A1A6F6A8}", "Function" => 3, "Address" => $Address, "Quantity" => 2, "Data" => ""))); if ($Watt === false) { return; } $Watt = unpack("n*", substr($Watt, 2)); $Address = 0x46 + ($this->ReadPropertyInteger("Phase") - 1) * 2; $KWh = $this->SendDataToParent(json_encode(array("DataID" => "{E310B701-4AE7-458E-B618-EC13A1A6F6A8}", "Function" => 3, "Address" => $Address, "Quantity" => 2, "Data" => ""))); if ($KWh === false) { return; } $KWh = unpack("n*", substr($KWh, 2)); if (IPS_GetProperty(IPS_GetInstance($this->InstanceID)['ConnectionID'], "SwapWords")) { SetValue($this->GetIDForIdent("Volt"), ($Volt[1] + ($Volt[2] << 16)) / 10); SetValue($this->GetIDForIdent("Ampere"), ($Ampere[1] + ($Ampere[2] << 16)) / 1000); SetValue($this->GetIDForIdent("Watt"), ($Watt[1] + ($Watt[2] << 16)) / 10); SetValue($this->GetIDForIdent("kWh"), ($KWh[1] + ($KWh[2] << 16)) / 10); } else { SetValue($this->GetIDForIdent("Volt"), ($Volt[2] + ($Volt[1] << 16)) / 10); SetValue($this->GetIDForIdent("Ampere"), ($Ampere[2] + ($Ampere[1] << 16)) / 1000); SetValue($this->GetIDForIdent("Watt"), ($Watt[2] + ($Watt[1] << 16)) / 10); SetValue($this->GetIDForIdent("kWh"), ($KWh[2] + ($KWh[1] << 16)) / 10); } }
protected function SetStatus($InstanceStatus) { if (IPS_GetKernelRunlevel() == KR_READY) { $OldStatus = IPS_GetInstance($this->InstanceID)['InstanceStatus']; } else { $OldStatus = -1; } if ($InstanceStatus != $OldStatus) { parent::SetStatus($InstanceStatus); if ($InstanceStatus == IS_ACTIVE) { $this->SetTimerInterval('KeepAlive', 3600000); } else { $this->SetTimerInterval('KeepAlive', 0); } return true; } else { return false; } }
protected function AddAddress(string $address) { $instance = IPS_GetInstance($this->InstanceID)["InstanceID"]; IPS_SetProperty($instance, "LEDAdresse", $address); //Adresse setzten. IPS_SetProperty($instance, "LearnAddressLED", false); //Haken entfernen. IPS_ApplyChanges($instance); //Neue Konfiguration übernehmen IPS_LogMessage("LED Controller Adresse hinzugefügt:", $address); }
/** * Check if a parent for Instance $id exists * @param $id integer InstanceID * @return integer */ protected function GetParent($id = 0) { $parent = 0; if ($id == 0) { $id = $this->InstanceID; } if (IPS_InstanceExists($id)) { $instance = IPS_GetInstance($id); $parent = $instance['ConnectionID']; } else { $this->debug(__FUNCTION__, "Instance #{$id} doesn't exists"); } return $parent; }
function GetOrCreateHMDevice($Parent, $Name, $Address, $Protocol, $HMParent) { $ObjID = IPS_CreateInstance("{EE4A81C6-5C90-4DB7-AD2F-F6BBD521412E}"); if (IPS_GetInstance($ObjID)['ConnectionID'] != $HMParent) { IPS_DisconnectInstance($ObjID); IPS_ConnectInstance($ObjID, $HMParent); } IPS_SetParent($ObjID, $Parent); IPS_SetName($ObjID, $Name); IPS_SetProperty($ObjID, 'Address', $Address); IPS_SetProperty($ObjID, 'Protocol', $Protocol); IPS_SetProperty($ObjID, 'EmulateStatus', false); usleep(50000); @IPS_ApplyChanges($ObjID); /* { echo "Error beim Erzeugen von Gerät ".$Address.PHP_EOL; // echo " Gerät mit Namen ".$Name." wird wieder gelöscht.".PHP_EOL; // IPS_DeleteInstance($ObjID); // return false; } */ return $ObjID; }
/** * Forward data to EnergyDev instances * Create one if needed * @param $data */ private function SendENData($data) { //parsing was OK, start distributing $this->debug(__FUNCTION__, 'Prepare ' . print_r($data, true)); $class = __CLASS__; if (!isset($data['Id']) || !isset($data['Typ'])) { IPS_LogMessage($class, 'Missing Data Id or Typ'); return; } $id = $data['Id']; $typ = $data['Typ']; $caps = ''; foreach ($this->fieldlist as $cap) { if (isset($data[$cap])) { $caps .= ";" . $cap; } } $caps = substr($caps, 1); $this->debug(__FUNCTION__, "USV {$id} Caps: {$caps} "); $found = false; $instID = 0; $instances = IPS_GetInstanceListByModuleID($this->module_interfaces['EnergyDev']); foreach ($instances as $instID) { $I = @IPS_GetInstance($instID); if ($I && $I['ConnectionID'] == $this->InstanceID) { //my child $iid = (string) IPS_GetProperty($instID, 'DeviceID'); $ityp = (string) IPS_GetProperty($instID, 'Typ'); $iclass = (string) IPS_GetProperty($instID, 'Class'); if ($iid == $id && $ityp == $typ && $iclass == $class) { $this->debug(__FUNCTION__, 'Use existing ID:' . $instID); $found = true; break; } //if destdevice } //if } //for if (!$found) { //no free instance available, have to create a new one if ($this->ReadPropertyBoolean('AutoCreate') == true) { //new instance needed $instID = $this->CreateENDevice($data, $caps); if ($instID > 0) { //new instance needed $this->debug(__FUNCTION__, 'CREATE Device with Caps: ' . $caps); $found = true; } } else { $this->debug(__FUNCTION__, 'Creating Device ID ' . $id . ' disabled by Property AutoCreate'); IPS_LogMessage($class, 'Creating Device ID ' . $id . ' disabled by Property AutoCreate'); } //if autocreate } //if found if ($found && $instID > 0) { //send record to children $json = json_encode(array("DataID" => $this->module_interfaces['EN-RX'], "DeviceID" => $id, "Typ" => $typ, "Class" => $class, "ENData" => $data)); $this->debug(__FUNCTION__, $json); @$this->SendDataToChildren($json); $this->log_data($data); } //found $this->debug(__FUNCTION__, 'Finished'); }
protected function SetStatus($InstanceStatus) { if ($InstanceStatus != IPS_GetInstance($this->InstanceID)['InstanceStatus']) { parent::SetStatus($InstanceStatus); } }
/** * checks if the instance to $archiveId is a valid IPS archive object * * @param integer $archiveId instance id to be checked * @throws Exception if $archiveId does not match to IPS archive * @return true if id refers to an archive * @access private */ private function checkArchive($archiveId) { $archive = @IPS_GetInstance($archiveId); if ($archive == NULL) { throw new Exception("Archive with instance id {$archiveId} does not exist"); } if ($archive["ModuleInfo"]["ModuleID"] == "{43192F0B-135B-4CE7-A0A7-1475603F3060}") { return true; } return false; }
protected function AddAddress($address) { $instance = IPS_GetInstance($this->InstanceID)["InstanceID"]; IPS_SetProperty($instance, "ELROAddress", $address); //Adresse setzten. IPS_SetProperty($instance, "LearnAddressELRO", false); //Haken entfernen. IPS_ApplyChanges($instance); //Neue Konfiguration übernehmen IPS_LogMessage("ELRO Adresse hinzugefügt:", $address); // Status aktiv $this->SetStatus(102); //Status-Variablen anlegen $stateId = $this->RegisterVariableBoolean("STATE", "Status", "~Switch", 1); $this->EnableAction("STATE"); }
public function SyncDevices() { $lightsCategoryId = $this->GetLightsCategory(); $lights = $this->Request('/lights'); foreach ($lights as $lightId => $light) { $name = utf8_decode((string)$light->name); $uniqueId = (string)$light->uniqueid; echo "$lightId. $name ($uniqueId)\n"; $deviceId = $this->GetDeviceByUniqueId($uniqueId); if ($deviceId == 0) { $deviceId = IPS_CreateInstance($this->DeviceGuid()); IPS_SetProperty($deviceId, 'UniqueId', $uniqueId); } IPS_SetParent($deviceId, $lightsCategoryId); IPS_SetProperty($deviceId, 'LightId', (integer)$lightId); IPS_SetName($deviceId, $name); // Verbinde Light mit Bridge if (IPS_GetInstance($deviceId)['ConnectionID'] <> $this->InstanceID) { @IPS_DisconnectInstance($deviceId); IPS_ConnectInstance($deviceId, $this->InstanceID); } IPS_ApplyChanges($deviceId); HUE_RequestData($deviceId); } }
private function ReadBatteryStates() { $InstanzIDsListAll[] = IPS_GetInstanceListByModuleID("{A89F8DFA-A439-4BF1-B7CB-43D047208DDD}"); // FHT $InstanzIDsListAll[] = IPS_GetInstanceListByModuleID("{2FD7576A-D2AD-47EE-9779-A502F23CABB3}"); // FS20 HMS $InstanzIDsListAll[] = IPS_GetInstanceListByModuleID("{EE4A81C6-5C90-4DB7-AD2F-F6BBD521412E}"); // HomeMatic $InstanzIDsListAll[] = IPS_GetInstanceListByModuleID("{101352E1-88C7-4F16-998B-E20D50779AF6}"); // Z-Wave $a = 0; $l = 0; foreach ($InstanzIDsListAll as $InstanzIDsList) { foreach ($InstanzIDsList as $InstanzID) { $InstanzHersteller = IPS_GetInstance($InstanzID); $InstanzHersteller = $InstanzHersteller["ModuleInfo"]["ModuleName"]; switch ($InstanzHersteller) { case "FHT": $InstanzHersteller = "FHT"; break; case "HMS": $InstanzHersteller = "HMS"; break; case "HomeMatic Device": $InstanzHersteller = "HomeMatic"; break; case "Z-Wave Module": $InstanzHersteller = "Z-Wave"; break; } //FHT $VarID = @IPS_GetObjectIDByIdent('LowBatteryVar', $InstanzID); if ($VarID !== false and $InstanzHersteller == "FHT") { $Var = IPS_GetVariable($VarID); $VarLastUpdated = $Var["VariableUpdated"]; $VarLastUpdatedDiffSek = time() - $VarLastUpdated; $DeviceID = IPS_GetProperty($InstanzID, "Address"); $LowBat = GetValueBoolean($VarID); if ($LowBat === true) { $Batterien_AR["Alle"][$a]["Name"] = $this->Umlaute_Ersetzen(IPS_GetName($InstanzID)); if ($this->ReadPropertyBoolean("NamenParentObjekt1CB") == true) { $ParentID = $this->ParentIDermitteln("ParentNr1NS", $InstanzID); $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle1TB")); $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID)); } if ($this->ReadPropertyBoolean("NamenParentObjekt2CB") == true) { $ParentID = $this->ParentIDermitteln("ParentNr2NS", $InstanzID); $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle2TB")); $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID)); } if ($this->ReadPropertyBoolean("NamenParentObjekt3CB") == true) { $ParentID = $this->ParentIDermitteln("ParentNr3NS", $InstanzID); $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle3TB")); $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID)); } $Batterien_AR["Alle"][$a]["Batterie"] = "LEER"; $Batterien_AR["Alle"][$a]["Hersteller"] = $InstanzHersteller; $Batterien_AR["Alle"][$a]["ID"] = $DeviceID; $Batterien_AR["Alle"][$a]["Hersteller_ID"] = $InstanzHersteller . " - " . $DeviceID; $Batterien_AR["Alle"][$a]["LetztesVarUpdateTimestamp"] = $VarLastUpdated; $Batterien_AR["Alle"][$a]["LetztesVarUpdateVorSek"] = $VarLastUpdatedDiffSek; $Batterien_AR["Leer"][$l]["Name"] = $this->Umlaute_Ersetzen(IPS_GetName($InstanzID)); if ($this->ReadPropertyBoolean("NamenParentObjekt1CB") == true) { $ParentID = $this->ParentIDermitteln("ParentNr1NS", $InstanzID); $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle1TB")); $Batterien_AR["Leer"][$l][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID)); } if ($this->ReadPropertyBoolean("NamenParentObjekt2CB") == true) { $ParentID = $this->ParentIDermitteln("ParentNr2NS", $InstanzID); $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle2TB")); $Batterien_AR["Leer"][$l][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID)); } if ($this->ReadPropertyBoolean("NamenParentObjekt3CB") == true) { $ParentID = $this->ParentIDermitteln("ParentNr3NS", $InstanzID); $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle3TB")); $Batterien_AR["Leer"][$l][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID)); } $Batterien_AR["Leer"][$l]["Batterie"] = "LEER"; $Batterien_AR["Leer"][$l]["Hersteller"] = $InstanzHersteller; $Batterien_AR["Leer"][$l]["ID"] = $DeviceID; $Batterien_AR["Leer"][$l]["Hersteller_ID"] = $InstanzHersteller . " - " . $DeviceID; $Batterien_AR["Leer"][$l]["LetztesVarUpdateTimestamp"] = $VarLastUpdated; $Batterien_AR["Leer"][$l]["LetztesVarUpdateVorSek"] = $VarLastUpdatedDiffSek; $a++; $l++; } else { $Batterien_AR["Alle"][$a]["Name"] = $this->Umlaute_Ersetzen(IPS_GetName($InstanzID)); if ($this->ReadPropertyBoolean("NamenParentObjekt1CB") == true) { $ParentID = $this->ParentIDermitteln("ParentNr1NS", $InstanzID); $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle1TB")); $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID)); } if ($this->ReadPropertyBoolean("NamenParentObjekt2CB") == true) { $ParentID = $this->ParentIDermitteln("ParentNr2NS", $InstanzID); $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle2TB")); $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID)); } if ($this->ReadPropertyBoolean("NamenParentObjekt3CB") == true) { $ParentID = $this->ParentIDermitteln("ParentNr3NS", $InstanzID); $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle3TB")); $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID)); } $Batterien_AR["Alle"][$a]["Batterie"] = "OK"; $Batterien_AR["Alle"][$a]["Hersteller"] = $InstanzHersteller; $Batterien_AR["Alle"][$a]["ID"] = $DeviceID; $Batterien_AR["Alle"][$a]["Hersteller_ID"] = $InstanzHersteller . " - " . $DeviceID; $Batterien_AR["Alle"][$a]["LetztesVarUpdateTimestamp"] = $VarLastUpdated; $Batterien_AR["Alle"][$a]["LetztesVarUpdateVorSek"] = $VarLastUpdatedDiffSek; $a++; } } //FS20 HMS $VarID = @IPS_GetObjectIDByIdent('LowBatteryVar', $InstanzID); if ($VarID !== false and $InstanzHersteller == "HMS") { $Var = IPS_GetVariable($VarID); $VarLastUpdated = $Var["VariableUpdated"]; $VarLastUpdatedDiffSek = time() - $VarLastUpdated; $DeviceID = IPS_GetProperty($InstanzID, "DeviceID"); $LowBat = GetValueBoolean($VarID); if ($LowBat === true) { $Batterien_AR["Alle"][$a]["Name"] = $this->Umlaute_Ersetzen(IPS_GetName($InstanzID)); if ($this->ReadPropertyBoolean("NamenParentObjekt") == true) { if ($this->ReadPropertyBoolean("NamenParentObjekt1CB") == true) { $ParentID = $this->ParentIDermitteln("ParentNr1NS", $InstanzID); $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle1TB")); $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID)); } } if ($this->ReadPropertyBoolean("NamenParentObjekt2CB") == true) { $ParentID = $this->ParentIDermitteln("ParentNr2NS", $InstanzID); $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle2TB")); $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID)); } if ($this->ReadPropertyBoolean("NamenParentObjekt3CB") == true) { $ParentID = $this->ParentIDermitteln("ParentNr3NS", $InstanzID); $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle3TB")); $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID)); } $Batterien_AR["Alle"][$a]["Batterie"] = "LEER"; $Batterien_AR["Alle"][$a]["Hersteller"] = $InstanzHersteller; $Batterien_AR["Alle"][$a]["ID"] = $DeviceID; $Batterien_AR["Alle"][$a]["Hersteller_ID"] = $InstanzHersteller . " - " . $DeviceID; $Batterien_AR["Alle"][$a]["LetztesVarUpdateTimestamp"] = $VarLastUpdated; $Batterien_AR["Alle"][$a]["LetztesVarUpdateVorSek"] = $VarLastUpdatedDiffSek; $Batterien_AR["Leer"][$l]["Name"] = $this->Umlaute_Ersetzen(IPS_GetName($InstanzID)); if ($this->ReadPropertyBoolean("NamenParentObjekt1CB") == true) { $ParentID = $this->ParentIDermitteln("ParentNr1NS", $InstanzID); $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle1TB")); $Batterien_AR["Leer"][$l][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID)); } if ($this->ReadPropertyBoolean("NamenParentObjekt2CB") == true) { $ParentID = $this->ParentIDermitteln("ParentNr2NS", $InstanzID); $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle2TB")); $Batterien_AR["Leer"][$l][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID)); } if ($this->ReadPropertyBoolean("NamenParentObjekt3CB") == true) { $ParentID = $this->ParentIDermitteln("ParentNr3NS", $InstanzID); $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle3TB")); $Batterien_AR["Leer"][$l][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID)); } $Batterien_AR["Leer"][$l]["Batterie"] = "LEER"; $Batterien_AR["Leer"][$l]["Hersteller"] = $InstanzHersteller; $Batterien_AR["Leer"][$l]["ID"] = $DeviceID; $Batterien_AR["Leer"][$l]["Hersteller_ID"] = $InstanzHersteller . " - " . $DeviceID; $Batterien_AR["Leer"][$l]["LetztesVarUpdateTimestamp"] = $VarLastUpdated; $Batterien_AR["Leer"][$l]["LetztesVarUpdateVorSek"] = $VarLastUpdatedDiffSek; $a++; $l++; } else { $Batterien_AR["Alle"][$a]["Name"] = $this->Umlaute_Ersetzen(IPS_GetName($InstanzID)); if ($this->ReadPropertyBoolean("NamenParentObjekt1CB") == true) { $ParentID = $this->ParentIDermitteln("ParentNr1NS", $InstanzID); $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle1TB")); $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID)); } if ($this->ReadPropertyBoolean("NamenParentObjekt2CB") == true) { $ParentID = $this->ParentIDermitteln("ParentNr2NS", $InstanzID); $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle2TB")); $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID)); } if ($this->ReadPropertyBoolean("NamenParentObjekt3CB") == true) { $ParentID = $this->ParentIDermitteln("ParentNr3NS", $InstanzID); $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle3TB")); $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID)); } $Batterien_AR["Alle"][$a]["Batterie"] = "OK"; $Batterien_AR["Alle"][$a]["Hersteller"] = $InstanzHersteller; $Batterien_AR["Alle"][$a]["ID"] = $DeviceID; $Batterien_AR["Alle"][$a]["Hersteller_ID"] = $InstanzHersteller . " - " . $DeviceID; $Batterien_AR["Alle"][$a]["LetztesVarUpdateTimestamp"] = $VarLastUpdated; $Batterien_AR["Alle"][$a]["LetztesVarUpdateVorSek"] = $VarLastUpdatedDiffSek; $a++; } } //HomeMatic $VarID = @IPS_GetObjectIDByIdent('LOWBAT', $InstanzID); if ($VarID !== false and $InstanzHersteller == "HomeMatic") { $Var = IPS_GetVariable($VarID); $VarLastUpdated = $Var["VariableUpdated"]; $VarLastUpdatedDiffSek = time() - $VarLastUpdated; $DeviceID = substr(IPS_GetProperty($InstanzID, "Address"), 0, -2); $LowBat = GetValueBoolean($VarID); if ($LowBat === true) { $Batterien_AR["Alle"][$a]["Name"] = $this->Umlaute_Ersetzen(IPS_GetName($InstanzID)); if ($this->ReadPropertyBoolean("NamenParentObjekt1CB") == true) { $ParentID = $this->ParentIDermitteln("ParentNr1NS", $InstanzID); $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle1TB")); $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID)); } if ($this->ReadPropertyBoolean("NamenParentObjekt2CB") == true) { $ParentID = $this->ParentIDermitteln("ParentNr2NS", $InstanzID); $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle2TB")); $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID)); } if ($this->ReadPropertyBoolean("NamenParentObjekt3CB") == true) { $ParentID = $this->ParentIDermitteln("ParentNr3NS", $InstanzID); $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle3TB")); $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID)); } $Batterien_AR["Alle"][$a]["Batterie"] = "LEER"; $Batterien_AR["Alle"][$a]["Hersteller"] = $InstanzHersteller; $Batterien_AR["Alle"][$a]["ID"] = $DeviceID; $Batterien_AR["Alle"][$a]["Hersteller_ID"] = $InstanzHersteller . " - " . $DeviceID; $Batterien_AR["Alle"][$a]["LetztesVarUpdateTimestamp"] = $VarLastUpdated; $Batterien_AR["Alle"][$a]["LetztesVarUpdateVorSek"] = $VarLastUpdatedDiffSek; $Batterien_AR["Leer"][$l]["Name"] = $this->Umlaute_Ersetzen(IPS_GetName($InstanzID)); if ($this->ReadPropertyBoolean("NamenParentObjekt1CB") == true) { $ParentID = $this->ParentIDermitteln("ParentNr1NS", $InstanzID); $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle1TB")); $Batterien_AR["Leer"][$l][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID)); } if ($this->ReadPropertyBoolean("NamenParentObjekt2CB") == true) { $ParentID = $this->ParentIDermitteln("ParentNr2NS", $InstanzID); $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle2TB")); $Batterien_AR["Leer"][$l][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID)); } if ($this->ReadPropertyBoolean("NamenParentObjekt3CB") == true) { $ParentID = $this->ParentIDermitteln("ParentNr3NS", $InstanzID); $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle3TB")); $Batterien_AR["Leer"][$l][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID)); } $Batterien_AR["Leer"][$l]["Batterie"] = "LEER"; $Batterien_AR["Leer"][$l]["Hersteller"] = $InstanzHersteller; $Batterien_AR["Leer"][$l]["ID"] = $DeviceID; $Batterien_AR["Leer"][$l]["Hersteller_ID"] = $InstanzHersteller . " - " . $DeviceID; $Batterien_AR["Leer"][$l]["LetztesVarUpdateTimestamp"] = $VarLastUpdated; $Batterien_AR["Leer"][$l]["LetztesVarUpdateVorSek"] = $VarLastUpdatedDiffSek; $a++; $l++; } else { $Batterien_AR["Alle"][$a]["Name"] = $this->Umlaute_Ersetzen(IPS_GetName($InstanzID)); if ($this->ReadPropertyBoolean("NamenParentObjekt1CB") == true) { $ParentID = $this->ParentIDermitteln("ParentNr1NS", $InstanzID); $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle1TB")); $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID)); } if ($this->ReadPropertyBoolean("NamenParentObjekt2CB") == true) { $ParentID = $this->ParentIDermitteln("ParentNr2NS", $InstanzID); $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle2TB")); $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID)); } if ($this->ReadPropertyBoolean("NamenParentObjekt3CB") == true) { $ParentID = $this->ParentIDermitteln("ParentNr3NS", $InstanzID); $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle3TB")); $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID)); } $Batterien_AR["Alle"][$a]["Batterie"] = "OK"; $Batterien_AR["Alle"][$a]["Hersteller"] = $InstanzHersteller; $Batterien_AR["Alle"][$a]["ID"] = $DeviceID; $Batterien_AR["Alle"][$a]["Hersteller_ID"] = $InstanzHersteller . " - " . $DeviceID; $Batterien_AR["Alle"][$a]["LetztesVarUpdateTimestamp"] = $VarLastUpdated; $Batterien_AR["Alle"][$a]["LetztesVarUpdateVorSek"] = $VarLastUpdatedDiffSek; $a++; } } //Z-Wave $VarID = @IPS_GetObjectIDByIdent('BatteryLowVariable', $InstanzID); if ($VarID !== false and $InstanzHersteller == "Z-Wave") { $Var = IPS_GetVariable($VarID); $VarLastUpdated = $Var["VariableUpdated"]; $VarLastUpdatedDiffSek = time() - $VarLastUpdated; $DeviceID = IPS_GetProperty($InstanzID, "NodeID"); $LowBat = GetValueBoolean($VarID); if ($LowBat === true) { $Batterien_AR["Alle"][$a]["Name"] = $this->Umlaute_Ersetzen(IPS_GetName($InstanzID)); if ($this->ReadPropertyBoolean("NamenParentObjekt1CB") == true) { $ParentID = $this->ParentIDermitteln("ParentNr1NS", $InstanzID); $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle1TB")); $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID)); } if ($this->ReadPropertyBoolean("NamenParentObjekt2CB") == true) { $ParentID = $this->ParentIDermitteln("ParentNr2NS", $InstanzID); $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle2TB")); $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID)); } if ($this->ReadPropertyBoolean("NamenParentObjekt3CB") == true) { $ParentID = $this->ParentIDermitteln("ParentNr3NS", $InstanzID); $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle3TB")); $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID)); } $Batterien_AR["Alle"][$a]["Batterie"] = "LEER"; $Batterien_AR["Alle"][$a]["Hersteller"] = $InstanzHersteller; $Batterien_AR["Alle"][$a]["ID"] = $DeviceID; $Batterien_AR["Alle"][$a]["Hersteller_ID"] = $InstanzHersteller . " - " . $DeviceID; $Batterien_AR["Alle"][$a]["LetztesVarUpdateTimestamp"] = $VarLastUpdated; $Batterien_AR["Alle"][$a]["LetztesVarUpdateVorSek"] = $VarLastUpdatedDiffSek; $Batterien_AR["Leer"][$l]["Name"] = $this->Umlaute_Ersetzen(IPS_GetName($InstanzID)); if ($this->ReadPropertyBoolean("NamenParentObjekt1CB") == true) { $ParentID = $this->ParentIDermitteln("ParentNr1NS", $InstanzID); $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle1TB")); $Batterien_AR["Leer"][$l][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID)); } if ($this->ReadPropertyBoolean("NamenParentObjekt2CB") == true) { $ParentID = $this->ParentIDermitteln("ParentNr2NS", $InstanzID); $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle3TB")); $Batterien_AR["Leer"][$l][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID)); } if ($this->ReadPropertyBoolean("NamenParentObjekt3CB") == true) { $ParentID = $this->ParentIDermitteln("ParentNr3NS", $InstanzID); $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle3TB")); $Batterien_AR["Leer"][$l][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID)); } $Batterien_AR["Leer"][$l]["Batterie"] = "LEER"; $Batterien_AR["Leer"][$l]["Hersteller"] = $InstanzHersteller; $Batterien_AR["Leer"][$l]["ID"] = $DeviceID; $Batterien_AR["Leer"][$l]["Hersteller_ID"] = $InstanzHersteller . " - " . $DeviceID; $Batterien_AR["Leer"][$l]["LetztesVarUpdateTimestamp"] = $VarLastUpdated; $Batterien_AR["Leer"][$l]["LetztesVarUpdateVorSek"] = $VarLastUpdatedDiffSek; $a++; $l++; } else { $Batterien_AR["Alle"][$a]["Name"] = $this->Umlaute_Ersetzen(IPS_GetName($InstanzID)); if ($this->ReadPropertyBoolean("NamenParentObjekt1CB") == true) { $ParentID = $this->ParentIDermitteln("ParentNr1NS", $InstanzID); $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle1TB")); $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID)); } if ($this->ReadPropertyBoolean("NamenParentObjekt2CB") == true) { $ParentID = $this->ParentIDermitteln("ParentNr2NS", $InstanzID); $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle2TB")); $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID)); } if ($this->ReadPropertyBoolean("NamenParentObjekt3CB") == true) { $ParentID = $this->ParentIDermitteln("ParentNr3NS", $InstanzID); $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabell3TB")); $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID)); } $Batterien_AR["Alle"][$a]["Batterie"] = "OK"; $Batterien_AR["Alle"][$a]["Hersteller"] = $InstanzHersteller; $Batterien_AR["Alle"][$a]["ID"] = $DeviceID; $Batterien_AR["Alle"][$a]["Hersteller_ID"] = $InstanzHersteller . " - " . $DeviceID; $Batterien_AR["Alle"][$a]["LetztesVarUpdateTimestamp"] = $VarLastUpdated; $Batterien_AR["Alle"][$a]["LetztesVarUpdateVorSek"] = $VarLastUpdatedDiffSek; $a++; } } } } if (isset($Batterien_AR)) { //Array sortieren, doppelte Einträge entfernen und neu durchnummerieren foreach ($Batterien_AR["Alle"] as $nr => $inhalt) { $nameALLE[$nr] = strtolower($inhalt["Name"]); if ($this->ReadPropertyBoolean("NamenParentObjekt1CB") == true) { $nameParent1ALLE[$nr] = $this->Umlaute_Ersetzen(strtolower($inhalt[$this->ReadPropertyString("NameParentTabelle1TB")])); } if ($this->ReadPropertyBoolean("NamenParentObjekt2CB") == true) { $nameParent2ALLE[$nr] = $this->Umlaute_Ersetzen(strtolower($inhalt[$this->ReadPropertyString("NameParentTabelle2TB")])); } if ($this->ReadPropertyBoolean("NamenParentObjekt3CB") == true) { $nameParent3ALLE[$nr] = $this->Umlaute_Ersetzen(strtolower($inhalt[$this->ReadPropertyString("NameParentTabelle3TB")])); } $batterieALLE[$nr] = strtolower($inhalt["Batterie"]); $herstellerALLE[$nr] = strtolower($inhalt["Hersteller"]); $idALLE[$nr] = strtolower($inhalt["ID"]); $herstelleridALLE[$nr] = strtolower($inhalt["Hersteller_ID"]); $lastupdatetsALLE[$nr] = strtolower($inhalt["LetztesVarUpdateTimestamp"]); $lastupdatevsALLE[$nr] = strtolower($inhalt["LetztesVarUpdateVorSek"]); } //Nach was soll das Array sortiert werden? if ($this->ReadPropertyString("ArraySortierWert") == "name") { array_multisort($nameALLE, SORT_ASC, $Batterien_AR["Alle"]); } elseif ($this->ReadPropertyString("ArraySortierWert") == "parentname1") { if ($this->ReadPropertyBoolean("NamenParentObjekt1CB") == true) { array_multisort($nameParent1ALLE, SORT_ASC, $Batterien_AR["Alle"]); } else { array_multisort($nameALLE, SORT_ASC, $Batterien_AR["Alle"]); } } elseif ($this->ReadPropertyString("ArraySortierWert") == "parentname2") { if ($this->ReadPropertyBoolean("NamenParentObjekt2CB") == true) { array_multisort($nameParent2ALLE, SORT_ASC, $Batterien_AR["Alle"]); } else { array_multisort($nameALLE, SORT_ASC, $Batterien_AR["Alle"]); } } elseif ($this->ReadPropertyString("ArraySortierWert") == "parentname3") { if ($this->ReadPropertyBoolean("NamenParentObjekt3CB") == true) { array_multisort($nameParent3ALLE, SORT_ASC, $Batterien_AR["Alle"]); } else { array_multisort($nameALLE, SORT_ASC, $Batterien_AR["Alle"]); } } elseif ($this->ReadPropertyString("ArraySortierWert") == "batterie") { array_multisort($batterieALLE, SORT_ASC, $Batterien_AR["Alle"]); } elseif ($this->ReadPropertyString("ArraySortierWert") == "hersteller") { array_multisort($herstellerALLE, SORT_ASC, $Batterien_AR["Alle"]); } elseif ($this->ReadPropertyString("ArraySortierWert") == "id") { array_multisort($idALLE, SORT_ASC, $Batterien_AR["Alle"]); } elseif ($this->ReadPropertyString("ArraySortierWert") == "letztesupdts") { array_multisort($lastupdatetsALLE, SORT_ASC, $Batterien_AR["Alle"]); } $Batterien_AR["Alle"] = $this->Array_UniqueBySubitem_Sort($Batterien_AR["Alle"], "Hersteller_ID"); $Batterien_AR["Alle"] = array_merge($Batterien_AR["Alle"]); if (isset($Batterien_AR["Leer"])) { foreach ($Batterien_AR["Leer"] as $nr => $inhalt) { $nameLEER[$nr] = strtolower($inhalt["Name"]); if ($this->ReadPropertyBoolean("NamenParentObjekt1CB") == true) { $nameParent1LEER[$nr] = $this->Umlaute_Ersetzen(strtolower($inhalt[$this->ReadPropertyString("NameParentTabelle1TB")])); } if ($this->ReadPropertyBoolean("NamenParentObjekt2CB") == true) { $nameParent2LEER[$nr] = $this->Umlaute_Ersetzen(strtolower($inhalt[$this->ReadPropertyString("NameParentTabelle2TB")])); } if ($this->ReadPropertyBoolean("NamenParentObjekt3CB") == true) { $nameParent3LEER[$nr] = $this->Umlaute_Ersetzen(strtolower($inhalt[$this->ReadPropertyString("NameParentTabelle3TB")])); } $batterieLEER[$nr] = strtolower($inhalt["Batterie"]); $herstellerLEER[$nr] = strtolower($inhalt["Hersteller"]); $idLEER[$nr] = strtolower($inhalt["ID"]); $herstelleridLEER[$nr] = strtolower($inhalt["Hersteller_ID"]); $lastupdatetsLEER[$nr] = strtolower($inhalt["LetztesVarUpdateTimestamp"]); $lastupdatevsLEER[$nr] = strtolower($inhalt["LetztesVarUpdateVorSek"]); } //Nach was soll das Array sortiert werden? if ($this->ReadPropertyString("ArraySortierWert") == "name") { array_multisort($nameLEER, SORT_ASC, $Batterien_AR["Leer"]); } elseif ($this->ReadPropertyString("ArraySortierWert") == "parentname1") { if ($this->ReadPropertyBoolean("NamenParentObjekt1CB") == true) { array_multisort($nameParent1LEER, SORT_ASC, $Batterien_AR["Leer"]); } else { array_multisort($nameLEER, SORT_ASC, $Batterien_AR["Leer"]); } } elseif ($this->ReadPropertyString("ArraySortierWert") == "parentname2") { if ($this->ReadPropertyBoolean("NamenParentObjekt2CB") == true) { array_multisort($nameParent2LEER, SORT_ASC, $Batterien_AR["Leer"]); } else { array_multisort($nameLEER, SORT_ASC, $Batterien_AR["Leer"]); } } elseif ($this->ReadPropertyString("ArraySortierWert") == "parentname3") { if ($this->ReadPropertyBoolean("NamenParentObjekt3CB") == true) { array_multisort($nameParent3LEER, SORT_ASC, $Batterien_AR["Leer"]); } else { array_multisort($nameLEER, SORT_ASC, $Batterien_AR["Leer"]); } } elseif ($this->ReadPropertyString("ArraySortierWert") == "batterie") { array_multisort($batterieLEER, SORT_ASC, $Batterien_AR["Leer"]); } elseif ($this->ReadPropertyString("ArraySortierWert") == "hersteller") { array_multisort($herstellerLEER, SORT_ASC, $Batterien_AR["Leer"]); } elseif ($this->ReadPropertyString("ArraySortierWert") == "id") { array_multisort($idLEER, SORT_ASC, $Batterien_AR["Leer"]); } elseif ($this->ReadPropertyString("ArraySortierWert") == "letztesupdts") { array_multisort($lastupdatetsLEER, SORT_ASC, $Batterien_AR["Leer"]); } $Batterien_AR["Leer"] = $this->Array_UniqueBySubitem_Sort($Batterien_AR["Leer"], "Hersteller_ID"); $Batterien_AR["Leer"] = array_merge($Batterien_AR["Leer"]); } return $Batterien_AR; } else { return false; } }
protected function GetBridge() { $instance = IPS_GetInstance($this->InstanceID); return ($instance['ConnectionID'] > 0) ? $instance['ConnectionID'] : false; }
/** * Forward weather data to WSDev instances * Create one if needed * @param $weather_data */ private function SendWSData($weather_data) { //parsing was OK, start distributing $this->debug(__FUNCTION__, 'Prepare'); $class = __CLASS__; $ts = $weather_data['date']; $datum = date('Y-m-d H:i:s', $ts); foreach ($this->sensors as $Device) { if (!isset($weather_data[$Device])) { continue; } $data = array(); $caps = ''; $id = $weather_data[$Device]['Id']; $typ = $weather_data[$Device]['Typ']; $data['Date'] = $datum; foreach ($this->fieldlist as $cap) { if (isset($weather_data[$Device][$cap])) { $data[$cap] = $weather_data[$Device][$cap]; $caps .= ";" . $cap; } } $this->debug(__FUNCTION__, "Sensor: {$id} Caps: {$caps} Prepared Data:" . print_r($data, true)); $found = false; $instID = 0; $instances = IPS_GetInstanceListByModuleID($this->module_interfaces['WSDEV']); foreach ($instances as $instID) { $I = @IPS_GetInstance($instID); if ($I && $I['ConnectionID'] == $this->InstanceID) { //my child $iid = (string) IPS_GetProperty($instID, 'DeviceID'); $ityp = (string) IPS_GetProperty($instID, 'Typ'); $iclass = (string) IPS_GetProperty($instID, 'Class'); if ($iid == $Device && $ityp == $typ && $iclass == $class) { $this->debug(__FUNCTION__, 'Use existing ID:' . $instID); $found = true; break; } //if destdevice } //if } //for if (!$found) { //no free instance available, have to create a new one if ($this->ReadPropertyBoolean('AutoCreate') == true) { //new instance needed $instID = $this->CreateWSDevice($data, $caps); if ($instID > 0) { //new instance needed $this->debug(__FUNCTION__, 'CREATE Device with Caps: ' . $caps); $found = true; } } else { $this->debug(__FUNCTION__, 'Creating Device ID ' . $Device . ' disabled by Property AutoCreate'); IPS_LogMessage($class, 'Creating Device ID ' . $Device . ' disabled by Property AutoCreate'); } //if autocreate } //if found if ($found && $instID > 0) { //send record to children $json = json_encode(array("DataID" => $this->module_interfaces['WS-RX'], "DeviceID" => $Device, "Typ" => $typ, "Class" => $class, "WSData" => $data)); $this->debug(__FUNCTION__, $json); @$this->SendDataToChildren($json); $this->log_weather($data); } //found } //for $this->debug(__FUNCTION__, 'Finished'); }
/** * Forward data to EnergyDev instances * Create one if needed * @param array $data * @param string $caps */ private function SendEnData($data, $caps) { //parsing was OK, start distributing $this->debug(__FUNCTION__, 'Prepare'); $class = $data['Class']; $id = $data['Id']; $typ = $data['Typ']; $found = false; $instID = 0; $instances = IPS_GetInstanceListByModuleID($this->module_interfaces['EnergyDev']); foreach ($instances as $instID) { $I = IPS_GetInstance($instID); $iid = (string) IPS_GetProperty($instID, 'DeviceID'); $ityp = (string) IPS_GetProperty($instID, 'Typ'); $iclass = (string) IPS_GetProperty($instID, 'Class'); if ($I['ConnectionID'] == $this->InstanceID) { //my child if ($iid == $id && $iclass == $class && $ityp == $typ) { $this->debug(__FUNCTION__, 'Use existing ID:' . $instID); $found = true; break; } //if destdevice } //if } //for if (!$found) { //no free instance available, have to create a new one if ($this->ReadPropertyBoolean('AutoCreate') == true) { //new instance needed $this->debug(__FUNCTION__, 'CREATE NEW Device'); $instID = $this->CreateENDevice($data, $caps); $found = true; } else { $this->debug(__FUNCTION__, 'Creating Device ID ' . $id . ' disabled by Property AutoCreate'); IPS_LogMessage($class, 'Creating Device ID ' . $id . ' disabled by Property AutoCreate'); } //if autocreate } //if found //drop counterfactor from data if (isset($data['CounterFactor'])) { unset($data['CounterFactor']); } if ($found && $instID > 0) { //send record to children $json = json_encode(array("DataID" => $this->module_interfaces['EN-RX'], "DeviceID" => $data['Id'], "Typ" => $data['Typ'], "Class" => $class, "ENData" => $data)); $this->debug(__FUNCTION__, $json); @$this->SendDataToChildren($json); $datum = date('Y-m-d H:i:s', time()); $vid = @$this->GetIDForIdent('LastUpdate'); if ($vid) { SetValueString($vid, $datum); } } //found }
private function deviceInstanceExists($name) { //if ($isUpdate) //{ $children = IPS_GetChildrenIDs($this->InstanceID); foreach ($children as $child) { if (IPS_InstanceExists($child)) { $childInstance = @IPS_GetInstance($child); $childInstanceID = $childInstance['InstanceID']; $childInstanceName = @IPS_GetName($childInstanceID); // Check if it is a Dummy Module and if it has a known device name if ($childInstanceName == $name and $childInstance['ModuleInfo']['ModuleID'] == "{485D0419-BE97-4548-AA9C-C083EB82E61E}") { return true; } } } return false; //} else { // return false; //} }
/** * Forward Energy data to EnergyDev instances * Create one if needed * @param $caps string * @param $data array */ private function SendENData($caps, $data) { $this->debug(__FUNCTION__, 'Prepare'); $datum = date('Y-m-d H:i:s', time()); $data['Date'] = $datum; $Device = $data['Id']; $typ = $data['Typ']; $branch = $data['Branch']; $found = false; $instID = 0; $class = __CLASS__ . "-EN"; $instances = IPS_GetInstanceListByModuleID($this->module_interfaces['EnergyDev']); foreach ($instances as $instID) { $I = IPS_GetInstance($instID); $iid = (string) IPS_GetProperty($instID, 'DeviceID'); $ityp = (string) IPS_GetProperty($instID, 'Typ'); $iclass = (string) IPS_GetProperty($instID, 'Class'); //$this->debug(__FUNCTION__, "Check my Device '$Device'' with Instance $instID($iid)"); if ($I['ConnectionID'] == $this->InstanceID) { //my child if ($iid == $Device && $iclass == $class && $ityp == $typ) { $this->debug(__FUNCTION__, 'Use existing ID:' . $instID); $found = true; break; } //if destdevice } //if } //for if (!$found) { //no free instance available, have to create a new one if ($this->ReadPropertyBoolean('AutoCreate') == true) { //new instance needed $this->debug(__FUNCTION__, 'CREATE NEW Energy Device ' . $Device); $instID = $this->CreateEnergyDevice($data, $caps); $found = true; } else { $this->debug(__FUNCTION__, "Creating XS1 {$branch} Energy Device " . $Device . ' disabled by Property AutoCreate'); IPS_LogMessage(__CLASS__, "Creating XS1 {$branch} Energy Device " . $Device . ' disabled by Property AutoCreate'); } //if autocreate } //if found if ($found && $instID > 0) { //send record to children $json = json_encode(array("DataID" => $this->module_interfaces['EN-RX'], "DeviceID" => $Device, "Typ" => $typ, "Class" => $class, "ENData" => $data)); $this->debug(__FUNCTION__, "Json:" . $json); @$this->SendDataToChildren($json); } //found }
protected function AddAddress($ITFamilyCode, $ITDeviceCode) { $instance = IPS_GetInstance($this->InstanceID)["InstanceID"]; IPS_SetProperty($instance, "ITFamilyCode", $ITFamilyCode); //ITFamilyCode setzten. IPS_SetProperty($instance, "ITDeviceCode", $ITDeviceCode); //ITDeviceCode setzten. IPS_SetProperty($instance, "LearnITCode", false); //Haken entfernen. IPS_ApplyChanges($instance); //Neue Konfiguration übernehmen IPS_LogMessage("IT FamilyCode hinzugefügt:", $ITFamilyCode); IPS_LogMessage("IT DeviceCode hinzugefügt:", $ITDeviceCode); // Status aktiv $this->SetStatus(102); $this->SetupVar(); $this->SetupProfiles(); }
protected function GetParent() { $instance = IPS_GetInstance($this->InstanceID); //array return $instance['ConnectionID'] > 0 ? $instance['ConnectionID'] : false; //ConnectionID }
/** * Forward weather data to WSDev instances * Create one if needed * @param $weather_data */ private function SendWSData($weather_data) { //parsing was OK, start distributing $this->debug(__FUNCTION__, 'Prepare '); //$this->debug(__FUNCTION__, 'Data:'. print_r($weather_data, true)); $dt = $weather_data['date']; $datum = date('Y-m-d H:i:s', $dt); for ($Device = 0; $Device < self::MAXSENSORS; $Device++) { if (!$weather_data['records'][$Device]['typ']) { continue; } $data = array(); $id = $weather_data['records'][$Device]['id']; $typ = $weather_data['records'][$Device]['typ']; //$sensor=$weather_data['records'][$Device]['sensor']; $temp = $weather_data['records'][$Device]['temp']; $hum = $weather_data['records'][$Device]['hum']; $data['Id'] = $id; $data['Typ'] = $typ; $data['Date'] = $datum; $caps = "Temp"; $data['Temp'] = $temp; if ($typ == 'T/F') { $data['Hum'] = $hum; $caps .= ";Hum"; } if ($Device < 9) { //innensensor hat keinenbatteryanzeige $lost = $weather_data['records'][$Device]['lost']; $bat = $weather_data['records'][$Device]['battery']; $data["Battery"] = $bat; $data["Lost"] = $lost; $caps .= ";Battery;Lost"; } if ($Device == 8) { $rain = $weather_data['rain']; $rainc = $weather_data['rainc']; $israining = $weather_data['israining']; $wind = $weather_data['wind']; $typ = 'Kombisensor'; $data['Typ'] = $typ; $data['Rain'] = $rain; $data['RainCounter'] = $rainc; $data['IsRaining'] = $israining; $data['Wind'] = $wind; $caps .= ";Wind;Rain;IsRaining;RainCounter"; } if ($Device == 9) { $typ = 'Indoor'; $press = $weather_data['press']; $willi = $weather_data['willi']; $data['Typ'] = $typ; $data["Press"] = $press; $data['Forecast'] = $willi; $caps .= ";Hum;Press;Forecast"; } if (strlen($temp) == 0) { continue; //nothing to send } //if temp //$this->debug(__FUNCTION__, "Sensor: $id Caps: $caps Data:" . print_r($data, true)); $found = false; $instID = 0; $instances = IPS_GetInstanceListByModuleID($this->module_interfaces['WSDEV']); foreach ($instances as $instID) { $I = @IPS_GetInstance($instID); if ($I && $I['ConnectionID'] == $this->InstanceID) { //my child $iid = (string) IPS_GetProperty($instID, 'DeviceID'); $ityp = (string) IPS_GetProperty($instID, 'Typ'); $class = (string) IPS_GetProperty($instID, 'Class'); if ($iid == $Device && $ityp == $typ && $class == __CLASS__) { $this->debug(__FUNCTION__, 'Use existing ID:' . $instID); $found = true; break; } //if destdevice } //if } //for if (!$found) { //no free instance available, have to create a new one if ($this->ReadPropertyBoolean('AutoCreate') == true) { //new instance needed $instID = $this->CreateWSDevice($data, $caps); if ($instID > 0) { //new instance needed $this->debug(__FUNCTION__, 'CREATE Device with Caps: ' . $caps); $found = true; } } else { $this->debug(__FUNCTION__, 'Creating Device ID ' . $Device . ' disabled by Property AutoCreate'); IPS_LogMessage(__CLASS__, 'Creating Device ID ' . $Device . ' disabled by Property AutoCreate'); } //if autocreate } //if found if ($found && $instID > 0) { //send record to children $json = json_encode(array("DataID" => $this->module_interfaces['WS-RX'], "DeviceID" => $Device, "Typ" => $typ, "Class" => __CLASS__, "WSData" => $data)); $this->debug(__FUNCTION__, $json); @$this->SendDataToChildren($json); } //found } //for $this->debug(__FUNCTION__, 'Finished'); $vid = $this->GetIDForIdent('LastUpdate'); SetValueString($vid, $datum); }
protected function AddAddress($address) { $instance = IPS_GetInstance($this->InstanceID)["InstanceID"]; IPS_SetProperty($instance, "AIOAdresse", $address); //FS20 Adresse setzten. IPS_SetProperty($instance, "LearnFS20Address", false); //Haken entfernen. IPS_ApplyChanges($instance); //Neue Konfiguration übernehmen IPS_LogMessage("FS20 Adresse hinzugefügt:", $address); // Status aktiv $this->SetStatus(102); $this->SetupVar(); $this->SetupProfiles(); }
public function setRadio() { // reset values SetValue($this->GetIDForIdent("DeviceMode"), ""); SetValue($this->GetIDForIdent("DeviceState"), ""); SetValue($this->GetIDForIdent("NowPlaying"), ""); SetValue($this->GetIDForIdent("Description"), ""); SetValue($this->GetIDForIdent("Logo"), ""); // get radio $instanceid = IPS_GetInstance($this->InstanceID)['InstanceID']; $stationname = GetValueFormatted($this->GetIDForIdent("Radio")); $associations = IPS_GetVariableProfile("bose.Device" . $instanceid . "RadioStations")["Associations"]; foreach ($associations as $key => $value) { if ($value["Name"] == $stationname) { $index = $value["Value"]; } } $associations = IPS_GetVariableProfile("bose.Device" . $instanceid . "RadioLocations")["Associations"]; foreach ($associations as $key => $value) { if ($value["Value"] == $index) { $location = $value["Name"]; } } // set location $timeout = $this->ReadPropertyString("Timeout"); $deviceip = $this->ReadPropertyString("DeviceIP"); try { if ($timeout && Sys_Ping($deviceip, $timeout) != true) { throw new Exception("Device " . $deviceip . " is not available"); } include_once __DIR__ . "/bose_soundtouch_api.php"; $bosedevice = new BoseSoundTouchAPI($deviceip); $result = $bosedevice->setDeviceRadioStationAPI($location); // get now playing ??? SetValue($this->GetIDForIdent("DevicePower"), true); } catch (Exception $e) { echo $e->getMessage(); } }
protected function DeleteInstance($InsID) { //Prüfen ob Instanz existiert $InstanzID = @IPS_GetInstance($InsID); if ($InstanzID === false) { //echo "Instanz nicht gefunden!"; //Instanz muss nicht gelöscht werden, existiert nicht. return $InsID; } else { //echo "Die Instanz-ID wurde gelöscht: ". $InstanzID; IPS_DeleteInstance($InsID); return $InstanzID; } }
/** * Forward Switch data to SwitchDev instances * Create one if needed * @param array $data */ private function SendSwitchData($data) { //parsing was OK, start distributing $this->debug(__FUNCTION__, 'Prepare'); $class = __CLASS__ . "-SW"; $Device = $data['DeviceID']; $typ = $data['Typ']; $found = false; $instID = 0; $caps = "Switch;Dimmer;Timer;FS20;TimerActionCode"; $instances = IPS_GetInstanceListByModuleID($this->module_interfaces['SwitchDev']); foreach ($instances as $instID) { $I = IPS_GetInstance($instID); $iid = (string) IPS_GetProperty($instID, 'DeviceID'); $ityp = (string) IPS_GetProperty($instID, 'Typ'); $iclass = (string) IPS_GetProperty($instID, 'Class'); $this->debug(__FUNCTION__, "Check my Device '{$Device}'' with Instance {$instID}({$iid})"); if ($I['ConnectionID'] == $this->InstanceID) { //my child if ($iid == $Device && $iclass == $class && $ityp == $typ) { $this->debug(__FUNCTION__, 'Use existing ID:' . $instID); $found = true; break; } //if destdevice } //if } //for if (!$found) { //no free instance available, have to create a new one if ($this->ReadPropertyBoolean('AutoCreate') == true) { //new instance needed $this->debug(__FUNCTION__, 'CREATE NEW Device'); $instID = $this->CreateSwitchDevice($data, $caps); $found = true; } else { $this->debug(__FUNCTION__, 'Creating FS20 Device ID ' . $Device . ' disabled by Property AutoCreate'); IPS_LogMessage($class, 'Creating FS20 Device ID ' . $Device . ' disabled by Property AutoCreate'); } //if autocreate } //if found if ($found && $instID > 0) { //send record to children $json = json_encode(array("DataID" => $this->module_interfaces['SWD-RX'], "DeviceID" => $data['DeviceID'], "Typ" => $data['Typ'], "Class" => $class, "SWData" => $data)); $this->debug(__FUNCTION__, $json); @$this->SendDataToChildren($json); $datum = date('Y-m-d H:i:s', time()); $vid = @$this->GetIDForIdent('LastUpdate'); if ($vid) { SetValueString($vid, $datum); } } //found }
protected function SetStatus($InstanceStatus) { if (IPS_GetKernelRunlevel() == KR_READY) { $OldStatus = IPS_GetInstance($this->InstanceID)['InstanceStatus']; } else { $OldStatus = -1; } if ($InstanceStatus != $OldStatus) { parent::SetStatus($InstanceStatus); } }
/** * Forward weather data to WSDev instances * Create one if needed * @param array $data * @param string $caps */ private function SendWSData($data, $caps) { //parsing was OK, start distributing $this->debug(__FUNCTION__, 'Prepare'); $class = __CLASS__; $id = $data['Id']; $typ = $data['Typ']; $this->debug(__FUNCTION__, 'GetInstance for Sensor:' . $id); $found = false; $instID = 0; $instances = IPS_GetInstanceListByModuleID($this->module_interfaces['WSDEV']); foreach ($instances as $instID) { $I = @IPS_GetInstance($instID); if ($I && $I['ConnectionID'] == $this->InstanceID) { //my child $iid = (string) IPS_GetProperty($instID, 'DeviceID'); $ityp = (string) IPS_GetProperty($instID, 'Typ'); $iclass = (string) IPS_GetProperty($instID, 'Class'); //$this->debug(__FUNCTION__, "Check my Device '$id'' with Instance $instID($iid)"); if ($iid == $id && $iclass == $class && $ityp == $typ) { $this->debug(__FUNCTION__, 'Use existing ID:' . $instID); $found = true; break; } //if destdevice } //if } //for if (!$found) { //no free instance available, have to create a new one if ($this->ReadPropertyBoolean('AutoCreate') == true) { //new instance needed $instID = $this->CreateWSDevice($data, $caps); if ($instID > 0) { //new instance needed $this->debug(__FUNCTION__, 'CREATE Device with Caps: ' . $caps); $found = true; } } else { $this->debug(__FUNCTION__, 'Creating Device ID ' . $id . ' disabled by Property AutoCreate'); IPS_LogMessage($class, 'Creating Device ID ' . $id . ' disabled by Property AutoCreate'); } //if autocreate } //if found if ($found && $instID > 0) { //send record to children $json = json_encode(array("DataID" => $this->module_interfaces['WS-RX'], "DeviceID" => $id, "Class" => $class, "Typ" => $typ, "WSData" => $data)); $this->debug(__FUNCTION__, $json); @$this->SendDataToChildren($json); $datum = date('Y-m-d H:i:s', time()); $vid = @$this->GetIDForIdent('LastUpdate'); if ($vid) { SetValueString($vid, $datum); } $this->log_weather($data); } //found }