Skip to content

Commit

Permalink
v1.5a
Browse files Browse the repository at this point in the history
  • Loading branch information
FredBardin committed Jul 29, 2016
1 parent 1635b95 commit ec682ae
Show file tree
Hide file tree
Showing 19 changed files with 881 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ $RECYCLE.BIN/
*.zip
*.txt
!LICENCE.txt
!histo.txt
!HISTO.txt
*.swp
include/config.php
*_old.php
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# phpMyHue
Php web interface to manage Philips Hue lights in a lan.
Php web interface to manage Philips Hue lights in a local network.

## Main Functionnalities
* **Full group management**
Expand All @@ -16,13 +16,14 @@ Php web interface to manage Philips Hue lights in a lan.
* Hue effects web service available with 'main.php' ([see wiki](https://github.com/FredBardin/phpMyHue/wiki/Web-services))
* ...

ie: lights screen in english
**Screenshots**
Lights screen in english
![screenshot](screen1_pmh.jpg)

ie: scenes screen in french
Scenes screen in french
![screenshot](screen2_pmh.jpg)

ie: effects screen in english
Effects screen in english
![screenshot](screen3_pmh.gif)

## Installation
Expand Down
8 changes: 6 additions & 2 deletions details.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
include 'include/hueapi.php';

@$rt=$_REQUEST['rt'];
@$nohide=$_REQUEST['nh']; // if set : doesn't hide details tab

switch ($rt)
{
Expand All @@ -22,14 +23,17 @@
$HueAPI->loadInfo("lights");
$HueAPI->assignLightsGroup();
case "effects" :
case "rules" :
include 'include/'.$rt.'_details.php';
break;
case "adm" :
break;
}
if (! isset($nohide)){
?>
<SCRIPT>
$("#detail").hide();
</SCRIPT>
<?php
}
?>


7 changes: 6 additions & 1 deletion histo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ v1.2.2 - 16/07/2015 : Update logo in code and screenshots
v1.3 - 07/11/2015 : Add Automatic Configuration
v1.4 - 13/12/2015 : Add Effects scripts
v1.4.1 - 28/12/2015 : Correction to manage white only lights (='dimmable light' type)

v1.4.2 - 05/05/2016 : add new effect sample
v1.5 - 05/03/2016 :
- Add Sensors Rules management
- Update color conversion with new formulas from meethue
- Now, manage also 'on' status in setcolor/getcolor effect execution (not only color status)
- Update some sample effects with save/restore original status
4 changes: 2 additions & 2 deletions include/about.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<SCRIPT language="javascript">
$('#detail').hide("slide");
</SCRIPT>
<DIV ID=about>phpMyHue 1.4.1<BR>
&copy; <A HREF="mailto:[email protected]" CLASS=about>F. Bardin</A> 12-2015<BR>
<DIV ID=about>phpMyHue 1.5<BR>
&copy; <A HREF="mailto:[email protected]" CLASS=about>F. Bardin</A> 03-2016<BR>
<small>
Bridge IP : <?php echo $bridgeip?><BR>
Current language : <?php echo $lang?>
Expand Down
3 changes: 1 addition & 2 deletions include/effects_details.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@

echo "<BR><BUTTON ID=rundbg>".$trs["Launch_with_execution_trace"]."</BUTTON>";

echo "<DIV ID=runout></DIV>";
echo "<DIV ID=runout title=\"".$trs["Execution_trace"]."\"></DIV>";
?>
<SCRIPT language="javascript">
scrollCurrentTab('#detail');
$("#rundbg").button();
$("#runout").dialog({
title: trs.Execution_trace,
closeText: trs.Close,
autoOpen: false,
width : 500,
Expand Down
138 changes: 124 additions & 14 deletions include/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ function display_bri_slider($prefid,$id,$gnum,$lnum=""){
} // display_bri_slider

// -------------------------------------------------------------
// Display checkbox for selecting groups or lights
// Display checkbox for selecting a row from a table
// -------------------------------------------------------------
// parameters : prefix id, checkbox ID, checkbox class, light id, grp id
// -------------------------------------------------------------
function display_lg_checkbox($prefid, $id, $class="", $gnum="", $lnum=""){
echo "<TD>&nbsp;";
function display_td_checkbox($prefid, $id, $class="", $gnum="", $lnum=""){
echo "<TD> ";
echo "<SPAN ID=".$prefid."s_$id>";
echo "<INPUT TYPE=checkbox ID=".$prefid."cb_$id";
if ($class != ""){
Expand All @@ -61,7 +61,7 @@ function display_lg_checkbox($prefid, $id, $class="", $gnum="", $lnum=""){
}
echo ">";
echo "</SPAN>";
} // display_lg_checkbox
} // display_td_checkbox

// -------------------------------------------------------------
// Display a light row
Expand All @@ -81,13 +81,13 @@ function display_light_row($prefid,$lnum,$gnum,$cbpos="E",$brislider=false){
// Display icon+name
echo "<TR CLASS=\"light grp$gnum\" lnum=$lnum gnum=$gnum>";
echo "<TD>";
if ($cbpos == "B"){display_lg_checkbox($prefid, $lid, "light", $gnum, $lnum);}
if ($cbpos == "B"){display_td_checkbox($prefid, $lid, "light", $gnum, $lnum);}
echo "<TD>";
if (! $unreachable){echo "<A HREF=lights CLASS=switch lnum=$lnum>";}
display_light($lnum);
if (! $unreachable){echo "</A>";}
echo "<TD CLASS=\"label light\"><LABEL FOR=".$prefid."cb_$lid>".$HueAPI->info['lights'][$lnum]['name']."</LABEL>";
if ($cbpos == "E"){display_lg_checkbox($prefid, $lid, "light", $gnum, $lnum);}
echo "<TD CLASS=\"label light\"><LABEL FOR=".$prefid."cb_$lid lnum=$lnum>".$HueAPI->info['lights'][$lnum]['name']."</LABEL>";
if ($cbpos == "E"){display_td_checkbox($prefid, $lid, "light", $gnum, $lnum);}
if ($brislider){display_bri_slider($prefid,$lid,$gnum,$lnum);}
} // display_light_row

Expand All @@ -106,35 +106,145 @@ function display_lights_groups($prefid="",$cbpos="E",$brislider=false){
echo "<THEAD>";
echo "<TR>";
echo "<TD>";
if ($cbpos == "B"){display_lg_checkbox($prefid,"all");}
if ($cbpos == "B"){display_td_checkbox($prefid,"all");}
echo "<TD CLASS=\"label all\"><LABEL FOR=".$prefid."cb_all>".$trs["All"]."</LABEL>";
echo "<TD><BUTTON ID=".$prefid."allon>On</BUTTON><BUTTON ID=".$prefid."alloff>Off</BUTTON>";
if ($cbpos == "E"){display_lg_checkbox($prefid,"all");}
if ($cbpos == "E"){display_td_checkbox($prefid,"all");}
if ($brislider){display_bri_slider($prefid,"all","all");}

echo "<TBODY>";
foreach ($HueAPI->info['groups'] as $gnum => $gval){ // Existing groups
echo "<TR CLASS=grp gnum=$gnum>";
echo "<TD><SPAN CLASS=\"grp ui-icon ui-icon-circle-minus\" gnum=$gnum open></SPAN>";
if ($cbpos == "B"){display_lg_checkbox($prefid, "$gnum", "grp", $gnum);}
echo "<TD CLASS=\"label grp\"><LABEL FOR=".$prefid."cb_$gnum>".$gval['name']."</LABEL>";
if ($cbpos == "B"){display_td_checkbox($prefid, "$gnum", "grp", $gnum);}
echo "<TD CLASS=\"label grp\"><LABEL FOR=".$prefid."cb_$gnum gnum=$gnum>".$gval['name']."</LABEL>";
echo "<TD><BUTTON CLASS=gron gnum=$gnum>On</BUTTON><BUTTON CLASS=groff gnum=$gnum>Off</BUTTON>";
if ($cbpos == "E"){display_lg_checkbox($prefid, $gnum, "grp", $gnum);}
if ($cbpos == "E"){display_td_checkbox($prefid, $gnum, "grp", $gnum);}
if ($brislider){display_bri_slider($prefid,$gnum,$gnum);}
foreach ($gval['lights'] as $internal => $lnum){display_light_row($prefid,$lnum,$gnum,$cbpos,$brislider);}
}

// Lamps without group
echo "<TR CLASS=grp gnum=other>";
echo "<TD><SPAN CLASS=\"grp ui-icon ui-icon-circle-minus\" gnum=other open></SPAN>";
if ($cbpos == "B"){display_lg_checkbox($prefid, "other", "grp", "other");}
if ($cbpos == "B"){display_td_checkbox($prefid, "other", "grp", "other");}
echo "<TD CLASS=\"label grp\"><LABEL FOR=".$prefid."cb_other>".$trs["Lamps"]."</LABEL>";
echo "<TD><BUTTON ID=".$prefid."otheron>On</BUTTON><BUTTON ID=".$prefid."otheroff>Off</BUTTON>";
if ($cbpos == "E"){display_lg_checkbox($prefid, "other", "grp", "other");}
if ($cbpos == "E"){display_td_checkbox($prefid, "other", "grp", "other");}
if ($brislider){display_bri_slider($prefid,"other","other");}
foreach ($HueAPI->info['lights'] as $lnum => $lval){if (! isset($lval['grp'])){display_light_row($prefid,$lnum,"other",$cbpos,$brislider);}}
echo "</DIV>";

echo "</TABLE>";
} // display_lights_groups

//-------------------------------------------------------
// Function to get a condition row
// Return the html string
// Parameters :
// sensorid = sensor id
// cond = condition id (0 to 3)
// cval = condition values (if existing)
// create = true/false. If false, display existing cval
// If true, create new cval row content (without <TR> tag)
//-------------------------------------------------------
function getCondRow($sensorid, $cond, $cval, $create=false){
if ($create){ // Init fields if row creation
$cval['address'] = "";
$cval['operator'] = "";
$cval['value'] = "";
}
else {echo "<TR>";}
display_td_checkbox("cond",$cond,"csel");
echo "<TD>";
echo "<INPUT TYPE=text ID=caddr$cond VALUE=\"".str_replace("/sensors/$sensorid/","",$cval['address'])."\" CLASS=ui-corner-all>";
echo "<TD>";
selOperator("sbcond_".$cond,$cval['operator']);
echo "<TD>";
echo "<INPUT TYPE=text ID=cval$cond VALUE=\"";
if ($cval['operator'] == "dx"){ // No value for dx
echo "\" style=\"display: none;\"";
} else {
echo $cval['value']."\"";
}
echo " CLASS=ui-corner-all>\n";
} // getCondRow

//-------------------------------------------------------
// Function to get an action row
// Return the html string
// Parameters :
// act = action id (0 to 3)
// aval = action values (if existing)
// create = true/false. If false, display existing aval
// If true, create new aval row content (without <TR> tag)
//-------------------------------------------------------
function getActRow($act, $aval, $create=false){
if ($create){ // Init fields if row creation
$aval['address'] = "";
$aval['method'] = "PUT";
$aval['body'] = "";
}
else {echo "<TR>";}
display_td_checkbox("act",$act,"asel");
echo "<TD>";
echo "<INPUT TYPE=text ID=aaddr$act VALUE=\"".$aval['address']."\" CLASS=ui-corner-all>";
echo "<TD>";
selMethod("sbact_".$act,$aval['method']);
echo "<TD>";
echo "<INPUT TYPE=text ID=abody$act VALUE=\"";
$comma="";
if ($aval['body'] != ""){
foreach ($aval['body'] as $key => $val){
echo $comma."&quot;$key&quot;:&quot;$val&quot;";
$comma=", ";
}
}
echo "\" CLASS=ui-corner-all>\n";
} // getActRow

//-------------------------------------------------------
// Function to display the operator selbox
// For reminder : eq, gt, lt or dx (has changed)
//-------------------------------------------------------
function selOperator($selboxid,$opval){
global $trs;
echo "<SELECT ID=$selboxid CLASS=selope>\n";
echo "<OPTION VALUE='eq'";
if ($opval == "eq"){echo " SELECTED";}
echo "> = </OPTION>\n";
echo "<OPTION VALUE='gt'";
if ($opval == "gt"){echo " SELECTED";}
echo "> &gt; </OPTION>\n";
echo "<OPTION VALUE='lt'";
if ($opval == "lt"){echo " SELECTED";}
echo "> &lt; </OPTION>\n";
echo "<OPTION VALUE='dx'";
if ($opval == "dx"){echo " SELECTED";}
echo ">".$trs["op_dx"]."</OPTION>\n";
echo "</SELECT>\n";

echo "<SCRIPT>\$(\"#$selboxid\").selectmenu({width : 'auto'});</SCRIPT>\n";
} // selOperator

//-------------------------------------------------------
// Function to display the action method selbox
// For reminder : put, post, delete
//-------------------------------------------------------
function selMethod($selmethid,$methval){
echo "<SELECT ID=$selmethid CLASS=selmeth>\n";
echo "<OPTION VALUE='PUT'";
if ($methval == "PUT"){echo " SELECTED";}
echo ">PUT</OPTION>\n";
echo "<OPTION VALUE='POST'";
if ($methval == "POST"){echo " SELECTED";}
echo ">POST</OPTION>\n";
echo "<OPTION VALUE='DELETE'";
if ($methval == "DELETE"){echo " SELECTED";}
echo ">DELETE</OPTION>\n";
echo "</SELECT>\n";

echo "<SCRIPT>\$(\"#$selmethid\").selectmenu({width : 'auto'});</SCRIPT>\n";
} // selMethod

?>
6 changes: 3 additions & 3 deletions include/huecolor.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ function RGBToXy($RGB){
$b = $b / 255;

// Apply gamma correction
$r = ($r > 0.04055 ? pow(($r + 0.055) / 1.055, 2.4) : ($r / 12.92));
$g = ($g > 0.04055 ? pow(($g + 0.055) / 1.055, 2.4) : ($g / 12.92));
$b = ($b > 0.04055 ? pow(($b + 0.055) / 1.055, 2.4) : ($b / 12.92));
$r = ($r > 0.04045 ? pow(($r + 0.055) / 1.055, 2.4) : ($r / 12.92));
$g = ($g > 0.04045 ? pow(($g + 0.055) / 1.055, 2.4) : ($g / 12.92));
$b = ($b > 0.04045 ? pow(($b + 0.055) / 1.055, 2.4) : ($b / 12.92));

// Convert to XYZ
$X = $r * 0.649926 + $g * 0.103455 + $b * 0.197109;
Expand Down
15 changes: 10 additions & 5 deletions include/hueeffect.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
// <light /> or <group /> : set light/group id with attributes values
// <scene /> : call a scene by name
// <timer /> : set a timer for n.m second
// <getcolor /> : get light id color and save it under a name (in colormode format)
// <setcolor /> : put a saved color on a given light (default) or group id (+[transitiontime])
// <getcolor /> : get light id on+color and save it under a name (in colormode format)
// <setcolor /> : put a saved on+color on a given light (default) or group id (+[transitiontime])
//----------------------------------------------------
// F. Bardin 14/11/2015
// 11/07/2015 : add 'on' state to getcolor/setcolor
//====================================================
// Anti-hack
if (! defined('ANTI_HACK')){exit;}
Expand Down Expand Up @@ -347,7 +348,7 @@ private function processTimer(){
} // processTimer

//-------------------------------------------------------------
// Get color from a light and save it
// Get color and 'on' status from a light and save it
// Remark : color is get from colormode value (hs or xy or ct)
//-------------------------------------------------------------
private function getColor(){
Expand All @@ -374,6 +375,8 @@ private function getColor(){
$this->ha->loadInfo("lights");

$lstate = &$this->ha->info['lights'][$id]['state'];
if ($lstate['on'] == ""){$this->color[$name]['on'] = "false";}
else {$this->color[$name]['on'] = "true";}
$this->color[$name]['colormode'] = $lstate['colormode'];
$this->color[$name]['bri'] = $lstate['bri'];
switch ($lstate['colormode']){
Expand All @@ -391,7 +394,9 @@ private function getColor(){
}
if ($this->debug){
echo str_repeat($this->indent,$this->nodelvl);
echo $this->indent."<SPAN CLASS=effect-attribute>colormode</SPAN>=<SPAN CLASS=effect-value>";
echo $this->indent."<SPAN CLASS=effect-attribute>on</SPAN>=<SPAN CLASS=effect-value>";
echo $this->color[$name]['on']."</SPAN> ";
echo "<SPAN CLASS=effect-attribute>colormode</SPAN>=<SPAN CLASS=effect-value>";
echo $this->color[$name]['colormode']."</SPAN> ";
echo "<SPAN CLASS=effect-attribute>bri</SPAN>=<SPAN CLASS=effect-value>";
echo $this->color[$name]['bri']."</SPAN> ";
Expand Down Expand Up @@ -459,7 +464,7 @@ private function setColor(){
if ($type == "light") {$action = $type."s/$id/state";}
else {$action = $type."s/$id/action";}

$json = '{"bri" : '.$this->color[$name]['bri'].',';
$json = '{"on" : '.$this->color[$name]['on'].',"bri" : '.$this->color[$name]['bri'].',';
switch ($this->color[$name]['colormode']){
case "hs" :
$json .= '"hue" : '.$this->color[$name]['hue'].',';
Expand Down
Loading

0 comments on commit ec682ae

Please sign in to comment.