Ejemplo n.º 1
0
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();
    $da = $now->getTimestamp() - $sunset_start->getTimestamp();
    $target_ct = round(($cold - $warm) * (1 - $da / $du) + $warm);
}
// late -> red
if ($now > $sunset_end) {
    $target_ct = $warm;
}
if ($target_ct === null) {
    exit;
}
$config = $hue->get_current_config();
//var_dump($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 && ($k['type'] === 'Extended color light' || $k['type'] === 'Color temperature light') && $k['state']['colormode'] === 'ct' && $k['state']['reachable'] === true;
});
$hue->set_many($filtered, array('ct' => round(1000000 / $target_ct), 'transitiontime' => 390));
Ejemplo n.º 2
0
    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'));