From 5b27f2fcb9f4d09fa4a824bcae403e23b63bab99 Mon Sep 17 00:00:00 2001 From: Paul <23568795+sktaylortrash@users.noreply.github.com> Date: Mon, 18 Dec 2017 14:39:11 -0600 Subject: [PATCH 01/16] Bulb Command referenced Room The bulb/light url generated had room specified as the type rather than device for the off and on commands --- queryBuilder.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/queryBuilder.php b/queryBuilder.php index 0c31a1e..26bc175 100644 --- a/queryBuilder.php +++ b/queryBuilder.php @@ -74,13 +74,13 @@ $('#command_on_2').html(roomName + " TCP light ON"); $('#command_on_3').html(roomName + " light on"); $('#command_on_response').html("Turning " + roomName + " light ON"); - $('#command_on_url').html( externalAddr + ( (externalPort != 80 || externalPort != 443) ? ':' + externalPort : '' ) + '/api.php?fx=toggle&type=room&uid=' + id + '&val=1' + ( requireExtPass == 1 ? '&password=' + externalPass : '') ); + $('#command_on_url').html( externalAddr + ( (externalPort != 80 || externalPort != 443) ? ':' + externalPort : '' ) + '/api.php?fx=toggle&type=device&uid=' + id + '&val=1' + ( requireExtPass == 1 ? '&password=' + externalPass : '') ); $('#command_off_1').html("TCP " + roomName + " light off"); $('#command_off_2').html(roomName + " TCP Light off"); $('#command_off_3').html(roomName + " light off"); $('#command_off_response').html("Turning off " + roomName + " light"); - $('#command_off_url').html( externalAddr + ( (externalPort != 80 || externalPort != 443) ? ':' + externalPort : '' ) + '/api.php?fx=toggle&type=room&uid=' + id + '&val=0' + ( requireExtPass == 1 ? '&password=' + externalPass : '') ); + $('#command_off_url').html( externalAddr + ( (externalPort != 80 || externalPort != 443) ? ':' + externalPort : '' ) + '/api.php?fx=toggle&type=device&uid=' + id + '&val=0' + ( requireExtPass == 1 ? '&password=' + externalPass : '') ); $('#command_dim_1').html("TCP " + roomName + " light to # % brightness"); $('#command_dim_2').html(roomName + " TCP light brightness # %"); From 3ec46d03c881fe5e83c6ed82086a083341fb100f Mon Sep 17 00:00:00 2001 From: Brendon Irwin Date: Mon, 18 Dec 2017 20:43:30 -0500 Subject: [PATCH 02/16] Scene Creation and Editting - Working! - no time implementation yet. --- index.php | 10 +++ scenescreatedit.php | 175 +++++++++++++++++++++++++++++++++----------- 2 files changed, 141 insertions(+), 44 deletions(-) diff --git a/index.php b/index.php index 8838708..68544ba 100644 --- a/index.php +++ b/index.php @@ -169,6 +169,16 @@ +
+
+

Create New

+

