Ejemplo n.º 1
0
$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);
// both to 4700k
$hue->set_params(4, array('ct' => Hue::ct_to_mired(4700), 'transitiontime' => 6000));
Ejemplo n.º 2
0
$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 {
        sleep(120);
    }
}