Skip to content

Instantly share code, notes, and snippets.

@tooooooooomy
Created January 17, 2015 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tooooooooomy/081a95fc10b0a4b9e04a to your computer and use it in GitHub Desktop.
Save tooooooooomy/081a95fc10b0a4b9e04a to your computer and use it in GitHub Desktop.
Philips Hue + PHPで天気予報 ref: http://qiita.com/tooooooooomy/items/11c661de0b8161a85d62
<?php
require_once __DIR__ . '/vendor/autoload.php';
$url = "http://www.drk7.jp/weather/xml/13.xml"; //13は東京
$xml = file_get_contents($url, true);
$parsedXml = new \SimpleXMLElement($xml);
$rain = "";
$hueHost = "ブリッジのIP";
$hueUsername = "登録したユーザーネーム";
foreach ($parsedXml->pref->area as $area) {
if ($area->attributes()["id"] != "東京地方") continue;
$hour = date("H");
$periodAry = get_object_vars($area->info->rainfallchance)["period"];
switch (true) {
case $hour < "06": // 00 ~ 06
$rain = $periodAry[0];
break;
case $hour < "12": // 06 ~ 12
$rain = $periodAry[1];
break;
case $hour < "18": // 12 ~ 18
$rain = $periodAry[2];
break;
default: //18 ~ 24
$rain = $periodAry[3];
break;
}
}
$client = new \Phue\Client($hueHost, $hueUsername);
$light = $client->getLights()[4];
$brightness = 50; //輝度 0 ~ 255
$saturation = 255; //彩度 0 ~ 255
$effect = "none"; //none or colorloop
$alert = "lselect"; //select, lselect, none
if ($rain < 30) { // 降水確率30%以下
$hue = 65000; //赤 色相 0 ~ 65535
// Send command
$client->sendCommand(
(new \Phue\Command\SetLightState($light))
->brightness($brightness)
->hue($hue)
->saturation($saturation)
->effect($effect)
->alert($alert)
);
} else {
$hue = 47000; //青
// Send command
$client->sendCommand(
(new \Phue\Command\SetLightState($light))
->brightness($brightness)
->hue($hue)
->saturation($saturation)
->effect($effect)
->alert($alert)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment