Skip to content

Commit

Permalink
Merge pull request #1 from bren1818/master
Browse files Browse the repository at this point in the history
Rebase to master
  • Loading branch information
sktaylortrash authored May 31, 2018
2 parents 60599a9 + 9a5ddf2 commit 5382be7
Show file tree
Hide file tree
Showing 17 changed files with 853 additions and 309 deletions.
58 changes: 0 additions & 58 deletions API Notes.txt

This file was deleted.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Creating a local web interface to work with the 'Connected by TCP' bulbs.

Let me place this note at the top of the readme. Using this project in conjunction with IFTTT, webhooks and say a Google Home will allow you to control your lights again using voice commands. I will document the procedure step by step.

See the fleshed out Wiki: https://github.com/bren1818/TCPLightingWebInterface/wiki

The goal of this project is to re-create and improve upon the web interface which was used to control the Connected by TCP bulbs. The web interface was removed and the 'Connected by TCP' line was discontinued, leaving people with the bulbs out of luck, myself included.

After doing some reading, de-compiling the Android source code, reverse engineering and some time, I have put together this simple PHP web interface with a GUI that can be used to control the Connected by TCP bulbs. This interface should work with the latest bridge firmware, and the previous version of the firmware as well. All that needs to be done is modifying some strings in the include.php file. This can also be used with IFTTT via web hook commands issued to the API.php
Expand Down
Binary file removed Using this project with IFTTT.docx
Binary file not shown.
229 changes: 227 additions & 2 deletions api.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,234 @@ function deviceOn($UID){
}else{
echo json_encode( array("error" => "No Scene mode specified") );
}
exit;
}

$sceneDevices = array("rooms"=> array(), "devices" => array(), "count" => 0);
$sceneList = array();


if( $function == "getSceneState" || $function == "getState"){
if( $UID != "" || $function == "getState" ){

$CMD = "cmd=SceneGetListDetails&data=<gip><version>1</version><token>".TOKEN."</token><bigicon>1</bigicon></gip>";
$result = getCurlReturn($CMD);
$array = xmlToArray($result);
$scenes = $array["scene"];
if( is_array($scenes) ){
$sceneItemCount = 0;
for($x = 0; $x < sizeof($scenes); $x++){
$sceneList[] = array("id" => $scenes[$x]["sid"], "name" => $scenes[$x]["name"], "icon" => $scenes[$x]["icon"], "active" => $scenes[$x]["active"] );
if( $scenes[$x]["sid"] == $UID ){

//echo '<pre>'.print_r( $scenes[$x], true ).'</pre>';

if( isset( $scenes[$x]["device"]["id"] ) ){

$sceneItemCount = $sceneItemCount + 1;
//one item in scene

$item = $scenes[$x]["device"];
if( $item["type"] == "D" ){
$sceneDevices["devices"][] = $item["id"];
}elseif( $item["type"] == "R" ){
$sceneDevices["rooms"][] = $item["id"];
}


}elseif( is_array( $scenes[$x]["device"] ) ){
foreach( $scenes[$x]["device"] as $d ){
if( isset( $d["id"] ) ){

$sceneItemCount = $sceneItemCount + 1;
if( $d["type"] == "D" ){
$sceneDevices["devices"][] = $d["id"];
}elseif( $d["type"] == "R" ){
$sceneDevices["rooms"][] = $d["id"];
}

}
}
}

$sceneDevices["count"] = $sceneItemCount;
//echo '<pre>'.print_r( $sceneDevices, true ).'</pre>';
//exit;
}
}


}


}else{
echo json_encode( array("error" => "No Scene ID specified") );
}
}


