public function ApplyChanges() { //Never delete this line! parent::ApplyChanges(); $change = false; // Zwangskonfiguration des ClientSocket $ParentID = $this->GetParent(); if (!($ParentID === false)) { if (IPS_GetProperty($ParentID, 'Host') != $this->ReadPropertyString('Host')) { IPS_SetProperty($ParentID, 'Host', $this->ReadPropertyString('Host')); $change = true; } if (IPS_GetProperty($ParentID, 'Port') != $this->ReadPropertyInteger('Port')) { IPS_SetProperty($ParentID, 'Port', $this->ReadPropertyInteger('Port')); $change = true; } $ParentOpen = $this->ReadPropertyBoolean('Open'); // Keine Verbindung erzwingen wenn Host leer ist, sonst folgt später Exception. if (IPS_GetProperty($ParentID, 'Open') != $ParentOpen) { IPS_SetProperty($ParentID, 'Open', $ParentOpen); $change = true; } if ($change) { @IPS_ApplyChanges($ParentID); } } /* Eigene Profile */ //Workaround für persistente Daten der Instanz // Wenn wir verbunden sind, am Gateway mit listen anmelden für Events if ($this->ReadPropertyBoolean('Open') and $this->HasActiveParent($ParentID)) { $this->SetStatus(102); } }
public function ApplyChanges() { //Never delete this line! parent::ApplyChanges(); //Variablenprofil erstellen $this->RegisterProfileBooleanEx("HMON.OfflineOnline", "Network", "", "", array(array(false, "Offline", "", 0xff0000), array(true, "Online", "", 0xff00))); if ($this->ReadPropertyString("HostName") != "" and $this->ReadPropertyString("HostAdresse") != "") { //Status setzen $this->SetStatus(102); //Variablen erstellen $this->RegisterVariableBoolean("HostStatus", "Host - Status", "HMON.OfflineOnline"); $this->RegisterVariableBoolean("HostBenachrichtigungsFlag", "Tmp"); IPS_SetHidden($this->GetIDForIdent("HostBenachrichtigungsFlag"), true); $this->RegisterVariableInteger("HostLastOnline", "Host - Zuletzt online", "~UnixTimestamp"); IPS_SetIcon($this->GetIDForIdent("HostLastOnline"), "Calendar"); //Logging aktivieren if ($this->ReadPropertyBoolean("LoggingAktiv") === true) { $ArchiveHandlerID = IPS_GetInstanceListByModuleID('{43192F0B-135B-4CE7-A0A7-1475603F3060}')[0]; AC_SetLoggingStatus($ArchiveHandlerID, $this->GetIDForIdent("HostStatus"), true); IPS_ApplyChanges($ArchiveHandlerID); } else { $ArchiveHandlerID = IPS_GetInstanceListByModuleID('{43192F0B-135B-4CE7-A0A7-1475603F3060}')[0]; AC_SetLoggingStatus($ArchiveHandlerID, $this->GetIDForIdent("HostStatus"), false); IPS_ApplyChanges($ArchiveHandlerID); } //Timer erstellen $this->SetTimerInterval("HMON_UpdateTimer", $this->ReadPropertyInteger("Intervall")); $this->SetTimerByIdent_InSekunden("HMON_BenachrichtigungOfflineTimer", false); IPS_SetHidden($this->GetIDForIdent("HMON_BenachrichtigungOfflineTimer"), true); //Update $this->Update(); } else { $this->SetStatus(206); } //Fehlerhafte Konfiguration melden if ($this->ReadPropertyBoolean("PushMsgAktiv") === true and $this->ReadPropertyInteger("WebFrontInstanceID") == "") { $this->SetStatus(201); } if ($this->ReadPropertyBoolean("EMailMsgAktiv") === true and $this->ReadPropertyInteger("SmtpInstanceID") == "") { $this->SetStatus(202); } if ($this->ReadPropertyBoolean("EigenesSkriptAktiv") === true and $this->ReadPropertyInteger("EigenesSkriptID") == "") { $this->SetStatus(203); } if ($this->ReadPropertyBoolean("PushMsgAktiv") === false and $this->ReadPropertyBoolean("EMailMsgAktiv") === false and $this->ReadPropertyBoolean("EigenesSkriptAktiv") === false and $this->ReadPropertyBoolean("OfflineBenachrichtigung") === true) { $this->SetStatus(204); } if ($this->ReadPropertyBoolean("OfflineBenachrichtigung") === false and $this->ReadPropertyBoolean("OnlineBenachrichtigung") === true) { $this->SetStatus(205); } }
public function ApplyChanges() { //Never delete this line! parent::ApplyChanges(); if (trim($this->ReadPropertyString('Apikey')) == "") { $this->SetStatus(104); } else { $this->SetStatus(102); } if (trim($this->ReadPropertyString('Apikey')) != $this->ReadPropertyString('Apikey')) { @IPS_SetProperty($this->InstanceID, 'Apikey', trim($this->ReadPropertyString('Apikey'))); @IPS_ApplyChanges($this->InstanceID); } }
public function ApplyChanges() { // Diese Zeile nicht löschen parent::ApplyChanges(); //Variablenprofil anlegen if (!IPS_VariableProfileExists("Megabyte")) { IPS_CreateVariableProfile("Megabyte", 2); IPS_SetVariableProfileValues("Megabyte", 0, 0, 2); IPS_SetVariableProfileText("Megabyte", "", " MB"); } if ($this->ReadPropertyString("IPS_Pfad") != "" and $this->ReadPropertyString("Netzwerkkarte") != "") { //Variablen erstellen $this->RegisterVariableFloat("CPU_idle", "CPU-Auslastung", "Humidity.F", 1); $this->RegisterVariableFloat("CPU_volts", "CPU-Spannung", "Volt", 2); $this->RegisterVariableFloat("CPU_temp", "CPU-Temperatur", "Temperature", 3); $this->RegisterVariableFloat("HDD_total", "Gesamt Speicherplatz", "Megabyte", 4); $this->RegisterVariableFloat("HDD_used", "Belegter Speicherplatz", "Megabyte", 5); $this->RegisterVariableFloat("HDD_percent", "HDD-Belegung", "Humidity.F", 6); $this->RegisterVariableFloat("HDD_symcon", "IPS-Speicherbelegung", "Megabyte", 7); $this->RegisterVariableFloat("RAM_total", "Gesamt RAM", "Megabyte", 8); $this->RegisterVariableFloat("RAM_used", "Benutzer RAM", "Megabyte", 9); $this->RegisterVariableFloat("RAM_percent", "RAM-Auslastung", "Humidity.F", 10); $this->RegisterVariableString("System_Info", "System Informationen", "HTMLBox", 11); //Timer zeit setzen $this->SetTimerInterval("Update", $this->ReadPropertyInteger("UpdateInterval") * 1000); } else { //Instanz ist inaktiv $this->SetStatus(104); } //Variablen Logging Aktivieren / Deaktivieren $archiveHandlerID = IPS_GetInstanceListByModuleID('{43192F0B-135B-4CE7-A0A7-1475603F3060}')[0]; AC_SetLoggingStatus($archiveHandlerID, $this->GetIDForIdent("CPU_idle"), $this->ReadPropertyBoolean("logCPU_idle")); AC_SetLoggingStatus($archiveHandlerID, $this->GetIDForIdent("CPU_volts"), $this->ReadPropertyBoolean("logCPU_volts")); AC_SetLoggingStatus($archiveHandlerID, $this->GetIDForIdent("CPU_temp"), $this->ReadPropertyBoolean("logCPU_temp")); AC_SetLoggingStatus($archiveHandlerID, $this->GetIDForIdent("HDD_total"), $this->ReadPropertyBoolean("logHDD_total")); AC_SetLoggingStatus($archiveHandlerID, $this->GetIDForIdent("HDD_used"), $this->ReadPropertyBoolean("logHDD_used")); AC_SetLoggingStatus($archiveHandlerID, $this->GetIDForIdent("HDD_percent"), $this->ReadPropertyBoolean("logHDD_percent")); AC_SetLoggingStatus($archiveHandlerID, $this->GetIDForIdent("HDD_symcon"), $this->ReadPropertyBoolean("logHDD_symcon")); AC_SetLoggingStatus($archiveHandlerID, $this->GetIDForIdent("RAM_total"), $this->ReadPropertyBoolean("logRAM_total")); AC_SetLoggingStatus($archiveHandlerID, $this->GetIDForIdent("RAM_used"), $this->ReadPropertyBoolean("logRAM_used")); AC_SetLoggingStatus($archiveHandlerID, $this->GetIDForIdent("RAM_percent"), $this->ReadPropertyBoolean("logRAM_percent")); IPS_ApplyChanges($archiveHandlerID); copy(IPS_GetKernelDir() . "modules/IPS_PI_Monitor/PI_Monitor/Raspi-PGB001.png", IPS_GetKernelDir() . "webfront/user/Raspi-PGB001.png"); }
private function RegisterHook($Hook, $TargetID) { $ids = IPS_GetInstanceListByModuleID("{015A6EB8-D6E5-4B93-B496-0D3F77AE9FE1}"); if (sizeof($ids) > 0) { $hooks = json_decode(IPS_GetProperty($ids[0], "Hooks"), true); $found = false; foreach ($hooks as $index => $hook) { if ($hook['Hook'] == "/hook/locative") { if ($hook['TargetID'] == $TargetID) { return; } $hooks[$index]['TargetID'] = $TargetID; $found = true; } } if (!$found) { $hooks[] = array("Hook" => "/hook/locative", "TargetID" => $TargetID); } IPS_SetProperty($ids[0], "Hooks", json_encode($hooks)); IPS_ApplyChanges($ids[0]); } }
public function ApplyChanges() { // get instance id $instanceid = IPS_GetInstance($this->InstanceID)['InstanceID']; // rename instance $room = $this->ReadPropertyString("Room"); if ($room != "") { IPS_SetName($instanceid, $room); } // check device $deviceip = $this->ReadPropertyString("DeviceIP"); $timeout = $this->ReadPropertyString("Timeout"); if ($deviceip != "") { // check device availability if ($timeout && Sys_Ping($deviceip, $timeout) != true) { // throw new Exception("Device ".$deviceip." is not available"); die("Unable to connect to device {$deviceip}"); } include_once __DIR__ . "/bose_soundtouch_api.php"; $bosedevice = new BoseSoundTouchAPI($deviceip); $result = $bosedevice->getDeviceNowPlayingAPI(); // get device id for multiroom $deviceid = $this->ReadPropertyString("DeviceID"); if ($deviceid == "" and $deviceip != "") { $deviceid = $result['deviceid']; IPS_SetProperty($instanceid, "DeviceID", "" . $deviceid . ""); if (IPS_HasChanges($instanceid)) { IPS_ApplyChanges($instanceid); } } } // never delete this line! parent::ApplyChanges(); ///////////////////////////////////////////////////////////////////////////////////////////////////////// // create profiles ///////////////////////////////////////////////////////////////////////////////////////////////////////// //create zone profiles for multiroom $allboseinstances = IPS_GetInstanceListByModuleID("{4836EF46-FF79-4D6A-91C9-FE54F1BDF2DB}"); // create profile for each instance / device foreach ($allboseinstances as $key => $instanceid) { $multiroomprofilename = "bose.Device" . $instanceid . "MasterZones"; // delete zone profiles if (IPS_VariableProfileExists($multiroomprofilename)) { IPS_DeleteVariableProfile($multiroomprofilename); } IPS_CreateVariableProfile($multiroomprofilename, 1); // set values for profile foreach ($allboseinstances as $key => $value) { if ($instanceid == $value) { IPS_SetVariableProfileAssociation($multiroomprofilename, "0", "Off", "", 0xff); } else { $instancename = IPS_GetName($value); if ($instancename != "") { IPS_SetVariableProfileAssociation($multiroomprofilename, "" . ($key + 1) . "", "" . $instancename . "", "", 0xff); } } } } // create volume slider profile $volumesliderprofilename = "bose.VolumeSlider"; if (!IPS_VariableProfileExists($volumesliderprofilename)) { IPS_CreateVariableProfile($volumesliderprofilename, 1); } IPS_SetVariableProfileValues($volumesliderprofilename, 0, 100, 1); IPS_SetVariableProfileText($volumesliderprofilename, "", "%"); IPS_SetVariableProfileIcon($volumesliderprofilename, "Speaker"); // play pause preset $playpauseprofilename = "bose.PlayPause"; if (!IPS_VariableProfileExists($playpauseprofilename)) { IPS_CreateVariableProfile($playpauseprofilename, 1); } IPS_SetVariableProfileAssociation($playpauseprofilename, "0", "Pause", "", 0xff); IPS_SetVariableProfileAssociation($playpauseprofilename, "1", "Play", "", 0xff); IPS_SetVariableProfileIcon($playpauseprofilename, "HollowArrowRight"); // create presets and radiolocations profiles $instanceid = IPS_GetInstance($this->InstanceID)['InstanceID']; $radiostationsprofilename = "bose.Device" . $instanceid . "RadioStations"; if (!IPS_VariableProfileExists($radiostationsprofilename)) { IPS_CreateVariableProfile($radiostationsprofilename, 1); } $radiolocationsprofilename = "bose.Device" . $instanceid . "RadioLocations"; if (!IPS_VariableProfileExists($radiolocationsprofilename)) { IPS_CreateVariableProfile($radiolocationsprofilename, 1); } // get device presets if ($deviceip != "") { include_once __DIR__ . "/bose_soundtouch_api.php"; $bosedevice = new BoseSoundTouchAPI($deviceip); $result = $bosedevice->getDevicePresetsAPI(); for ($i = 0; $i < 6; $i++) { $value = $i + 1; $radiostationname = $result->preset[$i]->ContentItem->itemName; $radiostationlocation = $result->preset[$i]->ContentItem["location"]; IPS_SetVariableProfileAssociation($radiostationsprofilename, "" . $value . "", "" . $radiostationname . "", "", 0xff); IPS_SetVariableProfileAssociation($radiolocationsprofilename, "" . $value . "", "" . $radiostationlocation . "", "", 0xff); } IPS_SetVariableProfileIcon($radiostationsprofilename, "Cloud"); } // create timer hour profile $timerhourprofilename = "bose.TimerHour"; if (!IPS_VariableProfileExists($timerhourprofilename)) { IPS_CreateVariableProfile($timerhourprofilename, 1); } $i = 0; for ($i = 0; $i < 24; $i++) { IPS_SetVariableProfileAssociation($timerhourprofilename, $i, $i, "", 0xff); } IPS_SetVariableProfileIcon($timerhourprofilename, "Clock"); // create timer minute profile $timerminuteprofilename = "bose.TimerMinute"; if (!IPS_VariableProfileExists($timerminuteprofilename)) { IPS_CreateVariableProfile($timerminuteprofilename, 1); } $i = 0; for ($i = 0; $i <= 55; $i = $i + 5) { IPS_SetVariableProfileAssociation($timerminuteprofilename, $i, $i, "", 0xff); } IPS_SetVariableProfileIcon($timerminuteprofilename, "Clock"); ///////////////////////////////////////////////////////////////////////////////////////////////////////// // register variables ///////////////////////////////////////////////////////////////////////////////////////////////////////// // device power $this->RegisterVariableBoolean("DevicePower", "Device Power", "~Switch", 1); $this->EnableAction("DevicePower"); SetValue($this->GetIDForIdent("DevicePower"), 0); // volume slider $this->RegisterVariableInteger("VolumeSlider", "Volume", "bose.VolumeSlider", 2); $this->EnableAction("VolumeSlider"); SetValue($this->GetIDForIdent("VolumeSlider"), 10); // play pause $this->RegisterVariableInteger("PlayPause", "Play / Pause", "bose.PlayPause", 3); $this->EnableAction("PlayPause"); SetValue($this->GetIDForIdent("PlayPause"), true); // join zone (multiroom) $instanceid = IPS_GetInstance($this->InstanceID)['InstanceID']; $this->RegisterVariableInteger("JoinZone", "Join Zone (MultiRoom)", "bose.Device" . $instanceid . "MasterZones", 4); $this->EnableAction("JoinZone"); IPS_SetIcon($this->GetIDForIdent("JoinZone"), "Network"); SetValue($this->GetIDForIdent("JoinZone"), 0); // radio $this->RegisterVariableInteger("Radio", "Radio", "bose.Device" . $instanceid . "RadioStations", 5); $this->EnableAction("Radio"); SetValue($this->GetIDForIdent("Radio"), 1); // device mode $this->RegisterVariableString("DeviceMode", "Device Mode", "", 7); IPS_SetIcon($this->GetIDForIdent("DeviceMode"), "Information"); // device state $this->RegisterVariableString("DeviceState", "Device State", "", 8); IPS_SetIcon($this->GetIDForIdent("DeviceState"), "Information"); // now playing $this->RegisterVariableString("NowPlaying", "Now Playing", "", 9); IPS_SetIcon($this->GetIDForIdent("NowPlaying"), "Information"); // description $this->RegisterVariableString("Description", "Description", "", 10); IPS_SetIcon($this->GetIDForIdent("Description"), "Information"); // logo $this->RegisterVariableString("Logo", "Logo", "~HTMLBox", 11); IPS_SetIcon($this->GetIDForIdent("Logo"), "Information"); // timer hour $this->RegisterVariableInteger("TimerHour", "Timer Hour", "bose.TimerHour", 12); $this->EnableAction("TimerHour"); SetValue($this->GetIDForIdent("TimerHour"), 12); // timer minute $this->RegisterVariableInteger("TimerMinute", "Timer Minute", "bose.TimerMinute", 13); $this->EnableAction("TimerMinute"); SetValue($this->GetIDForIdent("TimerMinute"), 0); // alarm clock $this->RegisterVariableBoolean("AlarmClock", "Alarm Clock", "~Switch", 14); $this->EnableAction("AlarmClock"); SetValue($this->GetIDForIdent("AlarmClock"), false); // volume fade in $this->RegisterVariableBoolean("VolumeFadeIn", "Volume Fade In (15 min)", "~Switch", 15); $this->EnableAction("VolumeFadeIn"); SetValue($this->GetIDForIdent("VolumeFadeIn"), false); // next power on $this->RegisterVariableString("NextPowerOn", "Next Power On", "", 16); IPS_SetIcon($this->GetIDForIdent("NextPowerOn"), "Information"); // alarm cycle IPS_SetHidden($this->RegisterVariableString("AlarmCycle", "Alarm Cycle", "", 17), true); SetValue($this->GetIDForIdent("AlarmCycle"), 0); // alarm radio station IPS_SetHidden($this->RegisterVariableString("AlarmRadioStation", "Alarm Radio Station", "", 18), true); SetValue($this->GetIDForIdent("VolumeFadeIn"), false); // alarm clock volume IPS_SetHidden($this->RegisterVariableInteger("AlarmClockVolume", "Alarm Clock Volume", "bose.VolumeSlider", 19), true); SetValue($this->GetIDForIdent("AlarmRadioStation"), ""); // sleep timer $this->RegisterVariableBoolean("SleepTimer", "Sleep Timer", "~Switch", 20); $this->EnableAction("SleepTimer"); SetValue($this->GetIDForIdent("SleepTimer"), false); // volume fade out $this->RegisterVariableBoolean("VolumeFadeOut", "Volume Fade Out (15 min)", "~Switch", 21); $this->EnableAction("VolumeFadeOut"); SetValue($this->GetIDForIdent("VolumeFadeOut"), false); // good night $this->RegisterVariableBoolean("GoodNight", "Good Night (30 min)", "~Switch", 22); IPS_SetIcon($this->GetIDForIdent("GoodNight"), "Moon"); $this->EnableAction("GoodNight"); SetValue($this->GetIDForIdent("GoodNight"), false); // next power off $this->RegisterVariableString("NextPowerOff", "Next Power Off", "", 23); IPS_SetIcon($this->GetIDForIdent("NextPowerOff"), "Information"); SetValue($this->GetIDForIdent("NextPowerOff"), ""); // sleep cycle IPS_SetHidden($this->RegisterVariableString("SleepCycle", "Sleep Cycle", "", 24), true); SetValue($this->GetIDForIdent("SleepCycle"), 0); ///////////////////////////////////////////////////////////////////////////////////////////////////////// // create scripts ///////////////////////////////////////////////////////////////////////////////////////////////////////// // device information script $DeviceInformationControlScript = '<? /* SymconBoseSoundTouch Bose SoundTouch Module for IP-Symcon filename: DeviceInformationControl.php description: Device Information Control Script version 1.0.1 date: 13.01.2016 publisher: Copyright (c) 2015, 2016 Ulrich Bittner license: CC BY-NC 4.0 Creative Commons Attribution-NonCommercial 4.0 International License environment: IP-Symcon 4.0 (beta) on RPi changelog: version 1.0.1 13.01.2016 multiroom fix for single device version 1.0.0 28.12.2015 initialscript todo: (none) github: https://github.com/ubittner/SymconBoseSoundTouch.git symcon forum: https://www.symcon.de/forum/threads/29922-Bose-SoundTouch-Modul */ if ($_IPS["SENDER"] == "Execute") { addRadioStations(); } if ($_IPS["SENDER"] == "TimerEvent") { getDeviceInformation(); } function addRadioStations() { // Radio Stations // if you want less radio stations, delete the unnecessary positions // if you want to have more radio stations, add positions // get the radio station location id from www.vtuner.com // http://vtuner.com/setupapp/guide/asp/BrowseStations/startpage.asp // example for WDR 2 Ruhrgebiet // url: http://www.vtuner.com/vtunerweb/mms/m3u32760.m3u // location = 32760 // Radio Station 7 $RadioStations["station7"]["name"] = "AH.FM"; $RadioStations["station7"]["location"] = "24836"; // Radio Station 8 $RadioStations["station8"]["name"] = "Sunshine Live Classics"; $RadioStations["station8"]["location"] = "44882"; // Radio Station 9 $RadioStations["station9"]["name"] = "Sunshine Live Trance"; $RadioStations["station9"]["location"] = "48651"; // Radio Station 10 $RadioStations["station10"]["name"] = "Sunshine Live Be Easy"; $RadioStations["station10"]["location"] = "44879"; // Radio Station 11 $RadioStations["station11"]["name"] = "Sunshine Live Be DJ"; $RadioStations["station11"]["location"] = "44881"; // Radio Station 12 $RadioStations["station12"]["name"] = "Sunshine Live Radioclub"; $RadioStations["station12"]["location"] = "62373"; // Radio Station 13 $RadioStations["station13"]["name"] = "SPORT1.fm"; $RadioStations["station13"]["location"] = "52773"; // Radio Station 14 $RadioStations["station14"]["name"] = "SPORT1.fm Spiel1"; $RadioStations["station14"]["location"] = "53341"; // Radio Station 15 $RadioStations["station15"]["name"] = "SPORT1.fm Spiel2"; $RadioStations["station15"]["location"] = "53343"; // Radio Station 16 $RadioStations["station16"]["name"] = "SPORT1.fm Spiel3"; $RadioStations["station16"]["location"] = "53344"; // Radio Station 17 $RadioStations["station17"]["name"] = "SPORT1.fm Spiel4"; $RadioStations["station17"]["location"] = "53346"; // Radio Station 18 $RadioStations["station18"]["name"] = "SPORT1.fm Spiel5"; $RadioStations["station18"]["location"] = "53347"; // Radio Station 19 $RadioStations["station19"]["name"] = "SPORT1.fm Spiel6"; $RadioStations["station19"]["location"] = "53349"; // Radio Station 20 $RadioStations["station20"]["name"] = "WDR2 Ruhrgebiet"; $RadioStations["station20"]["location"] = "32760"; // Radio Station 21 $RadioStations["station21"]["name"] = "BFBS Germany"; $RadioStations["station21"]["location"] = "35142"; // extend radio station and radio location profile $instanceid = IPS_GetParent($_IPS["SELF"]); $presetprofilename = "bose.Device".$instanceid."RadioStations"; $radiolocationsprofilename = "bose.Device".$instanceid."RadioLocations"; $variable = $RadioStations; $i = 7; foreach ($variable as $key => $value) { $radiostationname = $value["name"]; $radiostationlocation = $value["location"]; IPS_SetVariableProfileAssociation($presetprofilename, "".$i."", "".$radiostationname."", "", 0x0000FF); IPS_SetVariableProfileAssociation($radiolocationsprofilename, "".$i."", "".$radiostationlocation."", "", 0x0000FF); $i++; } } function getDeviceInformation() { $deviceip = IPS_GetProperty(IPS_GetParent($_IPS["SELF"]), "DeviceIP"); $timeout = IPS_GetProperty(IPS_GetParent($_IPS["SELF"]), "Timeout"); $instanceid = IPS_GetParent($_IPS["SELF"]); if ($deviceip == "") { die; } try { // check device availibility if ($timeout && Sys_Ping($deviceip, $timeout) != true) { throw new Exception("Device ".$deviceip." is not available"); } include_once("../modules/SymconBoseSoundTouch/Bose/bose_soundtouch_api.php"); $bosedevice = new BoseSoundTouchAPI($deviceip); $result = $bosedevice->getDeviceNowPlayingAPI(); // power switch if ($result["devicemode"] == "Standby") { $powerstate = false; } else { $powerstate = true; } $powerswitch = GetValue(IPS_GetObjectIDByName("Device Power", IPS_GetParent($_IPS["SELF"]))); if ($powerstate <> $powerswitch) { SetValue(IPS_GetObjectIDByName("Device Power", IPS_GetParent($_IPS["SELF"])), $powerstate); } // device mode $devicemode = GetValue(IPS_GetObjectIDByName("Device Mode", IPS_GetParent($_IPS["SELF"]))); if ($result["devicemode"] <> $devicemode) { SetValue(IPS_GetObjectIDByName("Device Mode", IPS_GetParent($_IPS["SELF"])), $result["devicemode"]); } // device state $devicestate = GetValue(IPS_GetObjectIDByName("Device State", IPS_GetParent($_IPS["SELF"]))); if ($result["devicestate"] <> $devicestate) { SetValue(IPS_GetObjectIDByName("Device State", IPS_GetParent($_IPS["SELF"])), $result["devicestate"]); } // now playing $nowplaying = GetValue(IPS_GetObjectIDByName("Now Playing", IPS_GetParent($_IPS["SELF"]))); if ($result["nowplaying"] <> $nowplaying) { SetValue(IPS_GetObjectIDByName("Now Playing", IPS_GetParent($_IPS["SELF"])), $result["nowplaying"]); $instanceid = IPS_GetParent($_IPS["SELF"]); $associations = IPS_GetVariableProfile("bose.Device".$instanceid."RadioStations")["Associations"]; $index = 0; foreach($associations as $key => $value) { if ($value["Name"] == $result["nowplaying"]) { $index = $value["Value"]; } } if ($index <> 0){ SetValue(IPS_GetObjectIDByName("Radio", IPS_GetParent($_IPS["SELF"])), $index); } } // description $description = GetValue(IPS_GetObjectIDByName("Description", IPS_GetParent($_IPS["SELF"]))); if ($result["description"] <> $description) { SetValue(IPS_GetObjectIDByName("Description", IPS_GetParent($_IPS["SELF"])), $result["description"]); } // logo $logo = GetValue(IPS_GetObjectIDByName("Logo", IPS_GetParent($_IPS["SELF"]))); if ($result["logourl"] <> $logo) { SetValue(IPS_GetObjectIDByName("Logo", IPS_GetParent($_IPS["SELF"])), $result["logourl"]); } // volume $result = $bosedevice->getDeviceVolumeAPI(); $volumeslider = GetValue(IPS_GetObjectIDByName("Volume", IPS_GetParent($_IPS["SELF"]))); if ($result["actualvolume"] <> $volumeslider) { SetValue(IPS_GetObjectIDByName("Volume", IPS_GetParent($_IPS["SELF"])), $result["actualvolume"]); } // zone $allboseinstances = IPS_GetInstanceListByModuleID("{4836EF46-FF79-4D6A-91C9-FE54F1BDF2DB}"); $numberofdevices = count($allboseinstances); if ($numberofdevices >1) { $result = $bosedevice->getDeviceZoneAPI(); $zonemasterid = $result["zonemasterid"]; $zonememberid = $result["zonememberid"]; $deviceid = IPS_GetProperty(IPS_GetParent($_IPS["SELF"]), "DeviceID"); $zonemembers = $result["zonememberid"]; $zonemember = false; $masterzone = 0; foreach ($zonemembers as $key => $value) { // device is member if ($value == $deviceid) { // device is the master if ($zonemasterid == $deviceid) { $masterzone = 0; } // get zone master else { $allboseinstances = IPS_GetInstanceListByModuleID("{4836EF46-FF79-4D6A-91C9-FE54F1BDF2DB}"); foreach ($allboseinstances as $key => $value) { $masterdeviceid = IPS_GetProperty($value, "DeviceID"); if ($masterdeviceid == $zonemasterid) { $zonemastername = IPS_GetName($value); } } $associations = IPS_GetVariableProfile("bose.Device".$instanceid."MasterZones")["Associations"]; foreach($associations as $key => $value) { if ($value["Name"] == $zonemastername) { $masterzone = $value["Value"]; } } } } } $zonestate = GetValue(IPS_GetObjectIDByName("Join Zone (MultiRoom)", IPS_GetParent($_IPS["SELF"]))); if ($masterzone <> $zonestate) { SetValue(IPS_GetObjectIDByName("Join Zone (MultiRoom)", IPS_GetParent($_IPS["SELF"])), $masterzone); } } } // error message catch (Exception $e) { echo $e->getMessage(); } } ?>'; // create script $deviceinformationcontrolscriptid = @$this->GetIDForIdent("DeviceInformationControl"); if ($deviceinformationcontrolscriptid === false) { $deviceinformationcontrolscriptid = $this->RegisterScript("DeviceInformationControl", "DeviceInformationControl", $DeviceInformationControlScript, 0); } else { IPS_SetScriptContent($deviceinformationcontrolscriptid, $DeviceInformationControlScript); } IPS_SetHidden($deviceinformationcontrolscriptid, true); IPS_SetScriptTimer($deviceinformationcontrolscriptid, 5); // alarm clock script $AlarmClockControlScript = '<? /* SymconBoseSoundTouch Bose SoundTouch Module for IP-Symcon filename: AlarmClockControl.php description: Alarm Clock Control Script version 1.0.0 date: 28.12.2015 publisher: Copyright (c) 2015, 2016 Ulrich Bittner license: CC BY-NC 4.0 Creative Commons Attribution-NonCommercial 4.0 International License environment: IP-Symcon 4.0 (beta) on RPi changelog: version 1.0.0 28.12.2015 initialscript todo: (none) github: https://github.com/ubittner/SymconBoseSoundTouch.git symcon forum: https://www.symcon.de/forum/threads/29922-Bose-SoundTouch-Modul */ // variable definitions $instanceid = IPS_GetParent(IPS_GetParent($_IPS["SELF"])); $deviceip = IPS_GetProperty($instanceid, "DeviceIP"); $timeout = IPS_GetProperty($instanceid, "Timeout"); $alarmclockscriptid = IPS_GetScriptIDByName("AlarmClockControl", IPS_GetParent($_IPS["SELF"])); $alarmclockeventid = @IPS_GetEventIDByName("AlarmClockEvent", $alarmclockscriptid); $alarmclockcycleseconds = GetValue(IPS_GetObjectIDByName("Alarm Cycle", $instanceid)); // get actual device mode try { // check device availibility if ($timeout && Sys_Ping($deviceip, $timeout) != true) { throw new Exception("Device ".$deviceip." is not available"); } include_once("../modules/SymconBoseSoundTouch/Bose/bose_soundtouch_api.php"); $bosedevice = new BoseSoundTouchAPI($deviceip); // get device mode $result = $bosedevice->getDeviceNowPlayingAPI(); $devicemode = $result["devicemode"]; // get volume $result = $bosedevice->getDeviceVolumeAPI(); SetValue(IPS_GetObjectIDByName("Volume", $instanceid), $result["actualvolume"]); // power device on if ($devicemode == "Standby"){ $result = $bosedevice->powerDeviceAPI(); // set radio station $alarmradiostation = GetValue(IPS_GetObjectIDByName("Alarm Radio Station", $instanceid)); SetValue(IPS_GetObjectIDByName("Radio", $instanceid), $alarmradiostation); $associations = IPS_GetVariableProfile("bose.Device".$instanceid."RadioLocations")["Associations"]; foreach($associations as $key => $value) { if ($value["Value"] == $alarmradiostation) { $location = $value["Name"]; } } $result = $bosedevice->setDeviceRadioStationAPI($location); if ($alarmclockcycleseconds <> 0) { $volume = 1; $result = $bosedevice->setDeviceVolumeAPI($volume); SetValue(IPS_GetObjectIDByName("Volume", $instanceid), $volume); setNewEventCycleTime(); } else { switchAlarmClockOff(); } SetValue(IPS_GetObjectIDByName("Device Power", $instanceid), true); // get now playing getnowplaying: $result = $bosedevice->getDevicenowPlayingAPI(); if ($result["devicestate"] == "Reload") { goto getnowplaying; } SetValue(IPS_GetObjectIDByName("Device Mode", $instanceid), $result["devicemode"]); SetValue(IPS_GetObjectIDByName("Device State", $instanceid), $result["devicestate"]); SetValue(IPS_GetObjectIDByName("Now Playing", $instanceid), $result["nowplaying"]); SetValue(IPS_GetObjectIDByName("Description", $instanceid), $result["description"]); SetValue(IPS_GetObjectIDByName("Logo", $instanceid), $result["logourl"]); } // device is already on else { if ($alarmclockcycleseconds <> 0) { $actualvolume = GetValue(IPS_GetObjectIDByName("Volume", $instanceid)); $alarmclockvolume = GetValue(IPS_GetObjectIDByName("Alarm Clock Volume", $instanceid)); if ($actualvolume < $alarmclockvolume) { $targetvolume = ($actualvolume+1); $result = $bosedevice->setDeviceVolumeAPI($targetvolume); SetValue(IPS_GetObjectIDByName("Volume", $instanceid), $targetvolume); setNewEventCycleTime(); } else { switchAlarmClockOff(); } } } } // error message catch (Exception $e) { echo $e->getMessage(); } // set new event cycle time function setNewEventCycleTime() { global $alarmclockeventid, $alarmclockcycleseconds; $eventinfo = IPS_GetEvent($alarmclockeventid); $eventtimestamp = ($eventinfo["NextRun"]); $neweventtimestamp = strtotime("+ " .$alarmclockcycleseconds. " seconds", $eventtimestamp); $newhour = date("H",$neweventtimestamp); $newminute = date("i",$neweventtimestamp); $newsecond = date("s",$neweventtimestamp); IPS_SetEventCyclicTimeFrom($alarmclockeventid, $newhour, $newminute, $newsecond); IPS_SetEventActive($alarmclockeventid, true); } // switch alarm clock off function switchAlarmClockOff() { global $instanceid, $alarmclockeventid; SetValue(IPS_GetObjectIDByName("Alarm Clock", $instanceid), false); IPS_SetEventActive($alarmclockeventid, false); SetValue(IPS_GetObjectIDByName("Alarm Cycle", $instanceid), 0); SetValue(IPS_GetObjectIDByName("Next Power On", $instanceid), ""); } ?>'; // create script $alarmclockvariableid = @$this->GetIDForIdent("AlarmClock"); $alarmclockcontrolscriptid = @IPS_GetScriptIDByName("AlarmClockControl", $alarmclockvariableid); if ($alarmclockcontrolscriptid === false) { $alarmclockcontrolscriptid = $this->RegisterScript("AlarmClockControl", "AlarmClockControl", $AlarmClockControlScript, 0); } else { IPS_SetScriptContent($alarmclockcontrolscriptid, $AlarmClockControlScript); } IPS_SetParent($alarmclockcontrolscriptid, $alarmclockvariableid); IPS_SetHidden($alarmclockcontrolscriptid, true); $alarmclockscripteventid = @IPS_GetEventIDByName("AlarmClockEvent", $alarmclockcontrolscriptid); if ($alarmclockscripteventid == false) { $alarmclockscripteventid = IPS_CreateEvent(1); IPS_SetParent($alarmclockscripteventid, $alarmclockcontrolscriptid); IPS_SetName($alarmclockscripteventid, "AlarmClockEvent"); } // SleepTimer Script $SleepTimerControlScript = '<? /* SymconBoseSoundTouch Bose SoundTouch Module for IP-Symcon filename: SleepTimerControl.php description: Sleep Timer Control Script version 1.0.0 date: 28.12.2015 publisher: Copyright (c) 2015, 2016 Ulrich Bittner license: CC BY-NC 4.0 Creative Commons Attribution-NonCommercial 4.0 International License environment: IP-Symcon 4.0 (beta) on RPi changelog: version 1.0.0 28.12.2015 initialscript todo: (none) github: https://github.com/ubittner/SymconBoseSoundTouch.git symcon forum: https://www.symcon.de/forum/threads/29922-Bose-SoundTouch-Modul */ $instanceid = IPS_GetParent(IPS_GetParent($_IPS["SELF"])); $deviceip = IPS_GetProperty($instanceid, "DeviceIP"); $timeout = IPS_GetProperty($instanceid, "Timeout"); $sleepcycle = GetValue(IPS_GetObjectIDByName("Sleep Cycle", $instanceid)); $sleeptimerscriptid = IPS_GetScriptIDByName("SleepTimerControl", IPS_GetParent($_IPS["SELF"])); $sleeptimereventid = @IPS_GetEventIDByName("SleepTimerEvent", $sleeptimerscriptid); include_once("../modules/SymconBoseSoundTouch/Bose/bose_soundtouch_api.php"); try { // check device availibility if ($timeout && Sys_Ping($deviceip, $timeout) != true) { throw new Exception("Device ".$deviceip." is not available"); } $bosedevice = new BoseSoundTouchAPI($deviceip); $result = $bosedevice->getDevicenowPlayingAPI(); // device is on if ($result["devicestate"] == "Play"){ if ($sleepcycle <> 0) { decreaseVolume(); } else { switchDeviceOff(); } } // device is already off else { resetValues(); } } // error message catch (Exception $e) { echo $e->getMessage(); } // decrease volume function decreaseVolume() { global $deviceip, $timeout, $sleeptimereventid, $instanceid, $sleepcycle; try { // check device availibility if ($timeout && Sys_Ping($deviceip, $timeout) != true) { throw new Exception("Device ".$deviceip." is not available"); } $bosedevice = new BoseSoundTouchAPI($deviceip); $result = $bosedevice->getDeviceVolumeAPI(); if ($result["actualvolume"] == 1) { switchDeviceOff(); IPS_SetEventActive($sleeptimereventid, false); } else { $volume = ($result["actualvolume"])-1; $setvolume = $bosedevice->setDeviceVolumeAPI($volume); SetValue(IPS_GetObjectIDByName("Volume", $instanceid), $volume); $eventinfo = IPS_GetEvent($sleeptimereventid); $eventtimestamp = ($eventinfo["NextRun"]); $neweventtimestamp = strtotime("+ " . $sleepcycle . " seconds", $eventtimestamp); $newhour = date("H",$neweventtimestamp); $newminute = date("i",$neweventtimestamp); $newsecond = date("s",$neweventtimestamp); IPS_SetEventCyclicTimeFrom($sleeptimereventid, $newhour, $newminute, $newsecond); } } // error message catch (Exception $e) { echo $e->getMessage(); } } // switch device off function switchDeviceOff() { global $deviceip, $timeout; // power off try { if ($timeout && Sys_Ping($deviceip, $timeout) != true) { throw new Exception("Device ".$deviceip." is not available"); } $bosedevice = new BoseSoundTouchAPI($deviceip); $result = $bosedevice->powerDeviceAPI(); resetValues(); } // error message catch (Exception $e) { echo $e->getMessage(); } } // reset values function resetValues() { global $instanceid, $sleeptimereventid; SetValue(IPS_GetObjectIDByName("Device Power", $instanceid), false); SetValue(IPS_GetObjectIDByName("Device Mode", $instanceid), ""); SetValue(IPS_GetObjectIDByName("Device State", $instanceid), ""); SetValue(IPS_GetObjectIDByName("Now Playing", $instanceid), ""); SetValue(IPS_GetObjectIDByName("Description", $instanceid), ""); SetValue(IPS_GetObjectIDByName("Logo", $instanceid), ""); SetValue(IPS_GetObjectIDByName("Sleep Timer", $instanceid), false); SetValue(IPS_GetObjectIDByName("Volume Fade Out (15 min)", $instanceid), false); SetValue(IPS_GetObjectIDByName("Good Night (30 min)", $instanceid), false); SetValue(IPS_GetObjectIDByName("Sleep Cycle", $instanceid), 0); SetValue(IPS_GetObjectIDByName("Next Power Off", $instanceid), ""); IPS_SetEventActive($sleeptimereventid, false); } ?>'; $sleeptimervariableid = @$this->GetIDForIdent("SleepTimer"); $sleeptimercontrolscriptid = @IPS_GetScriptIDByName("SleepTimerControl", $sleeptimervariableid); if ($sleeptimercontrolscriptid === false) { $sleeptimercontrolscriptid = $this->RegisterScript("SleepTimerControl", "SleepTimerControl", $SleepTimerControlScript, 0); } else { IPS_SetScriptContent($sleeptimercontrolscriptid, $SleepTimerControlScript); } IPS_SetParent($sleeptimercontrolscriptid, $sleeptimervariableid); IPS_SetHidden($sleeptimercontrolscriptid, true); $sleeptimerscripteventid = @IPS_GetEventIDByName("SleepTimerEvent", $sleeptimercontrolscriptid); if ($sleeptimerscripteventid == false) { $sleeptimerscripteventid = IPS_CreateEvent(1); IPS_SetParent($sleeptimerscripteventid, $sleeptimercontrolscriptid); IPS_SetName($sleeptimerscripteventid, "SleepTimerEvent"); } }
/** * OneWireLan_GetRomID * @return string */ public function GetRomID() { if ($_IPS['SENDER'] != "RunScript") { trigger_error("Do not use this function!", E_USER_WARNING); return; } if ($this->ReadPropertyString("ROMId")) { trigger_error("ROMId is not empty!", E_USER_WARNING); return; } $ModuleID_r = IPS_GetInstanceListByModuleID("{21C81179-662C-46E5-BB0E-F3E18EF75637}"); $resultat = $this->SendDataToParent(json_encode(array("DataID" => "{C7DF8BCB-7CF7-4AD9-B636-5A3DEFE4E034}", "Buffer" => "NEW"))); if ($resultat == "") { trigger_error("Interface is closed!", E_USER_WARNING); return; } $Data = json_decode($resultat); switch ($this->ReadPropertyInteger("DataType")) { case 0: foreach ($Data->DS18B20 as $Key => $Value) { $ROMId = $Key; foreach ($ModuleID_r as $ID) { if (IPS_GetProperty($ID, "ROMId") == $Key) { $ROMId = ""; } } if ($ROMId != "") { IPS_SetProperty($this->InstanceID, "ROMId", $ROMId); IPS_ApplyChanges($this->InstanceID); echo "New ROMID: " . $ROMId . " found and saved! PLEASE CLOSE THE WINDOW!"; return; } } echo "No New ROMId for DS18B20 found!"; return; break; case 2: foreach ($Data->DS18S20 as $Key => $Value) { $ROMId = $Key; foreach ($ModuleID_r as $ID) { if (IPS_GetProperty($ID, "ROMId") == $Key) { $ROMId = ""; } } if ($ROMId != "") { IPS_SetProperty($this->InstanceID, "ROMId", $ROMId); IPS_ApplyChanges($this->InstanceID); echo "New ROMID: " . $ROMId . " found and saved! PLEASE CLOSE THE WINDOW!"; return; } } echo "No New ROMId for DS18S20 found!"; return; break; case 1: foreach ($Data->DS2438 as $Key => $Value) { $ROMId = $Key; foreach ($ModuleID_r as $ID) { if (IPS_GetProperty($ID, "ROMId") == $Key) { $ROMId = ""; } } if ($ROMId != "") { IPS_SetProperty($this->InstanceID, "ROMId", $ROMId); IPS_ApplyChanges($this->InstanceID); echo "New ROMID: " . $ROMId . " found and saved! PLEASE CLOSE THE WINDOW!"; return; } } echo "No New ROMId for DS2438 found!"; return; break; } }
public function ApplyChanges() { //Never delete this line! parent::ApplyChanges(); $ArchivID = IPS_GetInstanceListByModuleID("{43192F0B-135B-4CE7-A0A7-1475603F3060}"); $ArchivID = $ArchivID[0]; $this->RegisterProfile(1, "WITHINGS_M_Groesse", "Gauge", "", " cm"); $this->RegisterProfile(1, "WITHINGS_M_Puls", "Graph", "", " bpm"); $this->RegisterProfile(2, "WITHINGS_M_Kilo", "", "", " kg", false, false, false, 1); $this->RegisterProfile(2, "WITHINGS_M_Prozent", "", "", " %", false, false, false, 1); $this->RegisterProfile(2, "WITHINGS_M_BMI", "", "", " kg/m²", false, false, false, 1); $this->RegisterProfile(1, "WITHINGS_M_Blutdruck", "", "", " mmHg"); $this->RegisterProfileGender("WITHINGS_M_Gender", "", "", "", array(array(0, "maennlich", "", 0xff), array(1, "weiblich", "", 0xff0000))); $id = $this->RegisterVariableString("name", "Name", "~String", 0); $id = $this->RegisterVariableInteger("gender", "Geschlecht", "WITHINGS_M_Gender", 2); $id = $this->RegisterVariableString("birthdate", "Geburtstag", "~String", 1); $id = $this->RegisterVariableInteger("height", "Groesse", "WITHINGS_M_Groesse", 3); $parent = IPS_GetParent($id); $CatID = false; if ($this->ReadPropertyBoolean("BloodMeasures") == true) { $CatID = $this->CreateKategorie("Blutdruck", $parent); if ($CatID === false) { throw new Exception("Kategorie Blutdruck nicht definiert"); } $VariablenID = @IPS_GetVariableIDByName("Diastolic", $CatID); if ($VariablenID === false) { $id = $this->RegisterVariableInteger("diastolicblood", "Diastolic", "WITHINGS_M_Blutdruck", 2); IPS_SetParent($id, $CatID); } $VariablenID = @IPS_GetVariableIDByName("Systolic", $CatID); if ($VariablenID === false) { $id = $this->RegisterVariableInteger("systolicblood", "Systolic", "WITHINGS_M_Blutdruck", 1); IPS_SetParent($id, $CatID); } $VariablenID = @IPS_GetVariableIDByName("Puls", $CatID); if ($VariablenID === false) { $id = $this->RegisterVariableInteger("heartpulse", "Puls", "WITHINGS_M_Puls", 3); IPS_SetParent($id, $CatID); } $VariablenID = @IPS_GetVariableIDByName("DatumUhrzeit", $CatID); if ($VariablenID === false) { $id = $this->RegisterVariableInteger("timestamp", "DatumUhrzeit", "~UnixTimestamp", 0); IPS_SetParent($id, $CatID); } } $logging = $this->ReadPropertyBoolean("BloodLogging"); if ($CatID) { if ($logging) { $this->Logging("BloodLogging wird eingeschaltet"); } else { $this->Logging("BloodLogging wird ausgeschaltet"); } $id = IPS_GetVariableIDByName("Diastolic", $CatID); if (AC_GetLoggingStatus($ArchivID, $id) != $logging) { AC_SetLoggingStatus($ArchivID, $id, $logging); IPS_ApplyChanges($ArchivID); } $id = IPS_GetVariableIDByName("Systolic", $CatID); if (AC_GetLoggingStatus($ArchivID, $id) != $logging) { AC_SetLoggingStatus($ArchivID, $id, $logging); IPS_ApplyChanges($ArchivID); } $id = IPS_GetVariableIDByName("Puls", $CatID); if (AC_GetLoggingStatus($ArchivID, $id) != $logging) { AC_SetLoggingStatus($ArchivID, $id, $logging); IPS_ApplyChanges($ArchivID); } $status = $this->ReadPropertyBoolean("BloodVisible"); $this->KategorieEnable($parent, "Blutdruck", $status); } $CatID = false; if ($this->ReadPropertyBoolean("BodyMeasures") == true) { $CatID = $this->CreateKategorie("Waage", $parent); if ($CatID === false) { throw new Exception("Kategorie Waage nicht definiert"); } $VariablenID = @IPS_GetVariableIDByName("DatumUhrzeit", $CatID); if ($VariablenID === false) { $id = $this->RegisterVariableInteger("timestamp", "DatumUhrzeit", "~UnixTimestamp", 0); IPS_SetParent($id, $CatID); } $VariablenID = @IPS_GetVariableIDByName("Gewicht", $CatID); if ($VariablenID === false) { $id = $this->RegisterVariableFloat("weight", "Gewicht", "WITHINGS_M_Kilo", 1); IPS_SetParent($id, $CatID); } $VariablenID = @IPS_GetVariableIDByName("Fettfrei Anteil", $CatID); if ($VariablenID === false) { $id = $this->RegisterVariableFloat("fatfree", "Fettfrei Anteil", "WITHINGS_M_Kilo", 3); IPS_SetParent($id, $CatID); } $VariablenID = @IPS_GetVariableIDByName("Fett Anteil", $CatID); if ($VariablenID === false) { $id = $this->RegisterVariableFloat("fatmassweight", "Fett Anteil", "WITHINGS_M_Kilo", 2); IPS_SetParent($id, $CatID); } $VariablenID = @IPS_GetVariableIDByName("Fett Prozent", $CatID); if ($VariablenID === false) { $id = $this->RegisterVariableFloat("fatradio", "Fett Prozent", "WITHINGS_M_Prozent", 4); IPS_SetParent($id, $CatID); } $VariablenID = @IPS_GetVariableIDByName("BMI", $CatID); if ($VariablenID === false) { $id = $this->RegisterVariableFloat("bmi", "BMI", "WITHINGS_M_BMI", 5); IPS_SetParent($id, $CatID); } else { @IPS_SetVariableCustomProfile($VariablenID, "WITHINGS_M_BMI"); } if ($this->ReadPropertyBoolean("BodyPuls") == true) { $VariablenID = @IPS_GetVariableIDByName("Puls", $CatID); if ($VariablenID === false) { $id = $this->RegisterVariableInteger("heartpulse", "Puls", "WITHINGS_M_Puls", 3); IPS_SetParent($id, $CatID); } } } $logging = $this->ReadPropertyBoolean("BodyLogging"); if ($CatID) { if ($logging) { $this->Logging("BodyLogging wird eingeschaltet"); } else { $this->Logging("BodyLogging wird ausgeschaltet"); } $id = IPS_GetVariableIDByName("Gewicht", $CatID); if (AC_GetLoggingStatus($ArchivID, $id) != $logging) { AC_SetLoggingStatus($ArchivID, $id, $logging); IPS_ApplyChanges($ArchivID); } $id = IPS_GetVariableIDByName("Fettfrei Anteil", $CatID); if (AC_GetLoggingStatus($ArchivID, $id) != $logging) { AC_SetLoggingStatus($ArchivID, $id, $logging); IPS_ApplyChanges($ArchivID); } $id = IPS_GetVariableIDByName("Fett Anteil", $CatID); if (AC_GetLoggingStatus($ArchivID, $id) != $logging) { AC_SetLoggingStatus($ArchivID, $id, $logging); IPS_ApplyChanges($ArchivID); } $id = IPS_GetVariableIDByName("Fett Prozent", $CatID); if (AC_GetLoggingStatus($ArchivID, $id) != $logging) { AC_SetLoggingStatus($ArchivID, $id, $logging); IPS_ApplyChanges($ArchivID); } $id = IPS_GetVariableIDByName("BMI", $CatID); if (AC_GetLoggingStatus($ArchivID, $id) != $logging) { AC_SetLoggingStatus($ArchivID, $id, $logging); IPS_ApplyChanges($ArchivID); } $id = @IPS_GetVariableIDByName("Puls", $CatID); if ($id > 0) { if (AC_GetLoggingStatus($ArchivID, $id) != $logging) { AC_SetLoggingStatus($ArchivID, $id, $logging); IPS_ApplyChanges($ArchivID); } } } $status = $this->ReadPropertyBoolean("BodyVisible"); $this->KategorieEnable($parent, "Waage", $status); //Timer erstellen $this->SetTimerInterval("WIT_UpdateTimer", $this->ReadPropertyInteger("Intervall")); //Update $this->Update(); }
/** * Create a new EnergyDev instance and set its properties * @param array $data parsed record * @param String $caps String semicolon seperated capabilities of this device * @return int new Instance ID */ private function CreateENDevice($data, $caps) { $instID = 0; $Device = $data['Id']; $typ = $data['Typ']; $ModuleID = $this->module_interfaces['EnergyDev']; if (IPS_ModuleExists($ModuleID)) { //return $result; $this->debug(__FUNCTION__, "Create Device {$Device},Type {$typ}"); $instID = IPS_CreateInstance($ModuleID); if ($instID > 0) { IPS_ConnectInstance($instID, $this->InstanceID); //Parents are ourself! IPS_SetProperty($instID, 'DeviceID', $Device); IPS_SetProperty($instID, 'Class', __CLASS__); IPS_SetProperty($instID, 'Typ', $typ); IPS_SetProperty($instID, 'CapList', $caps); IPS_SetProperty($instID, 'Debug', $this->isDebug()); //follow debug settings from splitter IPS_SetName($instID, "{$typ} ID {$Device}"); $ident = __CLASS__ . "_EN_{$Device}"; $ident = preg_replace("/\\W/", "_", $ident); //nicht-Buchstaben/zahlen entfernen IPS_SetIdent($instID, $ident); IPS_ApplyChanges($instID); $cat = $this->GetCategory(); $pcat = $this->GetParentCategory(); $ident = preg_replace("/\\W/", "_", $cat); //nicht-Buchstaben/zahlen entfernen $catid = @IPS_GetObjectIDByIdent($ident, $pcat); if ($catid == 0) { $catid = IPS_CreateCategory(); IPS_SetName($catid, $cat); if (IPS_SetIdent($catid, $ident) && IPS_SetParent($catid, $pcat)) { IPS_LogMessage(__CLASS__, "Category {$cat} Ident {$ident} ({$catid}) created"); } else { IPS_LogMessage(__CLASS__, "Category {$cat} Ident {$ident} ({$catid}) FAILED"); } } $this->debug(__FUNCTION__, "Category:{$catid}"); if (!IPS_SetParent($instID, $catid)) { $this->debug(__FUNCTION__, "SetParent to Cat {$catid} failed"); } $this->debug(__FUNCTION__, 'New ID:' . $instID); //if instID } else { $this->debug(__FUNCTION__, 'Instance is not created!'); } } //module exists return $instID; }
protected function AddIRCode($ircode, $irid) { $code = "IRCode" . $irid; $label = "IRLabel" . $irid; //$instance = IPS_GetInstance($this->InstanceID)["InstanceID"]; IPS_SetProperty($this->InstanceID, $code, $ircode); //IRCode setzten. $IRLabel = $this->ReadPropertyString($label); if (empty($IRLabel)) { IPS_SetProperty($this->InstanceID, $label, "Neuer Code"); //IRLabel provisorisch setzten. } $NumberIRCodes = $this->ReadPropertyString("NumberIRCodes"); $NumberIRCodes = $NumberIRCodes + 1; $this->CreateProfileIR($NumberIRCodes); IPS_SetProperty($this->InstanceID, "NumberIRCodes", $NumberIRCodes); //IRCode setzten. IPS_SetProperty($this->InstanceID, "LearnIRCode", false); //Haken entfernen. IPS_ApplyChanges($this->InstanceID); //Neue Konfiguration übernehmen IPS_LogMessage("IRCode" . $irid . " hinzugefügt:", $ircode); // Status aktiv $this->SetStatus(102); }
/** * Create a new EnergyDev instance and set its properties * @param array $data parsed record * @param String $caps String semicolon seperated capabilities of this device * @return int new Instance ID */ private function CreateEnergyDevice($data, $caps) { $instID = 0; $Device = $data['Id']; $typ = $data['Typ']; $name = $data['Name']; $branch = $data['Branch']; unset($data['Branch']); if (!$name) { $name = "XS1 {$branch} {$Device}"; } $class = __CLASS__ . "-EN"; //$host = $this->GetHost(); $ModuleID = $this->module_interfaces['EnergyDev']; if (IPS_ModuleExists($ModuleID)) { //return $result; $this->debug(__FUNCTION__, 'Device:' . $Device); $instID = IPS_CreateInstance($ModuleID); if ($instID > 0) { IPS_SetProperty($instID, 'DeviceID', $Device); IPS_SetProperty($instID, 'Class', $class); IPS_SetProperty($instID, 'Typ', $typ); IPS_SetProperty($instID, 'CapList', $caps); IPS_SetProperty($instID, 'Debug', $this->isDebug()); //follow debug settings from splitter IPS_SetName($instID, "XS1 {$branch} '{$name}'"); $ident = $class . "_" . $branch . "_{$Device}"; $ident = preg_replace("/\\W/", "_", $ident); //nicht-Buchstaben/zahlen entfernen IPS_SetIdent($instID, $ident); IPS_ConnectInstance($instID, $this->InstanceID); IPS_ApplyChanges($instID); //set category $cat = $this->GetCategory() . " {$branch}" . "s"; $pcat = $this->GetParentCategory(); $ident = preg_replace("/\\W/", "_", $cat); //fix naming $catid = @IPS_GetObjectIDByIdent($ident, $pcat); if ($catid == 0) { $catid = IPS_CreateCategory(); IPS_SetName($catid, $cat); if (IPS_SetIdent($catid, $ident) && IPS_SetParent($catid, $pcat)) { IPS_LogMessage($class, "Category {$cat} Ident {$ident} ({$catid}) created"); } else { IPS_LogMessage($class, "Category {$cat} Ident {$ident} ({$catid}) FAILED"); } } $this->debug(__FUNCTION__, "Category:{$catid}"); if (!IPS_SetParent($instID, $catid)) { $this->debug(__FUNCTION__, "SetParent Instance {$instID} to Cat {$catid} failed, Dropping instance"); IPS_DeleteInstance($instID); $instID = 0; } else { $this->debug(__FUNCTION__, 'New ID:' . $instID); } //if instID } else { $this->debug(__FUNCTION__, 'Instance is not created!'); } } //module exists return $instID; }
public function ApplyData($data) { $data = (array)$data; $state = (array)$data['state']; /* * Properties */ $dirty = false; $modelid = utf8_decode((string)$data['modelid']); $type = utf8_decode((string)$data['type']); $name = utf8_decode((string)$data['name']); if (IPS_GetProperty($this->InstanceID, 'ModelId') != $modelid) { IPS_SetProperty($this->InstanceID, 'ModelId', $modelid); $dirty = true; } if (IPS_GetProperty($this->InstanceID, 'Type') != $type) { IPS_SetProperty($this->InstanceID, 'Type', $type); $dirty = true; } if (IPS_GetName($this->InstanceID) != $name) { IPS_SetName($this->InstanceID, $name); $dirty = true; } // Setze den Modus if (isset($state['ct']) && isset($state['hue'])) { // HUE+CT Lamp $lightFeature = 0; } elseif(isset($state['hue'])) { // HUE Lamp $lightFeature = 1; } elseif(isset($state['ct'])) { // CT Lamp $lightFeature = 2; } else { // Lux Lamp $lightFeature = 3; } if (IPS_GetProperty($this->InstanceID, 'LightFeatures') != $lightFeature) { IPS_SetProperty($this->InstanceID, 'LightFeatures', $lightFeature); $dirty = true; } if ($dirty) IPS_ApplyChanges($this->InstanceID); /* * Variables */ $stateId = $this->RegisterVariableBoolean("STATE", "Zustand", "~Switch"); $this->EnableAction("STATE"); IPS_SetPosition($stateId, 1); $cmId = $this->RegisterVariableInteger("COLOR_MODE", "Modus", "ColorModeSelect.Hue"); $this->EnableAction("COLOR_MODE"); IPS_SetPosition($cmId, 2); IPS_SetIcon($cmId, 'ArrowRight'); $briId = $this->RegisterVariableInteger("BRIGHTNESS", "Helligkeit", "~Intensity.100"); $this->EnableAction("BRIGHTNESS"); IPS_SetIcon($briId, 'Sun'); IPS_SetPosition($briId, 5); if ($lightFeature == 0 || $lightFeature == 1) { $hueId = $this->RegisterVariableInteger("HUE", "Hue"); IPS_SetHidden($hueId, true); } else { $delete = @IPS_GetObjectIDByIdent("HUE", $this->InstanceID); if ($delete !== false) IPS_DeleteVariable($delete); } if ($lightFeature == 0) { IPS_SetVariableCustomProfile($cmId, 'ColorModeSelect.Hue'); IPS_SetHidden($cmId, false); } else { IPS_SetHidden($cmId, true); } if ($lightFeature == 0 || $lightFeature == 2) { $ctId = $this->RegisterVariableInteger("COLOR_TEMPERATURE", "Farbtemperatur", "~Intensity.100"); $this->EnableAction("COLOR_TEMPERATURE"); IPS_SetIcon($ctId, 'Bulb'); IPS_SetPosition($ctId, 4); } else { $delete = @IPS_GetObjectIDByIdent("COLOR_TEMPERATURE", $this->InstanceID); if ($delete !== false) IPS_DeleteVariable($delete); } if ($lightFeature == 0 || $lightFeature == 1) { $colorId = $this->RegisterVariableInteger("COLOR", "Farbe", "~HexColor"); $this->EnableAction("COLOR"); IPS_SetPosition($colorId, 3); IPS_SetIcon($colorId, 'Bulb'); $satId = $this->RegisterVariableInteger("SATURATION", utf8_decode("Sättigung"), "~Intensity.100"); $this->EnableAction("SATURATION"); IPS_SetIcon($satId, 'Intensity'); IPS_SetPosition($satId, 6); } else { $delete = @IPS_GetObjectIDByIdent("COLOR", $this->InstanceID); if ($delete !== false) IPS_DeleteVariable($delete); $delete = @IPS_GetObjectIDByIdent("SATURATION", $this->InstanceID); if ($delete !== false) IPS_DeleteVariable($delete); } /* * Values */ SetValueBoolean($stateId, $state['on']); SetValueInteger($briId, round($state['bri'] * 100 / 254)); if (@$satId) SetValueInteger($satId, round($state['sat'] * 100 / 254)); if (@$hueId) SetValueInteger($hueId, $state['hue']); if (@$ctId) SetValueInteger($ctId, 100 - round(( $state['ct'] - 153) * 100 / 347)); switch (@$state['colormode']) { case 'xy': case 'hs': $hex = $this->HSV2HEX($state['hue'], $state['sat'], $state['bri']); SetValueInteger($colorId, hexdec($hex)); IPS_SetHidden($colorId, false); IPS_SetHidden($satId, false); if (@$ctId) IPS_SetHidden($ctId, true); if (@$cmId) SetValueInteger($cmId, 0); break; case 'ct': if(@$colorId) IPS_SetHidden($colorId, true); if(@$satId) IPS_SetHidden($satId, true); IPS_SetHidden($ctId, false); SetValueInteger($cmId, 1); break; } }
/** * Create a new EneryDev instance and set its properties * @param array $data parsed record * @param String $caps String semicolon seperated capabilities of this device * @return int new Instance ID */ private function CreateENDevice($data, $caps) { $instID = 0; $class = $data['Class']; $Device = $data['Id']; $typ = $data['Typ']; $ModuleID = $this->module_interfaces['EnergyDev']; if (IPS_ModuleExists($ModuleID)) { //return $result; $this->debug(__FUNCTION__, 'Device:' . $Device); $instID = IPS_CreateInstance($ModuleID); if ($instID > 0) { IPS_SetProperty($instID, 'DeviceID', $Device); IPS_SetProperty($instID, 'Class', $class); IPS_SetProperty($instID, 'Typ', $typ); IPS_SetProperty($instID, 'CapList', $caps); IPS_SetProperty($instID, 'Debug', $this->isDebug()); //follow debug settings from splitter IPS_SetName($instID, "{$typ} Device " . $Device); $ident = $class . "_" . $typ . "_" . $Device; $ident = preg_replace("/\\W/", "_", $ident); //nicht-Buchstaben/zahlen entfernen IPS_SetIdent($instID, $ident); IPS_ConnectInstance($instID, $this->InstanceID); IPS_ApplyChanges($instID); //set factor if (isset($data['CounterFactor'])) { IPS_SetProperty($instID, 'CounterFactor', floatval($data['CounterFactor'])); $this->debug(__FUNCTION__, 'Set Counterfactor=' . $data['CounterFactor']); } //set category $cat = $this->GetCategory(); $pcat = $this->GetParentCategory(); $ident = preg_replace("/\\W/", "_", $cat); //fix naming $catid = @IPS_GetObjectIDByIdent($ident, $pcat); if ($catid == 0) { $catid = IPS_CreateCategory(); IPS_SetName($catid, $cat); if (IPS_SetIdent($catid, $ident) && IPS_SetParent($catid, $pcat)) { IPS_LogMessage($class, "Category {$cat} Ident {$ident} ({$catid}) created"); } else { IPS_LogMessage($class, "Category {$cat} Ident {$ident} ({$catid}) FAILED"); } } $this->debug(__FUNCTION__, "Category:{$catid}"); if (!IPS_SetParent($instID, $catid)) { $this->debug(__FUNCTION__, "SetParent Instance {$instID} to Cat {$catid} failed, Dropping instance"); IPS_DeleteInstance($instID); $instID = 0; } else { $this->debug(__FUNCTION__, 'New ID:' . $instID); } //parent if (IPS_HasChanges($instID)) { IPS_ApplyChanges($instID); } } else { $this->debug(__FUNCTION__, 'Instance is not created!'); } //if instID } //module exists return $instID; }
/** * This function will be available automatically after the module is imported with the module control. * Using the custom prefix this function will be callable from PHP and JSON-RPC through: * * LJ_GenerateShutter($id, $Start, $End); * */ public function GenerateShutter($Start, $End) { $qid = @IPS_GetObjectIDByIdent("KNXQuick", 0); if($qid === false) { $qid = IPS_CreateCategory(); IPS_SetName($qid, "KNX quick"); IPS_SetIdent($qid, "KNXQuick"); } $sid = @IPS_GetObjectIDByIdent("Shutter", $qid); if($sid === false) { $sid = IPS_CreateCategory(); IPS_SetName($sid, "Shutter"); IPS_SetIdent($sid, "Shutter"); IPS_SetParent($sid, $qid); IPS_SetPosition($sid, 2); } for($i=$Start; $i<=$End; $i++) { for($j=0; $j<=9; $j++) { $iid = @IPS_GetObjectIDByIdent("Shutter".strtoupper(dechex($i).$j), $sid); if($iid === false) { $iid = IPS_CreateInstance("{24A9D68D-7B98-4D74-9BAE-3645D435A9EF}"); IPS_SetName($iid, "Shutter (Group ".strtoupper(dechex($i)).", Channel ".$j.")"); IPS_SetIdent($iid, "Shutter".strtoupper(dechex($i)).$j); IPS_SetParent($iid, $sid); IPS_SetProperty($iid, "GroupMoveAddress1", 14); IPS_SetProperty($iid, "GroupMoveAddress2", 0); IPS_SetProperty($iid, "GroupMoveAddress3", ($i*16)+$j); IPS_SetProperty($iid, "GroupStopAddress1", 14); IPS_SetProperty($iid, "GroupStopAddress2", 1); IPS_SetProperty($iid, "GroupStopAddress3", ($i*16)+$j); if($j > 0) { $mapping = Array(); $mapping[] = Array( "GroupAddress1" => 14, "GroupAddress2" => 0, "GroupAddress3" => $i*16 ); $mapping[] = Array( "GroupAddress1" => 14, "GroupAddress2" => 0, "GroupAddress3" => 240 ); $mapping[] = Array( "GroupAddress1" => 14, "GroupAddress2" => 0, "GroupAddress3" => 240+$j ); IPS_SetProperty($iid, "GroupMoveMapping", json_encode($mapping)); $mapping = Array(); $mapping[] = Array( "GroupAddress1" => 14, "GroupAddress2" => 1, "GroupAddress3" => $i*16 ); $mapping[] = Array( "GroupAddress1" => 14, "GroupAddress2" => 1, "GroupAddress3" => 240 ); $mapping[] = Array( "GroupAddress1" => 14, "GroupAddress2" => 1, "GroupAddress3" => 240+$j ); IPS_SetProperty($iid, "GroupStopMapping", json_encode($mapping)); } IPS_ApplyChanges($iid); } } } echo "Done."; }
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); }
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); }
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); } }
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"); }
/** * checks if the variable logging state fits the settings * if not this method will update the variable logging * * @throws Exception if $archiveId is not set while logging is enabled * @access private */ private function verifyVariableLogging() { if ($this->enableLogging) { if ($this->archiveId == NULL) { throw new Exception("Parameter \$archiveId is not set but \$enableLogging is true"); } if ($this->checkArchive($this->archiveId)) { if (!AC_GetLoggingStatus($this->archiveId, $this->id)) { AC_SetLoggingStatus($this->archiveId, $this->id, true); AC_SetAggregationType($this->archiveId, $this->id, $this->aggregationType); IPS_ApplyChanges($this->archiveId); } } } else { //todo: disable logging not implemented } }
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 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(); }
/** * Startet den Timer bis zum Alarm * * @access private */ private function StartTimer() { if (IPS_GetKernelRunlevel() != KR_READY) { return; } $NowTime = time(); if (!IPS_VariableExists($this->ReadPropertyInteger('VarID'))) { IPS_SetProperty($this->InstanceID, 'VarID', 0); IPS_ApplyChanges($this->InstanceID); return; } $Variable = IPS_GetVariable($this->ReadPropertyInteger('VarID')); $LastTime = $Variable['VariableUpdated']; $TargetTime = $LastTime + $this->ReadPropertyInteger('Timer'); $DiffTime = $TargetTime - $NowTime; if ($TargetTime < $NowTime) { $this->SetStateVar(true); $this->DoScript($this->ReadPropertyInteger('VarID'), true, $this->State); $this->State = true; if ($this->ReadPropertyBoolean('MultipleAlert') == false) { $this->StopTimer(); } else { $this->SetTimerInterval('NoTrigger', $this->ReadPropertyInteger('Timer') * 1000); } // neuer Timer mit max. Zeit, ohne now zu berücksichtigen. } else { $this->SetStateVar(false); if ($this->State) { $this->DoScript($this->ReadPropertyInteger('VarID'), false, $this->State); $this->State = false; } $this->SetTimerInterval('NoTrigger', $DiffTime * 1000); } }
public function SomfyCreateInstance(string $InstName, string $AIOSomfyAdresse, string $SomfyType, string $CategoryID) { //Prüfen ob Instanz schon existiert $InstanzID = @IPS_GetInstanceIDByName($InstName, $CategoryID); if ($InstanzID === false) { //echo "Instanz nicht gefunden!"; //Neue Instanz anlegen $InsID = IPS_CreateInstance("{0F83D875-4737-4244-8234-4CF08E6F2626}"); IPS_SetName($InsID, $InstName); // Instanz benennen IPS_SetParent($InsID, $CategoryID); // Instanz einsortieren unter dem Objekt mit der ID "$CategoryID" IPS_SetProperty($InsID, "Adresse", $AIOSomfyAdresse); //Adresse setzten. IPS_ApplyChanges($InsID); //Neue Konfiguration übernehmen IPS_LogMessage("Instanz erstellt:", "Name: " . $InstName); return $InsID; } else { //echo "Die Instanz-ID lautet: ". $InstanzID; return $InstanzID; } }
/** * Create a new WSDev instance and set its properties * @param array $data parsed record * @param String $caps String semicolon seperated capabilities of this device * @return int new Instance ID */ private function CreateWSDevice($data, $caps) { $instID = 0; $Device = $data['Id']; $typ = $data['Typ']; $ModuleID = $this->module_interfaces['WSDEV']; if (IPS_ModuleExists($ModuleID)) { //return $result; $this->debug(__FUNCTION__, "Create Device {$Device},Type {$typ}"); $instID = IPS_CreateInstance($ModuleID); if ($instID > 0) { IPS_ConnectInstance($instID, $this->InstanceID); //Parents are ourself! IPS_SetProperty($instID, 'DeviceID', $Device); IPS_SetProperty($instID, 'Class', __CLASS__); IPS_SetProperty($instID, 'Typ', $typ); IPS_SetProperty($instID, 'CapList', $caps); IPS_SetProperty($instID, 'Debug', $this->isDebug()); //follow debug settings from splitter switch ($Device) { case 0: case $Device < 8: IPS_SetName($instID, 'Sensor ' . $Device); break; case 8: IPS_SetName($instID, 'KombiSensor'); break; case 9: IPS_SetName($instID, 'InnenSensor'); break; default: IPS_SetName($instID, "unknown Sensor('" . strToHex($Device) . "')"); break; } //switch $ident = __CLASS__ . "_WS_{$Device}"; $ident = preg_replace("/\\W/", "_", $ident); //nicht-Buchstaben/zahlen entfernen IPS_SetIdent($instID, $ident); IPS_ApplyChanges($instID); $cat = $this->GetCategory(); $pcat = $this->GetParentCategory(); $ident = preg_replace("/\\W/", "_", $cat); //nicht-Buchstaben/zahlen entfernen $catid = @IPS_GetObjectIDByIdent($ident, $pcat); if ($catid == 0) { $catid = IPS_CreateCategory(); IPS_SetName($catid, $cat); if (IPS_SetIdent($catid, $ident) && IPS_SetParent($catid, $pcat)) { IPS_LogMessage(__CLASS__, "Category {$cat} Ident {$ident} ({$catid}) created"); } else { IPS_LogMessage(__CLASS__, "Category {$cat} Ident {$ident} ({$catid}) FAILED"); } } $this->debug(__FUNCTION__, "Category:{$catid}"); if (!IPS_SetParent($instID, $catid)) { $this->debug(__FUNCTION__, "SetParent to Cat {$catid} failed"); } $this->debug(__FUNCTION__, 'New ID:' . $instID); //if instID //set willi profile for forecast $vid = @IPS_GetObjectIDByIdent('Forecast', $instID); if ($vid > 0) { IPS_SetVariableCustomProfile($vid, "WS300_Willi"); } } else { $this->debug(__FUNCTION__, 'Instance is not created!'); } } //module exists return $instID; }
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; }
$rincon = IPS_GetProperty($SonosID, "RINCON"); if (!$rincon) { // Get RINCON // Not sure why, but when executed in ApplyChanges of module.php RINCON is not alway set $ipAddress = IPS_GetProperty($SonosID, "IPAddress"); if ($ipAddress) { $curl = curl_init(); curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => "http://" . $ipAddress . ":1400/xml/device_description.xml")); $result = curl_exec($curl); if (!curl_exec($curl)) { continue; } $xmlr = new SimpleXMLElement($result); $rincon = str_replace("uuid:", "", $xmlr->device->UDN); IPS_SetProperty($SonosID, "RINCON", $rincon); IPS_ApplyChanges($SonosID); } } $rinconMapping[] = array("ID" => $SonosID, "RINCON" => $rincon); if ($SonosID === IPS_GetParent($_IPS["SELF"])) { $ownRincon = $rincon; } } $ipAddress = IPS_GetProperty(IPS_GetParent($_IPS["SELF"]), "IPAddress"); $timeout = IPS_GetProperty(IPS_GetParent($_IPS["SELF"]), "TimeOut"); if (!$timeout || Sys_Ping($ipAddress, $timeout) == true) { $sonos = new SonosAccess($ipAddress); $sonosGroupCoordinator = explode(":", $sonos->GetZoneGroupAttributes()["CurrentZoneGroupID"])[0]; foreach ($rinconMapping as $key => $value) { if ($value["RINCON"] === $sonosGroupCoordinator) { $sonosGroupCoordinatorID = $value["ID"];