diff --git a/server/ControlScripts/SpotlightsScope.php b/server/ControlScripts/SpotlightsScope.php index 2121569..c24ce05 100644 --- a/server/ControlScripts/SpotlightsScope.php +++ b/server/ControlScripts/SpotlightsScope.php @@ -30,7 +30,36 @@ } public function register_regular_scripts(): void { + $this -> add_regular_script([ + "alias" => "spotlights_by_time", + "name" => "Spotlights by Time", + "description" => "Управление уличными прожекторами по времени", + "author" => "Eugene Sukhodolskiy" + ], function () { + $tz = new \DateTimeZone('Europe/Kyiv'); + $now = new \DateTime('now', $tz); + $limit = new \DateTime('9:00', $tz); + + if ($now >= $limit) { + try { + $relay_api = $this -> devices() -> by_alias("spotlight_main_back_2") -> device_api(); + if($relay_api instanceof \SHServ\Tools\DeviceAPI\Relay) { + $relay_api -> set_state(false); + } + + // if($btn_api instanceof \SHServ\Tools\DeviceAPI\Button) { + // if(($btn_api -> get_status())["channels"][2]["indicator"] != "error") { + // $btn_api -> set_channel_state("error", 2); + // } else { + // $btn_api -> set_channel_state("mute", 2); + // } + // } + } catch(\Exception $e) { + echo $e -> getMessage(); + } + } + }); } // ACTIONS @@ -45,7 +74,14 @@ $results = []; foreach($aliases as $alias) { - $results[$alias] = $this -> devices() -> by_alias($alias) -> device_api() -> set_state($state); + $relay_api = $this -> devices() -> by_alias($alias) -> device_api(); + $result = false; + + if($relay_api instanceof \SHServ\Tools\DeviceAPI\Relay) { + $result = $relay_api -> set_state($state); + } + + $results[$alias] = $result; } return [