if( $function == "getState" || $function == "getDeviceState" || $function == "getRoomState" || $function == "getSceneState" ){

}else{
echo json_encode( array("error" => "argument empty or invalid. Required: fx, type, UID, val", "recieved" => $_REQUEST) );
$sceneDeviceObjectsON = 0;

$CMD = "cmd=GWRBatch&data=<gwrcmds><gwrcmd><gcmd>RoomGetCarousel</gcmd><gdata><gip><version>1</version><token>".TOKEN."</token><fields>name,image,imageurl,control,power,product,class,realtype,status</fields></gip></gdata></gwrcmd></gwrcmds>&fmt=xml";
$result = getCurlReturn($CMD);
$array = xmlToArray($result);
if( !isset($array["gwrcmd"]) ){
exit;
}

$DEVICES = array();
if( isset( $array["gwrcmd"]["gdata"]["gip"]["room"] ) ){
$DATA = $array["gwrcmd"]["gdata"]["gip"]["room"];
}else{
exit;
}
$ROOMS = array();
$BRIDGE = array();
if( sizeof($DATA) > 0 ){
if ( isset( $DATA["rid"] ) ){ $DATA = array( $DATA ); }


foreach($DATA as $room){
$thisRoom = array();


if( isset($room['rid'] ) ){
$thisRoom["room_id"] = $room['rid'];
$thisRoom["name"] = $room['name'];
$thisRoom["color"] = $room['color'];
$thisRoom["colorid"] = $room['colorid'];
$thisRoom["brightness"] = 0;
//$thisRoom["data"] = $room;
$thisRoom["state"] = 0;




if( ! is_array($room["device"]) ){

}else{

$device = (array)$room["device"];
if( isset($device["did"]) ){
$rd = array();
$rd["id"] = $device["did"];
$rd["name"] = $device["name"];
$rd["level"] = ($device["level"] != null ? (int)$device["level"] : 0);
$rd["state"] = $device["state"];
$rd["online"] = (isset($device['offline']) && $device['offline'] == 1) ? 1 : 0;
if( isset($device["other"]) && isset( $device["other"]["rcgroup"] ) && $device["other"]["rcgroup"] != null ){
$rd["buttonNum"] = $device["other"]["rcgroup"];
}
$thisRoom["brightness"] += $rd["level"];
$thisRoom["devices"][] = $rd;

if( $device["state"] > 0 ){
$thisRoom["state"] = (int)$thisRoom["state"] + 1;
}

//

if( $function == "getSceneState" && in_array( $rd["id"], $sceneDevices["devices"] ) && $rd["state"] > 0 ){
$sceneDeviceObjectsON++;
}


if( $function == "getDeviceState" && $UID == $device["did"] ){
ob_clean();
echo trim($device["state"]);
exit;
}

}else{
for( $x = 0; $x < sizeof($device); $x++ ){
if( isset($device[$x]) && is_array($device[$x]) && ! empty($device[$x]) ){
$rd = array();

$rd["id"] = $device[$x]["did"];
$rd["name"] = $device[$x]["name"];
$rd["level"] = ( $device[$x]["level"] != null ? (int)$device[$x]["level"] : 0);
$rd["state"] = $device[$x]["state"];
$rd["online"] = (isset($device[$x]['offline']) && $device[$x]['offline'] == 1) ? 1 : 0;
if( isset($device[$x]["other"]) && isset( $device[$x]["other"]["rcgroup"] ) && $device[$x]["other"]["rcgroup"] != null ){
$rd["buttonNum"] = $device[$x]["other"]["rcgroup"];
}

$thisRoom["brightness"]+= $rd["level"];
$thisRoom["devices"][] = $rd;

if( $device[$x]["state"] > 0 ){
$thisRoom["state"] = (int)$thisRoom["state"] + 1;
}

//

if( $function == "getSceneState" && in_array( $rd["id"], $sceneDevices["devices"] ) && $rd["state"] > 0 ){
$sceneDeviceObjectsON++;
}


if( $function == "getDeviceState" && $UID == $device[$x]["did"] ){
ob_clean();
echo trim($device[$x]["state"]);
exit;
}

}
}
}
}


if( $function == "getRoomState" && $UID == $room['rid'] ){
ob_clean();
echo ( $thisRoom["state"] > 0 ) ? 1 : 0;
exit;
}

if( $function == "getSceneState" && in_array( $room['rid'], $sceneDevices["rooms"] ) && $thisRoom["state"] > 0 ){
$sceneDeviceObjectsON++;
}


$thisRoom["devicesCount"] = sizeof( $thisRoom["devices"] );
$thisRoom["brightness"] = (int)($thisRoom["brightness"] / $thisRoom["devicesCount"]);
$thisRoom["state"] = ( $thisRoom["state"] > 0 ) ? ( $thisRoom["state"] / sizeof( $thisRoom["devices"] ) ) : 0;

$ROOMS[] = $thisRoom;
}
}

}

$BRIDGE["rooms"] = $ROOMS;
$BRIDGE["roomCount"] = sizeof($ROOMS);
$BRIDGE["scenes"] = $sceneList;
$BRIDGE["sceneCount"] = sizeof( $sceneList );


if( $function == "getState" ){
header('Content-Type: application/json');
echo json_encode( $BRIDGE );
exit;
}elseif( $function == "getSceneState" ){

if( $sceneDeviceObjectsON == 0){
echo 0;
}elseif( $sceneDeviceObjectsON == $sceneDevices["count"] ){
echo 1;
}else{
echo $sceneDeviceObjectsON / $sceneDevices["count"];
}
exit;
}else{
echo '-1';
exit;
}
}

echo json_encode( array("error" => "argument empty or invalid. Required: fx, type, UID, val", "recieved" => $_REQUEST) );

}
?>
2 changes: 1 addition & 1 deletion createDevice.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function SelectMoveRows(SS1,SS2){
<option value="3">Button 3</option>
<option value="4">Button 4</option>
</select><br />
<img id="remote" style="display: none;" src="<?php echo LOCAL_URL; ?>/images/remote.png" />
<img id="remote" style="display: none;" src="css/images/remote.png" />
</label><br />

<table>
Expand Down
Binary file added css/images/Ui-icons_222222_256x240.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added css/images/ui-icons_454545_256x240.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 31 additions & 2 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ a.info{ display: block; height: 30px; line-height: 30px; width: 30px; float: rig
float: left;
border: 1px solid #000;
background-position-x: center;
position: relative;
}

.room-controls{
Expand Down Expand Up @@ -154,7 +155,7 @@ a.info{ display: block; height: 30px; line-height: 30px; width: 30px; float: rig
.unplugged .device-slider,
.unplugged button{ display: none; }

.unplugged p.device-name{ display: block; background-color: rgba(255,255,255,.7); padding: 20px; }
.unplugged p.device-name{ display: block; background-color: rgba(255,255,255,.7); padding: 10px; }

.home-controls,
.home-devices{
Expand Down Expand Up @@ -264,4 +265,32 @@ input:checked + .slider:before {
border-radius: 50%;
}

/*End Switch*/
/*End Switch*/

div.control-button{
border: 1px solid #999;
border-radius: 4px;
background-color: #fff;
text-align: center;
width: 25px;
height: 25px;
line-height: 20px;
position: absolute;
right: 4px;
top: 4px;
font-size: 12px;
}

.device.unplugged div.control-button::after,
.device.plugged div.control-button::after{
content: '•';
color: #0f0;
position: relative;
bottom: -7px;
left: 2px;
}

.device.unplugged div.control-button::after{
color: #f00;
}

Loading

0 comments on commit 5382be7

Please sign in to comment.