+
+ '; } echo ''; diff --git a/scenescreatedit.php b/scenescreatedit.php index b9598a0..0b9c88c 100644 --- a/scenescreatedit.php +++ b/scenescreatedit.php @@ -25,10 +25,81 @@ } - echo "SceneID: ".$sceneID." Action: ". $action; + //echo "SceneID: ".$sceneID." Action: ". $action; if( $action == "save"){ echo '
'.print_r($_POST,true).'
'; + + if( $sceneID == -1 ){ + //New Scene + $sceneID = "0"; // will populate with number + }else{ + //Updating a scene + $sceneID = ''.$sceneID.''; + } + + $icon = "images/scene/". $_POST['icon']; + $type = "manualcustom"; + $active = "1"; + $name = $_POST['name']; + + + $icon = htmlspecialchars($icon, ENT_XML1 | ENT_QUOTES, 'UTF-8'); + $name = htmlspecialchars($name, ENT_XML1 | ENT_QUOTES, 'UTF-8'); + + $deviceStr = ""; + + if( isset( $_POST['rooms'] ) && is_array($_POST['rooms'] ) ){ + foreach( $_POST['rooms'] as $room ){ + $deviceStr .= "".$room["rid"]."Rpower".$room["toggled"]."level".$room["value"].""; + } + } + + if( isset( $_POST['devices'] ) && is_array($_POST['devices'] ) ){ + foreach( $_POST['devices'] as $dev ){ + //if( $dev["toggled"] == 0 ) + $deviceStr .= "".$dev["did"]."Dpower".$dev["toggled"]."level".$dev["value"].""; + } + } + + + + $cmd = "cmd=SceneCreateEdit&data=1".TOKEN."".$sceneID."1"; + $cmd .= "".$name.""; + $cmd .= "".$type.""; + $cmd .= "1"; //unknown... + $cmd .= "".$icon.""; + $cmd .= $deviceStr; + $cmd.= ""; + + + + $result = getCurlReturn($cmd); + $array = xmlToArray($result); + + ob_clean(); + echo json_encode( array("success" => 1, "cmd" => $cmd, "scene" => $array["sid"], "fx" => $action, "resp" => $array) ); + + /* + if (this.every != null && this.every.length() > 0) { + dataString.append(String.format("%s", new Object[]{xmlEscape(this.every)})); + } + if (this.starttime != null && this.starttime.length() > 0) { + dataString.append(String.format("%s", new Object[]{xmlEscape(this.starttime)})); + } + if (this.stoptime != null && this.stoptime.length() > 0) { + dataString.append(String.format("%s", new Object[]{xmlEscape(this.stoptime)})); + } + if (this.masterid != null && this.masterid.length() > 0) { + dataString.append(String.format("%s", new Object[]{xmlEscape(this.masterid)})); + } + if (this.image != null && this.image.length() > 0) { + dataString.append(String.format("%s", new Object[]{xmlEscape(this.image)})); + } + + */ + + } if( $action == "delete"){ @@ -46,35 +117,7 @@ ?> @@ -264,6 +321,8 @@ for($x = 0; $x < sizeof($scenes); $x++){ if($scenes[$x]["sid"] == $scene ){ $foundScene = 1; + + //pa( $scenes[$x] ); ?>
"> @@ -279,9 +338,9 @@

- - - + + +

Scene ID:

