Advertisement
Guest User

IPSShadowing_Device

a guest
Dec 5th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 34.98 KB | None | 0 0
  1. <?
  2. /*
  3. * This file is part of the IPSLibrary.
  4. *
  5. * The IPSLibrary is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published
  7. * by the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * The IPSLibrary is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with the IPSLibrary. If not, see http://www.gnu.org/licenses/gpl.txt.
  17. */
  18.  
  19. /**@addtogroup ipsshadowing
  20. * @{
  21. *
  22. * @file IPSShadowing_Device.class.php
  23. * @author Andreas Brauneis
  24. * @version
  25. * Version 2.50.1, 21.03.2012<br/>
  26. * Version 2.50.2, 29.12.2012 Added Reset of Flags after Change of Day/Night<br/>
  27. *
  28. * Funktionen zum Bewegen der Beschattung
  29. */
  30.  
  31. IPSUtils_Include ("IPSLogger.inc.php", "IPSLibrary::app::core::IPSLogger");
  32. IPSUtils_Include ("IPSInstaller.inc.php", "IPSLibrary::install::IPSInstaller");
  33. IPSUtils_Include ("IPSComponent.class.php", "IPSLibrary::app::core::IPSComponent");
  34. IPSUtils_Include ("IPSShadowing_Constants.inc.php", "IPSLibrary::app::modules::IPSShadowing");
  35. IPSUtils_Include ("IPSShadowing_Configuration.inc.php", "IPSLibrary::config::modules::IPSShadowing");
  36. IPSUtils_Include ("IPSShadowing_Custom.inc.php", "IPSLibrary::config::modules::IPSShadowing");
  37. IPSUtils_Include ("IPSShadowing_Logging.inc.php", "IPSLibrary::app::modules::IPSShadowing");
  38.  
  39. /**
  40. * @class IPSShadowing_Device
  41. *
  42. * Definiert ein IPSShadowing_Device Objekt
  43. *
  44. * @author Andreas Brauneis
  45. * @version
  46. * Version 2.50.1, 01.04.2012<br/>
  47. */
  48. class IPSShadowing_Device {
  49.  
  50. /**
  51. * @private
  52. * ID des Shadowing Device
  53. */
  54. private $deviceId;
  55.  
  56. /**
  57. * @public
  58. *
  59. * Initialisierung des IPSShadowing_Device Objektes
  60. *
  61. * @param integer $deviceId Instance ID
  62. */
  63. public function __construct($deviceId) {
  64. $this->deviceId = IPSUtil_ObjectIDByPath($deviceId);
  65. }
  66.  
  67. // ----------------------------------------------------------------------------------------------------------------------------
  68. private function GetPropertyValue($propertyName) {
  69. $deviceConfig = get_ShadowingConfiguration();
  70. $deviceName = IPS_GetName($this->deviceId);
  71.  
  72. $propertyValue = $deviceConfig[$deviceName][$propertyName];
  73. return $propertyValue;
  74. }
  75.  
  76. // ----------------------------------------------------------------------------------------------------------------------------
  77. private function GetVariableValue($variableIdent) {
  78. $variableId = IPS_GetObjectIDByIdent($variableIdent, $this->deviceId);
  79. if ($variableId === false) {
  80. throw new Exception('Variable '.$variableIdent.' could NOT be found for DeviceId='.$this->deviceId);
  81. }
  82. return GetValue($variableId);
  83. }
  84.  
  85. // ----------------------------------------------------------------------------------------------------------------------------
  86. private function SetVariableValue($variableIdent, $value) {
  87. $variableId = IPS_GetObjectIDByIdent($variableIdent, $this->deviceId);
  88. if ($variableId === false) {
  89. throw new Exception('Variable '.$variableIdent.' could NOT be found for DeviceId='.$this->deviceId);
  90. }
  91. if ($variableIdent==c_Control_Movement) {
  92. SetValueInteger($variableId, (int)$value);
  93. } else {
  94. SetValue($variableId, $value);
  95. }
  96. }
  97.  
  98. // ----------------------------------------------------------------------------------------------------------------------------
  99. private function SetStatus() {
  100. if ($this->GetVariableValue(c_Control_StepsToDo)<>"") {
  101. return;
  102. }
  103.  
  104. $Position = $this->GetVariableValue(c_Control_Position);
  105. $MovementId = $this->GetVariableValue(c_Control_Movement);
  106. if (!$this->GetVariableValue(c_Control_Automatic)) {
  107. if ($MovementId<=c_MovementId_Space and $MovementId>=c_MovementId_Closed) {
  108. $Status = 'Manuell';
  109. } elseif ($Position<=10) {
  110. $Status = 'Manuell';
  111. } else {
  112. $Status = "Manuell / $Position%";
  113. }
  114. } elseif ($this->GetVariableValue(c_Control_ManualChange)) {
  115. if ($MovementId<=c_MovementId_Space and $MovementId>=c_MovementId_Closed) {
  116. $Status = 'Autom./Manuell';
  117. } elseif ($Position<=10) {
  118. $Status = 'Autom./Manuell';
  119. } else {
  120. $Status = "Autom./Manuell $Position%";
  121. }
  122. } else {
  123. $Status = 'Automatik';
  124. }
  125. $this->SetVariableValue(c_Control_Display, $Status);
  126. }
  127.  
  128. // ----------------------------------------------------------------------------------------------------------------------------
  129. public function MoveByCommand($command) {
  130. $componentParams = $this->GetPropertyValue(c_Property_Component);
  131.  
  132. // Execute Shutter Command
  133. if (IPSShadowing_BeforeActivateShutter($this->deviceId, $command)) {
  134. $component = IPSComponent::CreateObjectByParams($componentParams);
  135. switch ($command) {
  136. case c_MovementId_Up:
  137. case c_MovementId_MovingIn:
  138. $component->MoveUp();
  139. break;
  140. case c_MovementId_Down:
  141. case c_MovementId_MovingOut:
  142. $component->MoveDown();
  143. break;
  144. case c_MovementId_Stop:
  145. $component->Stop();
  146. break;
  147. case c_MovementId_StepUp:
  148. $component->MoveStepUp();
  149. break;
  150. case c_MovementId_StepDown:
  151. $component->MoveStepDown();
  152. break;
  153. default:
  154. }
  155. IPSShadowing_AfterActivateShutter($this->deviceId, $command);
  156.  
  157. // Abort Processing in case of false result
  158. } else {
  159. SetValue(IPS_GetObjectIDByIdent(c_Control_StartTime, $this->deviceId),-1);
  160. SetValue(IPS_GetObjectIDByIdent(c_Control_StepsToDo, $this->deviceId),"");
  161. SetValue(IPS_GetObjectIDByIdent(c_Control_Step, $this->deviceId),-1);
  162. $command = c_MovementId_Stop;
  163. }
  164.  
  165. if ($this->GetVariableValue(c_Control_Movement) <> $command) {
  166. $this->SetVariableValue(c_Control_Movement, $command);
  167. }
  168. }
  169.  
  170. // ----------------------------------------------------------------------------------------------------------------------------
  171. private function MoveByStatus() {
  172. $this->CalcNextSteps();
  173. $this->SetVariableValue(c_Control_Movement, -1);
  174. $this->ExecuteNextStep();
  175. $this->StartRefreshTimer(true);
  176. }
  177.  
  178. // ----------------------------------------------------------------------------------------------------------------------------
  179. public function SyncStatus($status) {
  180. if ($this->GetVariableValue(c_Control_StepsToDo)=="") {
  181. IPSLogger_Inf(__file__, "Sync State=".$status." from Shutter '".IPS_GetName($this->deviceId));
  182. $this->SetVariableValue(c_Control_Movement, $status);
  183. $this->SetVariableValue(c_Control_ManualChange, true);
  184. }
  185. $this->SetStatus();
  186. }
  187.  
  188. // ----------------------------------------------------------------------------------------------------------------------------
  189. public function MoveByEvent($Level) {
  190. IPSLogger_Dbg(__file__, "Received StateChange from Shutter '".IPS_GetName($this->deviceId)."', NewLevel=".round($Level).", CurrentLevel=".$this->GetVariableValue(c_Control_Position));
  191. if ($this->GetVariableValue(c_Control_Position) <> $Level and
  192. $this->GetVariableValue(c_Control_StepsToDo)=="") {
  193. IPSLogger_Inf(__file__, "Apply StateChange from Shutter '".IPS_GetName($this->deviceId)."', Level=".round($Level));
  194. $shadowingType = $this->GetPropertyValue(c_Property_ShadowingType);
  195.  
  196. // Set Movement Value
  197. $this->SetVariableValue(c_Control_Movement, $this->GetMovementByPositionSync($Level));
  198.  
  199. // Set manual Change Flag
  200. $this->SetVariableValue(c_Control_Position, $Level);
  201. if (!$this->GetVariableValue(c_Control_ManualChange) and
  202. $this->GetVariableValue(c_Control_Automatic)) {
  203. $this->SetVariableValue(c_Control_ManualChange, true);
  204. }
  205. // Set Status
  206. $this->SetStatus();
  207. }
  208. }
  209.  
  210. // ----------------------------------------------------------------------------------------------------------------------------
  211. public function MoveByProgram($ProgramId, $logMessage, $DimoutOption=null, $TriggeredByTemp=false) {
  212. $MovementStatus = $this->GetVariableValue(c_Control_Movement);
  213.  
  214. $DoBeMoved = $MovementStatus;
  215. switch ($ProgramId) {
  216. case c_ProgramId_Manual:
  217. break;
  218. case c_ProgramId_Opened:
  219. case c_ProgramId_OpenedDay:
  220. case c_ProgramId_OpenedNight:
  221. $DoBeMoved = c_MovementId_Opened;
  222. break;
  223. case c_ProgramId_MovedIn:
  224. $DoBeMoved = c_MovementId_MovedIn;
  225. break;
  226. case c_ProgramId_OpenedOrShadowing:
  227. if ($MovementStatus<>c_MovementId_Opened and $MovementStatus<>c_MovementId_Shadowing) {$DoBeMoved = c_MovementId_Shadowing;}
  228. break;
  229. case c_ProgramId_MovedOut:
  230. case c_ProgramId_MovedOutTemp:
  231. $DoBeMoved = c_MovementId_MovedOut;
  232. break;
  233. case c_ProgramId_Closed:
  234. $DoBeMoved = c_MovementId_Closed;
  235. break;
  236. case c_ProgramId_90:
  237. $DoBeMoved = c_MovementId_90;
  238. break;
  239. case c_ProgramId_75:
  240. $DoBeMoved = c_MovementId_75;
  241. break;
  242. case c_ProgramId_50:
  243. $DoBeMoved = c_MovementId_50;
  244. break;
  245. case c_ProgramId_25:
  246. $DoBeMoved = c_MovementId_25;
  247. break;
  248. case c_ProgramId_Dimout:
  249. $DoBeMoved = c_MovementId_Dimout;
  250. break;
  251. case c_ProgramId_DimoutOrShadowing:
  252. if ($MovementStatus<>c_MovementId_Dimout and $MovementStatus<>c_MovementId_Shadowing) {$DoBeMoved = c_MovementId_Shadowing;}
  253. break;
  254. case c_ProgramId_DimoutAndShadowing:
  255. if ($DimoutOption) {
  256. $DoBeMoved = c_MovementId_Dimout;
  257. } else {
  258. $DoBeMoved = c_MovementId_Shadowing;
  259. }
  260. break;
  261. case c_ProgramId_LastPosition:
  262. $DoBeMoved = $this->GetVariableValue(c_Control_TempLastPos);
  263. break;
  264. default:
  265. IPSLogger_Err(__file__, "Unknown ProgramId $ProgramId, DeviceId=".$this->DeviceId);
  266. exit;
  267. }
  268.  
  269. if ($DoBeMoved<>$MovementStatus) {
  270. // Check Program Delay
  271. $lastProgramTime = $this->GetVariableValue(c_Control_ProgramTime);
  272. $lastProgramMinutes = (time() - $lastProgramTime)/60;
  273. if (defined('IPSSHADOWING_PROGRAM_DELAY') and $lastProgramMinutes < IPSSHADOWING_PROGRAM_DELAY ) {
  274. return round(IPSSHADOWING_PROGRAM_DELAY-$lastProgramMinutes);
  275. }
  276. if ($TriggeredByTemp and !$this->GetVariableValue(c_Control_TempChange)) {
  277. $this->SetVariableValue(c_Control_TempChange, true);
  278. $this->SetVariableValue(c_Control_TempLastPos, $this->GetMovementLastPosition());
  279. }
  280. $this->SetVariableValue(c_Control_ProgramTime, time());
  281. $this->SetVariableValue(c_Control_Movement, $DoBeMoved);
  282. $this->MoveByStatus();
  283. IPSShadowing_LogMoveByProgram($this->deviceId, $ProgramId, $logMessage, $TriggeredByTemp);
  284. }
  285. return 0;
  286. }
  287.  
  288. // ----------------------------------------------------------------------------------------------------------------------------
  289. private function GetMovementLastPosition() {
  290. $lastMovment = $this->GetVariableValue(c_Control_Movement);
  291. $currentPosition = $this->GetVariableValue(c_Control_Position);
  292.  
  293. if ($lastMovment==c_MovementId_Stop) {
  294. $lastMovment = $this->GetMovementByPositionSync($currentPosition);
  295. }
  296.  
  297. return $lastMovment;
  298. }
  299.  
  300. // ----------------------------------------------------------------------------------------------------------------------------
  301. private function GetMovementByPosition($Level) {
  302. $result = c_MovementId_Stop;
  303.  
  304. $shadowingType = $this->GetPropertyValue(c_Property_ShadowingType);
  305. if ($Level <= 5) {
  306. switch($shadowingType) {
  307. case c_ShadowingType_Marquees: $result = c_MovementId_MovedIn; break;
  308. default: $result = c_MovementId_Opened; break;
  309. }
  310. } else if ($Level > 5 and $Level <= 55) {
  311. switch($shadowingType) {
  312. case c_ShadowingType_Marquees:
  313. case c_ShadowingType_Shutter: $result = c_MovementId_50; break;
  314. default: $result = c_MovementId_Opened; break;
  315. }
  316. } else if ($Level > 55 and $Level <= 80) {
  317. switch($shadowingType) {
  318. case c_ShadowingType_Marquees:
  319. case c_ShadowingType_Shutter: $result = c_MovementId_75; break;
  320. default: $result = c_MovementId_Stop; break;
  321. }
  322. } else if ($Level > 80 and $Level <= 95) {
  323. switch($shadowingType) {
  324. case c_ShadowingType_Marquees: $result = c_MovementId_MovedOut;break;
  325. case c_ShadowingType_Shutter: $result = c_MovementId_90; break;
  326. default: $result = c_MovementId_Shadowing;
  327. }
  328. } else if ($Level >= 95) {
  329. switch($shadowingType) {
  330. case c_ShadowingType_Marquees: $result = c_MovementId_MovedOut;break;
  331. case c_ShadowingType_Shutter: $result = c_MovementId_Closed; break;
  332. default: $result = c_MovementId_Dimout;
  333. }
  334. } else {
  335. $result = c_MovementId_Stop;
  336. }
  337.  
  338. return $result ;
  339. }
  340.  
  341. // ----------------------------------------------------------------------------------------------------------------------------
  342. private function GetMovementByPositionSync($Level) {
  343. $result = c_MovementId_Stop;
  344.  
  345. $shadowingType = $this->GetPropertyValue(c_Property_ShadowingType);
  346. if ($Level <= 5) {
  347. switch($shadowingType) {
  348. case c_ShadowingType_Marquees: $result = c_MovementId_MovedIn; break;
  349. default: $result = c_MovementId_Opened;
  350. }
  351. } else if ($Level >= 95) {
  352. switch($shadowingType) {
  353. case c_ShadowingType_Marquees: $result = c_MovementId_MovedOut; break;
  354. case c_ShadowingType_Shutter: $result = c_MovementId_Closed; break;
  355. default: $result = c_MovementId_Shadowing;
  356. }
  357. } else if ($Level > 45 and $Level < 55) {
  358. switch($shadowingType) {
  359. case c_ShadowingType_Marquees:
  360. case c_ShadowingType_Shutter: $result = c_MovementId_50; break;
  361. default: $result = c_MovementId_Stop;
  362. }
  363. } else if ($Level > 70 and $Level < 80) {
  364. switch($shadowingType) {
  365. case c_ShadowingType_Marquees:
  366. case c_ShadowingType_Shutter: $result = c_MovementId_75; break;
  367. default: $result = c_MovementId_Stop;
  368. }
  369. } else if ($Level > 85 and $Level < 95) {
  370. switch($shadowingType) {
  371. case c_ShadowingType_Shutter: $result = c_MovementId_90; break;
  372. default: $result = c_MovementId_Stop;
  373. }
  374. } else {
  375. $result = c_MovementId_Stop;
  376. }
  377. return $result ;
  378. }
  379.  
  380. // ----------------------------------------------------------------------------------------------------------------------------
  381. public function MoveByControl($Value) {
  382. if ($Value==c_MovementId_Space) {
  383. return;
  384. } elseif ($this->GetVariableValue(c_Control_Movement)==$Value) {
  385. return;
  386. } else {
  387. if (!$this->GetVariableValue(c_Control_ManualChange)) {
  388. $this->SetVariableValue(c_Control_ManualChange, true);
  389. }
  390. $this->SetVariableValue(c_Control_Movement, $Value);
  391. $this->MoveByStatus();
  392. IPSShadowing_LogMoveByControl($this->deviceId);
  393. }
  394. }
  395.  
  396. // ----------------------------------------------------------------------------------------------------------------------------
  397. public function MoveByLevel($level) {
  398. $movement = $this->GetMovementByPosition($level);
  399.  
  400. if ($this->GetVariableValue(c_Control_StepsToDo)<>"") {
  401. if (!$this->GetVariableValue(c_Control_ManualChange)) {
  402. $this->SetVariableValue(c_Control_ManualChange, true);
  403. }
  404. $this->SetVariableValue(c_Control_Movement, c_MovementId_Stop);
  405. $this->MoveByStatus();
  406. IPSShadowing_LogMoveByControl($this->deviceId);
  407. } else if ($this->GetVariableValue(c_Control_Movement)==$movement) {
  408. $this->SetVariableValue(c_Control_Position, $this->GetVariableValue(c_Control_Position));
  409. return;
  410. } else {
  411. if (!$this->GetVariableValue(c_Control_ManualChange)) {
  412. $this->SetVariableValue(c_Control_ManualChange, true);
  413. }
  414. $this->SetVariableValue(c_Control_Movement, $movement);
  415. $this->MoveByStatus();
  416. IPSShadowing_LogMoveByControl($this->deviceId);
  417. }
  418. }
  419.  
  420. // ----------------------------------------------------------------------------------------------------------------------------
  421. private function AddNextStep(&$StepsToDo, $Command, $SecondsToDo, $Display, $SecondsTotal, $PercentagePosition) {
  422. $Step = count($StepsToDo);
  423. $StepsToDo[$Step] = $Command;
  424. $StepsToDo[$Step+1] = number_format($SecondsToDo,2,'.','');
  425. $StepsToDo[$Step+2] = $Display;
  426. $StepsToDo[$Step+3] = number_format($SecondsTotal,2,'.','');
  427. $StepsToDo[$Step+4] = number_format($PercentagePosition,2,'.','');
  428. }
  429.  
  430. // ----------------------------------------------------------------------------------------------------------------------------
  431. private function CalcNextSteps() {
  432. $DeviceName = IPS_GetIdent($this->deviceId);
  433. $DeviceConfig = get_ShadowingConfiguration();
  434.  
  435. $Position = $this->GetVariableValue(c_Control_Position);
  436. $ToBeMoved = $this->GetVariableValue(c_Control_Movement);
  437. $StepsToDo = array();
  438.  
  439. if ($ToBeMoved==c_MovementId_Opened or $ToBeMoved==c_MovementId_Up) {
  440. $SecTotal = $DeviceConfig[$DeviceName][c_Property_TimeOpening];
  441. $SecNullToPos = $SecTotal*$Position/100;
  442. $SecPosTo100 = $SecTotal-$SecNullToPos;
  443. $this->AddNextStep($StepsToDo, c_MovementId_Up, $SecTotal-$SecPosTo100, null, $SecTotal, $SecPosTo100);
  444. $this->AddNextStep($StepsToDo, c_MovementId_Stop, $DeviceConfig[$DeviceName][c_Property_TimePause], 'Offen (Stop)', null, null);
  445. $this->AddNextStep($StepsToDo, c_MovementId_Opened, 1, null, null , null);
  446.  
  447. } elseif ($ToBeMoved==c_MovementId_MovedIn or $ToBeMoved==c_MovementId_MovingIn) {
  448. $SecTotal = $DeviceConfig[$DeviceName][c_Property_TimeOpening];
  449. $SecNullToPos = $SecTotal*$Position/100;
  450. $SecPosTo100 = $SecTotal-$SecNullToPos;
  451. $this->AddNextStep($StepsToDo, c_MovementId_MovingIn, $SecTotal-$SecPosTo100, null, $SecTotal, $SecPosTo100);
  452. $this->AddNextStep($StepsToDo, c_MovementId_Stop, $DeviceConfig[$DeviceName][c_Property_TimePause], 'Offen (Stop)', null, null);
  453. $this->AddNextStep($StepsToDo, c_MovementId_MovedIn, 1, null, null , null);
  454.  
  455. } elseif ($ToBeMoved==c_MovementId_Shadowing or $ToBeMoved==c_MovementId_Down or $ToBeMoved==c_MovementId_Dimout or $ToBeMoved==c_MovementId_Closed or $ToBeMoved==c_MovementId_MovingOut or $ToBeMoved==c_MovementId_MovedOut) {
  456. $SecTotal = $DeviceConfig[$DeviceName][c_Property_TimeClosing];
  457. $SecNullToPos = $SecTotal*$Position/100;
  458. if ($ToBeMoved==c_MovementId_Dimout) {
  459. $this->AddNextStep($StepsToDo, c_MovementId_Down, $SecTotal-$SecNullToPos, null, $SecTotal, $SecNullToPos);
  460. //$this->AddNextStep($StepsToDo, c_MovementId_Stop, $DeviceConfig[$DeviceName][c_Property_TimePause], 'Abdunkelung (Pause)', null, null);
  461. //$this->AddNextStep($StepsToDo, c_MovementId_Up, $DeviceConfig[$DeviceName][c_Property_TimeDimoutUp], 'Abdunkelung (Hoch)', null, null);
  462. //$this->AddNextStep($StepsToDo, c_MovementId_Stop, $DeviceConfig[$DeviceName][c_Property_TimePause], 'Abdunkelung (Pause)', null, null);
  463. //$this->AddNextStep($StepsToDo, c_MovementId_Down, $DeviceConfig[$DeviceName][c_Property_TimeDimoutUp], 'Abdunkelung (Runter)', null, null);
  464. $this->AddNextStep($StepsToDo, c_MovementId_Stop, $DeviceConfig[$DeviceName][c_Property_TimePause], 'Abdunkelung (Stop)', null, null);
  465. $this->AddNextStep($StepsToDo, c_MovementId_Dimout, 1, null, null, null);
  466. } elseif ($ToBeMoved==c_MovementId_Down) {
  467. $this->AddNextStep($StepsToDo, c_MovementId_Down, $SecTotal-$SecNullToPos, null, $SecTotal, $SecNullToPos);
  468. $this->AddNextStep($StepsToDo, c_MovementId_Stop, 1, null, null, null);
  469. } elseif ($ToBeMoved==c_MovementId_MovedOut or $ToBeMoved==c_MovementId_MovingOut) {
  470. $this->AddNextStep($StepsToDo, c_MovementId_MovingOut, $SecTotal-$SecNullToPos, null, $SecTotal, $SecNullToPos);
  471. $this->AddNextStep($StepsToDo, c_MovementId_Stop, 1, null, null, null);
  472. $this->AddNextStep($StepsToDo, c_MovementId_MovedOut, 1, null, null, null);
  473. } elseif ($ToBeMoved==c_MovementId_Shadowing) {
  474. $this->AddNextStep($StepsToDo, c_MovementId_Down, $SecTotal-$SecNullToPos, null, $SecTotal, $SecNullToPos);
  475. $this->AddNextStep($StepsToDo, c_MovementId_Stop, $DeviceConfig[$DeviceName][c_Property_TimePause], 'Abdunkelung (Stop)', null, null);
  476. //$this->AddNextStep($StepsToDo, c_MovementId_Up, $DeviceConfig[$DeviceName][c_Property_TimeDimoutUp], 'Beschattung (Hoch)', null, null);
  477. $this->AddNextStep($StepsToDo, c_MovementId_StepUp, 1, 'Beschattung (Schritt Hoch)', null, null);
  478. $this->AddNextStep($StepsToDo, c_MovementId_StepUp, 1, 'Beschattung (Schritt Hoch)', null, null);
  479. $this->AddNextStep($StepsToDo, c_MovementId_StepUp, 1, 'Beschattung (Schritt Hoch)', null, null);
  480. //$this->AddNextStep($StepsToDo, c_MovementId_Stop, $DeviceConfig[$DeviceName][c_Property_TimePause], 'Beschattung (Stop)', null, null);
  481. $this->AddNextStep($StepsToDo, c_MovementId_Shadowing, 1, null, null, null);
  482. } else {
  483. $this->AddNextStep($StepsToDo, c_MovementId_Down, $SecTotal-$SecNullToPos, null, $SecTotal, $SecNullToPos);
  484. $this->AddNextStep($StepsToDo, c_MovementId_Stop, 1, "$Position%", null, null);
  485. $this->AddNextStep($StepsToDo, c_MovementId_Closed, 1, null, null, null);
  486. }
  487.  
  488. } elseif ($ToBeMoved==c_MovementId_90 or$ToBeMoved==c_MovementId_75 or $ToBeMoved==c_MovementId_50 or $ToBeMoved==c_MovementId_25) {
  489. $SecTotal = $DeviceConfig[$DeviceName][c_Property_TimeClosing];
  490. $ShadowingType = $DeviceConfig[$DeviceName][c_Property_ShadowingType];
  491. $SecNullToPos = $SecTotal*$Position/100;
  492. $SecPosTo100 = $SecTotal-$SecNullToPos;
  493. if ($ToBeMoved==c_MovementId_90) {
  494. $SecNullToNew = $SecTotal*90/100;
  495. $Position = 90;
  496. } elseif ($ToBeMoved==c_MovementId_75) {
  497. $SecNullToNew = $SecTotal*75/100;
  498. $Position = 75;
  499. } elseif ($ToBeMoved==c_MovementId_50) {
  500. $SecNullToNew = $SecTotal*50/100;
  501. $Position = 50;
  502. } else {
  503. $SecNullToNew = $SecTotal*25/100;
  504. $Position = 25;
  505. }
  506. if ($SecNullToNew > $SecNullToPos) {
  507. if ($ShadowingType==c_ShadowingType_Marquees) {
  508. $this->AddNextStep($StepsToDo, c_MovementId_MovingOut, $SecNullToNew-$SecNullToPos, null, $SecTotal, $SecNullToPos);
  509. } else {
  510. $this->AddNextStep($StepsToDo, c_MovementId_Down, $SecNullToNew-$SecNullToPos, null, $SecTotal, $SecNullToPos);
  511. }
  512. } elseif ($SecNullToNew < $SecNullToPos) {
  513. if ($ShadowingType==c_ShadowingType_Marquees) {
  514. $this->AddNextStep($StepsToDo, c_MovementId_MovingIn, $SecNullToPos-$SecNullToNew, null, $SecTotal, $SecPosTo100);
  515. } else {
  516. $this->AddNextStep($StepsToDo, c_MovementId_Up, $SecNullToPos-$SecNullToNew, null, $SecTotal, $SecPosTo100);
  517. }
  518. } else {
  519. }
  520. $this->AddNextStep($StepsToDo, c_MovementId_Stop, 1, "$Position%", null, null);
  521. $this->AddNextStep($StepsToDo, $ToBeMoved, 1, null, null, null);
  522.  
  523. } elseif ($ToBeMoved==c_MovementId_Stop) {
  524. $this->AddNextStep($StepsToDo, c_MovementId_Stop, 1, null, null, null);
  525.  
  526. } else {
  527. throw new Exception ("Unknown MovementId $ToBeMoved, DeviceId=".$this->deviceId);
  528. exit;
  529. }
  530.  
  531. $this->SetVariableValue(c_Control_StepsToDo, implode('|', $StepsToDo));
  532. $this->SetVariableValue(c_Control_Step, -5);
  533. }
  534.  
  535. // ----------------------------------------------------------------------------------------------------------------------------
  536. private function ExecuteNextStep() {
  537. $DeviceName = IPS_GetIdent($this->deviceId);
  538. $Step = $this->GetVariableValue(c_Control_Step)+5;
  539. $NextStepsToDo = $this->GetVariableValue(c_Control_StepsToDo);
  540. $NextStepsToDo = Explode('|', $NextStepsToDo);
  541.  
  542. if ($Step < count($NextStepsToDo)) {
  543. $Command = $NextStepsToDo[$Step];
  544. $Time = $NextStepsToDo[$Step+1];
  545. IPSLogger_Trc(__file__, "Shadowing for Device '$DeviceName', Step $Step, Command=$Command, Time=$Time");
  546. $this->MoveByCommand($Command);
  547.  
  548. $this->SetVariableValue(c_Control_Step, $Step);
  549. $this->SetVariableValue(c_Control_StartTime, time());
  550. } else {
  551. IPSLogger_Dbg(__file__, "Finished all Steps for Device '$DeviceName'");
  552. $this->SetVariableValue(c_Control_Step, -1);
  553. $this->SetVariableValue(c_Control_StepsToDo, "");
  554. $this->SetVariableValue(c_Control_StartTime, -1);
  555. $this->StartRefreshTimer(false);
  556. $this->SetStatus();
  557. }
  558. }
  559.  
  560. // ----------------------------------------------------------------------------------------------------------------------------
  561. public function Refresh() {
  562. $NextStepsToDo = Explode('|', $this->GetVariableValue(c_Control_StepsToDo));
  563. $StepCount = count($NextStepsToDo);
  564. $Step = $this->GetVariableValue(c_Control_Step);
  565. if ($StepCount >= ($Step+4) and $Step>=0) {
  566. $StartTime = $this->GetVariableValue(c_Control_StartTime);
  567. $SecsDone = time()-$StartTime;
  568. $SecsToDo = (float)$NextStepsToDo[$Step+1];
  569. $Display = $NextStepsToDo[$Step+2];
  570. $SecsTotal = (float)$NextStepsToDo[$Step+3];
  571. $SecStepBegin = (float)$NextStepsToDo[$Step+4];
  572. $Command = $NextStepsToDo[$Step];
  573.  
  574. if ($SecsTotal <> null) {
  575. // SecTotal ... 100%
  576. // Begin+Done ... x%
  577. $Position = (int)round(($SecStepBegin+$SecsDone)*100/$SecsTotal);
  578. if ($Command==c_MovementId_Up or $Command==c_MovementId_MovingIn) {
  579. $Position = 100-$Position;
  580. }
  581. if ($Position>100) {$Position=100;}
  582. if ($Position<0) {$Position=0;}
  583. $this->SetVariableValue(c_Control_Position, $Position);
  584. $SecsOpen = $SecsToDo-$SecsDone;
  585. if ($SecsOpen < 0) {$SecsOpen=0;}
  586. $Display = "$Position% ($SecsOpen Sek)";
  587. }
  588.  
  589. if ($Display!=null) {
  590. $this->SetVariableValue(c_Control_Display, $Display);
  591. }
  592.  
  593. if (function_exists('IPSShadowing_Refresh')) {
  594. IPSShadowing_Refresh($this->deviceId, $StepCount, $Step, $Command, $SecsToDo, $SecsDone);
  595. }
  596.  
  597. if ($SecsDone >= $SecsToDo) {
  598. $this->ExecuteNextStep();
  599. }
  600. return true;
  601. } else {
  602. return false;
  603. }
  604. }
  605.  
  606. // ----------------------------------------------------------------------------------------------------------------------------
  607. private function StartRefreshTimer($Value) {
  608. if ($Value) {
  609. $Name = 'Refresh';
  610. $refreshTimerScriptId = IPSUtil_ObjectIDByPath('Program.IPSLibrary.app.modules.IPSShadowing.IPSShadowing_RefreshTimer');
  611.  
  612. $TimerId = @IPS_GetEventIDByName($Name, $refreshTimerScriptId);
  613. if ($TimerId === false) {
  614. $TimerId = IPS_CreateEvent(1 /*Cyclic Event*/);
  615. IPS_SetName($TimerId, $Name);
  616. IPS_SetParent($TimerId, $refreshTimerScriptId);
  617. if (!IPS_SetEventCyclic($TimerId, 2 /*Daily*/, 1 /*Int*/,0 /*Days*/,0 /*DayInt*/,1 /*TimeType Sec*/,1 /*Sec*/)) {
  618. throw new Exception ("IPS_SetEventCyclic failed for Refresh Timer!!!");
  619. }
  620. }
  621. IPS_SetEventActive($TimerId, true);
  622. }
  623. }
  624.  
  625. // ----------------------------------------------------------------------------------------------------------------------------
  626. public function ChangeSetting($controlId, $value) {
  627. if (GetValue($controlId)<>$value) {
  628. if (IPS_GetIdent($controlId)==c_Control_Automatic) {
  629. if (GetValue(IPS_GetObjectIDByIdent(c_Control_TempChange, $this->deviceId))) {
  630. SetValue(IPS_GetObjectIDByIdent(c_Control_TempChange, $this->deviceId), false);
  631. }
  632. } else {
  633. }
  634. if (GetValue(IPS_GetObjectIDByIdent(c_Control_ManualChange, $this->deviceId))) {
  635. SetValue(IPS_GetObjectIDByIdent(c_Control_ManualChange, $this->deviceId), false);
  636. }
  637. SetValue($controlId, $value);
  638. IPSShadowing_LogChange($this->deviceId, $value, $controlId);
  639. $this->SetStatus();
  640. }
  641. }
  642.  
  643. // ----------------------------------------------------------------------------------------------------------------------------
  644. public function CheckPrograms($profileManager) {
  645. $deviceName = IPS_GetIdent($this->deviceId);
  646. $profileIdTemp = GetValue(IPS_GetObjectIDByIdent(c_Control_ProfileTemp, $this->deviceId));
  647. $profileIdSun = GetValue(IPS_GetObjectIDByIdent(c_Control_ProfileSun, $this->deviceId));
  648. $profileIdBgnOfDay = GetValue(IPS_GetObjectIDByIdent(c_Control_ProfileBgnOfDay, $this->deviceId));
  649. $profileIdEndOfDay = GetValue(IPS_GetObjectIDByIdent(c_Control_ProfileEndOfDay, $this->deviceId));
  650. $profileIdWeather = null;
  651. $programPresent = GetValue(IPS_GetObjectIDByIdent(c_Control_ProgramPresent, $this->deviceId));
  652. $programTemp = GetValue(IPS_GetObjectIDByIdent(c_Control_ProgramTemp, $this->deviceId));
  653. $programDay = GetValue(IPS_GetObjectIDByIdent(c_Control_ProgramDay, $this->deviceId));
  654. $programNight = GetValue(IPS_GetObjectIDByIdent(c_Control_ProgramNight, $this->deviceId));
  655. $programWeather = null;
  656. $automaticActive = GetValue(IPS_GetObjectIDByIdent(c_Control_Automatic, $this->deviceId));
  657. $tempIndoorPath = $this->GetPropertyValue(c_Property_TempSensorIndoor);
  658.  
  659. $controlId = @IPS_GetObjectIDByIdent(c_Control_ProfileWeather, $this->deviceId);
  660. if ($controlId!==false) {
  661. $profileIdWeather = GetValue($controlId);
  662. $programWeather = GetValue(IPS_GetObjectIDByIdent(c_Control_ProgramWeather, $this->deviceId));
  663. }
  664.  
  665. $isDay = $profileManager->IsDay($profileIdBgnOfDay, $profileIdEndOfDay);
  666. $isDayNightChange = $profileManager->IsDayNightChange($profileIdBgnOfDay, $profileIdEndOfDay);
  667. $closeByTemp = $profileManager->CloseByTemp($profileIdSun, $profileIdTemp, $tempIndoorPath);
  668. $shadowingByTemp = $profileManager->ShadowingByTemp($profileIdSun, $profileIdTemp, $tempIndoorPath);
  669. $openByTemp = $profileManager->OpenByTemp($profileIdSun, $profileIdTemp, $tempIndoorPath);
  670. $activationByWeather = $profileManager->ActivationByWeather($profileIdWeather);
  671. $programInfo = '';
  672. $programDelay = false;
  673.  
  674.  
  675. // Reset Manual Change Flag
  676. if ($isDayNightChange) {
  677. if (GetValue(IPS_GetObjectIDByIdent(c_Control_ManualChange, $this->deviceId))) {
  678. IPSLogger_Dbg(__file__, "Reset ManualChange Flag for Device '$deviceName'");
  679. SetValue(IPS_GetObjectIDByIdent(c_Control_ManualChange, $this->deviceId), false);
  680. }
  681. if (GetValue(IPS_GetObjectIDByIdent(c_Control_TempChange, $this->deviceId))) {
  682. IPSLogger_Dbg(__file__, "Reset TempChange Flag for Device '$deviceName'");
  683. SetValue(IPS_GetObjectIDByIdent(c_Control_TempChange, $this->deviceId), false);
  684. }
  685. }
  686.  
  687. $changeByTemp = GetValue(IPS_GetObjectIDByIdent(c_Control_TempChange, $this->deviceId));
  688. $changeByUser = GetValue(IPS_GetObjectIDByIdent(c_Control_ManualChange, $this->deviceId));
  689.  
  690. $func_reflection = new ReflectionFunction('IPSShadowing_ProgramCustom');
  691. $paramCountCustom = $func_reflection->getNumberOfParameters();
  692.  
  693. // Check all Programs
  694. // --------------------------------------------------------------------------------
  695. // Automatic Off ...
  696. if (!$automaticActive) {
  697. $programInfo = 'Automatic Off';
  698.  
  699. // Activation by Wind/Rain
  700. } elseif ($activationByWeather and $programWeather<>c_ProgramId_Manual) {
  701. $programInfo = 'Wetterprogramm';
  702. $programDelay = $this->MoveByProgram($programWeather, 'Wetterprogramm');
  703.  
  704. // Custom
  705. } elseif ( ($paramCountCustom == 3 and IPSShadowing_ProgramCustom($this->deviceId, $isDay, $programInfo))
  706. or ($paramCountCustom == 2 and IPSShadowing_ProgramCustom($this->deviceId, $isDay))) {
  707. if ($programInfo=='') {$programInfo = 'CustomProgram';}
  708. // Action done in Custom Procedure
  709.  
  710. // Manual Change ...
  711. } elseif ($changeByUser) {
  712. $programInfo = 'Manuelle Änderung';
  713.  
  714. // Present ...
  715. } elseif ($profileManager->GetPresent() and $programPresent==c_ProgramId_OpenedDay and $isDay) {
  716. $programInfo = 'Anwesenheit (Tag)';
  717. $programDelay = $this->MoveByProgram($programPresent, 'Anwesenheitsprogramm');
  718. } elseif ($profileManager->GetPresent() and $programPresent==c_ProgramId_OpenedNight and !$isDay) {
  719. $programInfo = 'Anwesenheit (Nacht)';
  720. $programDelay = $this->MoveByProgram($programPresent, 'Anwesenheitsprogramm');
  721. } elseif ($profileManager->GetPresent() and $programPresent==c_ProgramId_Opened) {
  722. $programInfo = 'Anwesenheit';
  723. $programDelay = $this->MoveByProgram($programPresent, 'Anwesenheitsprogramm');
  724. } elseif ($profileManager->GetPresent() and $programPresent==c_ProgramId_MovedOutTemp and $isDay and $closeByTemp) {
  725. $programInfo = 'Anwesenheit (Temperatur)';
  726. $programDelay = $this->MoveByProgram($programPresent, 'Anwesenheitsprogramm (Beschattung bei Temp und Anwesenheit)');
  727.  
  728. // Temperature/Sun
  729. } elseif ($isDay and ($closeByTemp or $shadowingByTemp) and $programTemp<>c_ProgramId_Manual) {
  730. if ($closeByTemp) {
  731. $programInfo = 'Temperatur';
  732. $programDelay = $this->MoveByProgram($programTemp, 'Temperaturprogramm', true/*DimoutOption*/, true/*TriggeredByTemp*/);
  733. } elseif ($changeByTemp) {
  734. $programInfo = 'Temperatur (Warte Öffnen)';
  735. } elseif ($shadowingByTemp) {
  736. $programInfo = 'Temperatur (Beschattung)';
  737. $programDelay = $this->MoveByProgram($programTemp, 'Temperaturprogramm (Beschattung)', false/*DimoutOption*/, true/*TriggeredByTemp*/);
  738. } else {
  739. $programInfo = 'Temperatur (Error)';
  740. }
  741.  
  742. // Day
  743. } elseif ($isDay) {
  744. if (!$openByTemp and $changeByTemp) {
  745. $programInfo = 'Tag (Warte Öffnen)';
  746. } elseif ($openByTemp and $changeByTemp) {
  747. SetValue(IPS_GetObjectIDByIdent(c_Control_TempChange, $this->deviceId), false);
  748. if ($programDay<>c_ProgramId_Manual) {
  749. $programInfo = 'Temperatur Reset (Tag)';
  750. $programDelay = $this->MoveByProgram($programDay, 'Temperatur Reset (Tag)');
  751. } else {
  752. $programInfo = 'Temperatur Reset (LastPosition)';
  753. $programDelay = $this->MoveByProgram(c_ProgramId_LastPosition, 'Temperatur Reset (LastPosition)');
  754. }
  755. } else {
  756. $programInfo = 'Tagesprogramm';
  757. $programDelay = $this->MoveByProgram($programDay, 'Tagesprogramm');
  758. }
  759.  
  760. // Night
  761. } else {
  762. $programInfo = 'Nachtprogramm';
  763. $programDelay = $this->MoveByProgram($programNight, '"Nachtprogramm"');
  764. }
  765.  
  766. // Update ProfileInfos
  767. if ($programDelay > 0)
  768. $programInfo = 'Warte '.$programDelay.' Min '.$programInfo;
  769. $profileInfo = $profileManager->GetProfileInfo($profileIdBgnOfDay, $profileIdEndOfDay, $profileIdTemp, $tempIndoorPath);
  770. $deviceName = IPSShadowing_GetDeviceName($this->deviceId);
  771. echo "$deviceName -> $programInfo, $profileInfo \n";
  772. SetValue(IPS_GetObjectIDByIdent(c_Control_ProfileInfo, $this->deviceId), $programInfo.', '.$profileInfo);
  773. }
  774. }
  775.  
  776.  
  777. /** @}*/
  778. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement