Ejemplo n.º 1
0
    {
        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());
Ejemplo n.º 2
0
// '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();
    $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.º 3
0
}
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) {
        sleep($trans);
    } else {