@@ -308,13 +367,41 @@ } } - if( !isset( $scene ) || $foundScene == 0){ + if( !isset( $scene ) || $foundScene == 0 && $scene != -1){ echo "

Invalid Scene

You may have an invalid ID, or the Scene may have been deleted.

"; echo ''; pageFooter(); exit; } + + if( $scene == -1){ + ?> +

"> +

+

+ + +

+ +
+

Scene ID:

+

Scene Name:

+

Save Scene:

+ + +
+ + -
+

Keep in mind that the bridge uses UTC time. Based on your timezone, you should probably set the time to:

Set Time:
From 457ccceed4befc05c99490ec783594427e73434d Mon Sep 17 00:00:00 2001 From: Brendon Irwin Date: Thu, 21 Dec 2017 21:21:05 -0500 Subject: [PATCH 09/16] Added "button" identifier to lights if they have a remote associated with them. Added "getState" API call. --- api.php | 96 +++++++++++++++++++++++++++++++++++++++++++++++++-- css/style.css | 32 +++++++++++++++-- index.php | 5 ++- info.php | 4 +-- scheduler.php | 43 +++++++++-------------- 5 files changed, 146 insertions(+), 34 deletions(-) diff --git a/api.php b/api.php index 2476535..cedd846 100644 --- a/api.php +++ b/api.php @@ -449,9 +449,101 @@ function deviceOn($UID){ }else{ echo json_encode( array("error" => "No Scene mode specified") ); } + exit; + } + + if( $function == "getState" ){ - }else{ - echo json_encode( array("error" => "argument empty or invalid. Required: fx, type, UID, val", "recieved" => $_REQUEST) ); + $CMD = "cmd=GWRBatch&data=RoomGetCarousel1".TOKEN."name,image,imageurl,control,power,product,class,realtype,status&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; + + 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; + + }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; + } + } + } + } + + $thisRoom["devicesCount"] = sizeof( $thisRoom["devices"] ); + $thisRoom["brightness"] = (int)($thisRoom["brightness"] / $thisRoom["devicesCount"]); + + $ROOMS[] = $thisRoom; + } + } + + } + + $BRIDGE["rooms"] = $ROOMS; + $BRIDGE["roomCount"] = sizeof($ROOMS); + + + + header('Content-Type: application/json'); + echo json_encode( $BRIDGE ); + exit; } + + echo json_encode( array("error" => "argument empty or invalid. Required: fx, type, UID, val", "recieved" => $_REQUEST) ); + } ?> \ No newline at end of file diff --git a/css/style.css b/css/style.css index 9ce518a..35dda47 100644 --- a/css/style.css +++ b/css/style.css @@ -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{ @@ -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{ @@ -264,4 +265,31 @@ input:checked + .slider:before { border-radius: 50%; } -/*End Switch*/ \ No newline at end of file +/*End Switch*/ + +div.control-button{ + border: 1px solid #000; + border-radius: 2px; + background-color: #fff; + text-align: center; + width: 25px; + height: 25px; + line-height: 20px; + position: absolute; + right: 4px; + top: 4px; +} + +.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; +} + diff --git a/index.php b/index.php index 4bc99e8..901b74a 100644 --- a/index.php +++ b/index.php @@ -94,7 +94,10 @@ //state = on or off if( isset($device['offline']) && $device['offline'] == 1){ $unplugged++; } - + + if( isset($device["other"]) && isset( $device["other"]["rcgroup"] ) && $device["other"]["rcgroup"] != null ){ + echo '
'.$device["other"]["rcgroup"].'
'; + } echo '

'.$device['name'].'

'; echo '

|

'; diff --git a/info.php b/info.php index 9e5e67a..582341b 100644 --- a/info.php +++ b/info.php @@ -253,7 +253,7 @@ echo '
'; //power > 0 then enabled //level = brightness //state = on or off - echo '

'.$device['name'].'

'; + echo '

'.$device['name'].'

'; echo ' | '; echo '
'; echo '

Brightness:

'; @@ -267,7 +267,7 @@ echo '
'; ?> -
+
diff --git a/scheduler.php b/scheduler.php index 4529b3c..2e42dc5 100644 --- a/scheduler.php +++ b/scheduler.php @@ -1,13 +1,8 @@ -
"> @@ -341,9 +468,7 @@

- - - +

Scene ID:

@@ -353,15 +478,10 @@

Save Scene:

Delete Scene:

- - - - + " name="sceneID" id="sceneID" /> - -
">

@@ -408,70 +528,9 @@
- -
'; - - + echo '
'; } @@ -594,6 +652,113 @@ function renderRoom($r, $toggled){ echo '
'; } + ?> + +

Scene Schedule

+ + +
+ Use Schedule: +
+ +
+ +
+

Days:

+

+
+
+
+
+
+
+ + +

+

Start Time:

+
+ + +
+

Stop Time:

+ +
+ + + + +
+ +
+ +
+ RoomGetCarousel1".TOKEN."name,image,imageurl,control,power,product,class,realtype,status&fmt=xml"; $result = getCurlReturn($CMD); @@ -638,15 +803,9 @@ function renderRoom($r, $toggled){ } } ?> +
- -
-

Create Scene

-

Feature not built yet... sorry!

-
'; From 051745a7de6dfeb785f16846616ddd6782b61c1e Mon Sep 17 00:00:00 2001 From: Paul <23568795+sktaylortrash@users.noreply.github.com> Date: Sun, 31 Dec 2017 03:01:39 -0600 Subject: [PATCH 11/16] Setting a Val= on scene fails Setting a val of 0 or 1 on a scene call generates an error message --- queryBuilder.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/queryBuilder.php b/queryBuilder.php index 60610fc..520babe 100644 --- a/queryBuilder.php +++ b/queryBuilder.php @@ -130,21 +130,21 @@ $('#scene_command_on_3').html(sceneName + preface + " scene on"); $('#scene_command_on_response').html("Turning " + sceneName + preface + " devices ON"); - $('#scene_command_on_url').html( externalAddr + ( externalPort != 80 ? ':' + externalPort : '' ) + '/api.php?fx=scene&type=on&uid=' + id + '&val=1' + ( requireExtPass == 1 ? '&password=' + externalPass : '') ); + $('#scene_command_on_url').html( externalAddr + ( externalPort != 80 ? ':' + externalPort : '' ) + '/api.php?fx=scene&type=on&uid=' + id + '' + ( requireExtPass == 1 ? '&password=' + externalPass : '') ); $('#scene_command_off_1').html("Deactivate " + sceneName + preface + " scene"); $('#scene_command_off_2').html("Turn " + sceneName + preface + " scene off"); $('#scene_command_off_3').html(sceneName + preface + " scene off"); $('#scene_command_off_response').html("Turning " + sceneName + preface + " devices off"); - $('#scene_command_off_url').html( externalAddr + ( externalPort != 80 ? ':' + externalPort : '' ) + '/api.php?fx=scene&type=off&uid=' + id + '&val=0' + ( requireExtPass == 1 ? '&password=' + externalPass : '') ); + $('#scene_command_off_url').html( externalAddr + ( externalPort != 80 ? ':' + externalPort : '' ) + '/api.php?fx=scene&type=off&uid=' + id + '' + ( requireExtPass == 1 ? '&password=' + externalPass : '') ); $('#command_run_1').html("Activate " + sceneName + preface +" scene"); $('#command_run_2').html("Turn " + sceneName + preface + " scene on"); $('#command_run_3').html(sceneName + " scene on"); $('#command_run_response').html("Running " + preface + sceneName + " scene"); - $('#command_run_url').html( externalAddr + ( externalPort != 80 ? ':' + externalPort : '' ) + '/api.php?fx=scene&type=run&uid=' + id + '&val=' + ( requireExtPass == 1 ? '&password=' + externalPass : '') ); + $('#command_run_url').html( externalAddr + ( externalPort != 80 ? ':' + externalPort : '' ) + '/api.php?fx=scene&type=run&uid=' + id + '' + ( requireExtPass == 1 ? '&password=' + externalPass : '') ); } From 985f89eeffadddaa203e9b24a2a026317a8b8f89 Mon Sep 17 00:00:00 2001 From: Brendon Irwin Date: Sat, 6 Jan 2018 10:52:10 -0500 Subject: [PATCH 12/16] Bug Fix for scene code - not setting active by default on first save --- scenescreatedit.php | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/scenescreatedit.php b/scenescreatedit.php index 2618e68..1eaf48a 100644 --- a/scenescreatedit.php +++ b/scenescreatedit.php @@ -41,8 +41,8 @@ $icon = "images/scene/". $_POST['icon']; $type = "manualcustom"; - $active = $_POST["active"]; - $name = $_POST['name']; + $active = isset($_POST["active"]) ? $_POST["active"] : 1 ; + $name = isset($_POST['name']) ? $_POST['name'] : "New Scene"; $schedule = -1; $startTime = -1; $stopTime = -1; @@ -79,6 +79,7 @@ //exit; $cmd = "cmd=SceneCreateEdit&data=1".TOKEN."".$sceneID."".$active.""; + $cmd .= "".$name.""; $cmd .= "".$type.""; $cmd .= "1"; //unknown... @@ -240,14 +241,18 @@ } }); - $('#saveScene, #save2').click(function(event){ + + $('#saveScene').click(function(event){ + event.preventDefault(); + + console.log("here"); $('.switch-val-0 .switch input.device-toggle').each(function(){ $(this).attr('value', 0); //fix for non zeroed out switches }); /*To Do - In Progress*/ - event.preventDefault(); + var rooms = []; var devices = []; @@ -314,8 +319,9 @@ } }); - var sID = $('#sceneID').attr('value'); - var sName = $('#SceneName').attr('value'); + + var sID = $('#sceneID').val(); + var sName = $('#SceneName').val(); var icon = $('#sceneIcon option:selected').attr('value'); var enabled = $('input[name="sceneActive"]:checked').attr('value'); var schedule = 0; @@ -356,7 +362,6 @@ } - var scene = {action : "save", sceneID: sID, name: sName, icon: icon, rooms: rooms, devices: devices, active: enabled, schedule : schedule }; $.post( "scenescreatedit.php", scene ).done( function( data ){ @@ -368,6 +373,8 @@ if( sID != json.resp.sid && sID == -1){ window.location = "scenescreatedit.php?SID=" + json.resp.sid; + + console.log( json ); } }); @@ -376,6 +383,12 @@ }); + $('#save2').click(function(event){ + event.preventDefault(); + $('#saveScene').click(); + }); + + $('#deleteScene').click(function(event){ event.preventDefault(); var SID = $('#sceneID').attr('value'); From 3bcc27a33812e4d9837fde5cf8450f3029b0a61f Mon Sep 17 00:00:00 2001 From: Brendon Irwin Date: Sat, 6 Jan 2018 11:16:02 -0500 Subject: [PATCH 13/16] Disabled settings for scenes now represented in GUI --- index.php | 6 +++--- scenescreatedit.php | 12 +++++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/index.php b/index.php index 2780339..a9b4e01 100644 --- a/index.php +++ b/index.php @@ -165,9 +165,9 @@

" />

- - - + + +