function create() { $hue = new Hue(); $hue->discover(); (new Sync())->update(Sync::LIGHTS); return 200; }
public static function setColors($colors) { $hue = new Hue(self::IP, self::USER); $lights = $hue->lights(); for ($i = 1; $i <= count($lights); $i++) { $light = $lights[$i]; $color = $colors[$i % count($colors)]; $light->setLight($color); } }
public function status($pattern) { $size_lights = count($this->lights); $size_pattern = count($pattern); $hue = new Hue(); if ($size_lights != $size_pattern) { return false; } for ($i = 0; $i < $size_lights; $i++) { $light = $this->lights[$i]; $protocol = $light['protocol']; switch ($protocol) { case 'hue': $uid = $light['uid']; $status = $pattern[$i] == true ? 'true' : 'false'; $hue->on($uid, $status); break; } } }
$settings = parse_ini_file(getenv('HOME') . '/.lights.conf'); $now = new DateTime(); $now_date = $now->format('Y-m-d'); # get sunrise / sunset $sunrise_start = DateTime::createFromFormat('Y-m-d H:i', $now_date . ' ' . $settings['SUNRISE_START']); $sunrise_duration = new DateInterval('PT' . $settings['SUNRISE_DURATION'] . 'M'); $sunset_start = DateTime::createFromFormat('Y-m-d H:i', $now_date . ' ' . $settings['SUNSET_START']); $sunset_duration = new DateInterval('PT' . $settings['SUNSET_DURATION'] . 'M'); $sunrise_end = clone $sunrise_start; $sunset_end = clone $sunset_start; $sunrise_end->add($sunrise_duration); $sunset_end->add($sunset_duration); # get settings $cold = $settings['COLD']; $warm = $settings['WARM']; $hue = new Hue($settings['SECRET'], $settings['HUEIP']); $target_ct = null; // 'night' -> red if ($now < $sunrise_start) { $target_ct = $warm; } // it's sunrise time -- scripted elsewhere. do nothing if ($now >= $sunrise_start && $now <= $sunrise_end) { } // after waking up -> blue if ($now > $sunrise_end && $now < $sunset_start) { $target_ct = $cold; } // interpolate if ($now >= $sunset_start && $now <= $sunset_end) { $du = $sunset_end->getTimestamp() - $sunset_start->getTimestamp();
} date_default_timezone_set('Europe/Berlin'); $settings = parse_ini_file(getenv('HOME') . '/.lights.conf'); $now = new DateTime(); $now_date = $now->format('Y-m-d'); # get sunrise / sunset $sunrise_start = DateTime::createFromFormat('Y-m-d H:i', $now_date . ' ' . $settings['SUNRISE_START']); $sunrise_duration = new DateInterval('PT' . $settings['SUNRISE_DURATION'] . 'M'); $sunset_start = DateTime::createFromFormat('Y-m-d H:i', $now_date . ' ' . $settings['SUNSET_START']); $sunset_duration = new DateInterval('PT' . $settings['SUNSET_DURATION'] . 'M'); $sunrise_end = clone $sunrise_start; $sunset_end = clone $sunset_start; $sunrise_end->add($sunrise_duration); $sunset_end->add($sunset_duration); # get settings $hue = new Hue($settings['SECRET'], $settings['HUEIP']); // uplight red $hue->set_params(4, array('on' => true, 'hue' => 0, 'sat' => 255, 'bri' => 0, 'transitiontime' => 0)); sleep(1); // 2000k $hue->set_params(4, array('ct' => Hue::ct_to_mired(2000), 'bri' => 255, 'transitiontime' => 6000)); sleep(600); // transition uplight to 2700k -> minimum osram can do $hue->set_params(4, array('ct' => Hue::ct_to_mired(2700), 'transitiontime' => 3000)); sleep(300); // transition both to 3500k $hue->set_params(4, array('ct' => Hue::ct_to_mired(3500), 'transitiontime' => 3000)); $hue->set_params(10, array('on' => true, 'ct' => Hue::ct_to_mired(2700), 'bri' => 10, 'transitiontime' => 60)); sleep(10); $hue->set_params(10, array('ct' => Hue::ct_to_mired(3500), 'bri' => 80, 'transitiontime' => 3000)); sleep(300);
public function get_current_config() { return json_decode($this->get_ssl_page($this->_base . 'lights'), true); } public function set_many($bulbs, $params) { foreach ($bulbs as $bulb => $value) { echo $this->set_params($bulb, $params) . PHP_EOL; } } public static function ct_to_mired($ct) { return round(1000000 / $ct); } } date_default_timezone_set('Europe/Berlin'); $settings = parse_ini_file(getenv('HOME') . '/.lights.conf'); $now = new DateTime(); $now_date = $now->format('Y-m-d'); # get sunrise / sunset $sunrise_start = DateTime::createFromFormat('Y-m-d H:i', $now_date . ' ' . $settings['SUNRISE_START']); $sunrise_duration = new DateInterval('PT' . $settings['SUNRISE_DURATION'] . 'M'); $sunset_start = DateTime::createFromFormat('Y-m-d H:i', $now_date . ' ' . $settings['SUNSET_START']); $sunset_duration = new DateInterval('PT' . $settings['SUNSET_DURATION'] . 'M'); $sunrise_end = clone $sunrise_start; $sunset_end = clone $sunset_start; $sunrise_end->add($sunrise_duration); $sunset_end->add($sunset_duration); # get settings $hue = new Hue($settings['SECRET'], $settings['HUEIP']); var_dump($hue->get_current_config());
return round(1000000 / $ct); } } date_default_timezone_set('Europe/Berlin'); $settings = parse_ini_file(getenv('HOME') . '/.lights.conf'); $bulbs = $settings['FADE_LIGHT']; #$sunrise_start = DateTime::createFromFormat('Y-m-d H:i', $now_date . ' ' . $settings['SUNRISE_START']); #$sunrise_duration = new DateInterval('PT' . $settings['SUNRISE_DURATION'] . 'M'); #$sunset_start = DateTime::createFromFormat('Y-m-d H:i', $now_date . ' ' . $settings['SUNSET_START']); #$sunset_duration = new DateInterval('PT' . $settings['SUNSET_DURATION'] . 'M'); #$sunrise_end = clone($sunrise_start); #$sunset_end = clone($sunset_start); #$sunrise_end->add($sunrise_duration); #$sunset_end->add($sunset_duration); # get settings $core = new Hue($settings['SECRET'], $settings['HUEIP']); while (true) { $config = $core->get_current_config(); $trans = mt_rand(15, 35); $on = false; foreach ($bulbs as $bulb) { $hue = mt_rand(0, 65535); $sat = mt_rand(127, 254); $bri = mt_rand(40, 254); $cf_bulb = $config[(int) $bulb]; if ($cf_bulb['state']['on'] === true) { $on = true; $core->set_params((int) $bulb, array('hue' => $hue, 'sat' => $sat, 'bri' => $bri, 'transitiontime' => $trans * 10)); } } if ($on) {
} public function __construct($apikey, $ip) { $thisapikey = $apikey; $this->_base = 'http://' . $ip . '/api/' . $apikey . '/'; $this->_ip = $ip; } public function get_current_config() { return json_decode($this->get_ssl_page($this->_base . 'lights'), true); } public function set_many($bulbs, $params) { $filtered = array_filter($bulbs, function ($k) use($params) { // echo '|' . $k['state']['ct'] . '| |' . $params['ct'] . '|' . PHP_EOL; return $k['state']['ct'] != $params['ct']; }); foreach ($filtered as $bulb => $value) { echo $this->set_params($bulb, $params) . PHP_EOL; } } } date_default_timezone_set('Europe/Berlin'); $settings = parse_ini_file(getenv('HOME') . '/.lights.conf'); $hue = new Hue($settings['SECRET'], $settings['HUEIP']); $config = $hue->get_current_config(); $filtered = array_filter($config, function ($k) { // find lights that are turned on, can change color temperature, where a color temperature is actually set, and which is currently reachable return $k['state']['on'] === true; }); $hue->set_many($filtered, array('alert' => 'lselect'));