Allow hue lamp to specify IP manually...

for those cases where discovery doesn't...
This commit is contained in:
dceejay 2015-01-29 16:41:06 +00:00
parent 102c4b4d6c
commit 0a5b184dad
2 changed files with 83 additions and 65 deletions

View File

@ -17,6 +17,7 @@
--> -->
<script type="text/x-red" data-template-name="HueNode"> <script type="text/x-red" data-template-name="HueNode">
<div class="form-row"> <div class="form-row">
<label for="node-input-topic"><i class="fa fa-tasks"></i>Hue App Username:</label> <label for="node-input-topic"><i class="fa fa-tasks"></i>Hue App Username:</label>
<input type="text" id="node-input-username" placeholder="username"> <input type="text" id="node-input-username" placeholder="username">
@ -28,7 +29,12 @@
</div> </div>
<div class="form-row"> <div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i>Lamp Status:</label> <label for="node-input-ip_address"><i class="fa fa-tag"></i>Hue Bridge IP Address:</label>
<input type="text" id="node-input-ip_address" placeholder="IP Address (optional)">
</div>
<div class="form-row">
<label for="node-input-lamp_status"><i class="fa fa-tag"></i>Lamp Status:</label>
<select id="node-input-lamp_status" placeholder="lamp_status"> <select id="node-input-lamp_status" placeholder="lamp_status">
<option value="AUTO">AUTO</option> <option value="AUTO">AUTO</option>
<option value="ON">ON</option> <option value="ON">ON</option>
@ -65,6 +71,8 @@
</ul> </ul>
<p>Please note, by setting the status to AUTO on the node configuration, the rest of the node parameters are ignored, you need to set all parameters through the message input.</p> <p>Please note, by setting the status to AUTO on the node configuration, the rest of the node parameters are ignored, you need to set all parameters through the message input.</p>
<p>By default, the node will search for Philips Hue Bridges. However, by specifying an IP address, you can find Hue systems when this may not be possible due to network configuration.
</p>
</script> </script>
<!-- Finally, the node type is registered along with all of its properties --> <!-- Finally, the node type is registered along with all of its properties -->
@ -77,6 +85,7 @@
username: {value:"", required:true}, username: {value:"", required:true},
discovery_mode: {value: "", required:false}, discovery_mode: {value: "", required:false},
lamp_id: {value:"", required:false}, lamp_id: {value:"", required:false},
ip_address: {value:"", required:false},
color: {value:"EBF5FF"}, color: {value:"EBF5FF"},
brightness: {value:"100"}, brightness: {value:"100"},
lamp_status:{} lamp_status:{}

View File

@ -41,47 +41,13 @@ function hexToRgb(hex) {
} : null; } : null;
} }
function setLights(node, myMsg) {
// The main node definition - most things happen in here
function HueNode(n) {
// Create a RED node
RED.nodes.createNode(this,n);
var node = this;
//get parameters from user
this.username = n.username;
this.lamp_status = n.lamp_status;
this.lamp_id = n.lamp_id;
this.color = n.color;
this.brightness = n.brightness;
// Store local copies of the node configuration (as defined in the .html)
this.topic = n.topic;
var msg = {};
msg.topic = this.topic;
this.on("input", function(msg){
var myMsg = msg;
//set the lamp status
//first locate the Hue gateway:
hue.locateBridges(function(err, result) {
var msg2 = {}; var msg2 = {};
msg2.topic = this.topic; msg2.topic = this.topic;
if (err) throw err;
//check for found bridges
if(result[0]!=null) {
//save the IP address of the 1st bridge found
this.gw_ipaddress = result[0].ipaddress;
//set light status //set light status
var api = new HueApi(this.gw_ipaddress, node.username); var api = new HueApi(node.gw_ipaddress, node.username);
var lightState = hue.lightState; var lightState = hue.lightState;
var state = lightState.create(); var state = lightState.create();
@ -137,6 +103,48 @@ function HueNode(n) {
msg2.payload = 'Light with ID: '+node.lamp_id+ ' was set to '+node.lamp_status; msg2.payload = 'Light with ID: '+node.lamp_id+ ' was set to '+node.lamp_status;
node.send(msg2); node.send(msg2);
} }
// The main node definition - most things happen in here
function HueNode(n) {
// Create a RED node
RED.nodes.createNode(this,n);
var node = this;
//get parameters from user
this.username = n.username;
this.lamp_status = n.lamp_status;
this.lamp_id = n.lamp_id;
this.gw_ipaddress = n.ip_address;
this.color = n.color;
this.brightness = n.brightness;
// Store local copies of the node configuration (as defined in the .html)
this.topic = n.topic;
var msg = {};
msg.topic = this.topic;
this.on("input", function(msg){
var myMsg = msg;
//set the lamp status
if (this.gw_ipaddress) {
setLights(node, myMsg);
} else {
//first locate the Hue gateway:
hue.locateBridges(function(err, result) {
if (err) throw err;
//check for found bridges
if(result[0]!=null) {
//save the IP address of the 1st bridge found
this.gw_ipaddress = result[0].ipaddress;
setLights(node, myMsg);
}
else { else {
//bridge not found: //bridge not found:
var msg = {}; var msg = {};
@ -145,6 +153,7 @@ function HueNode(n) {
} }
}); });
}
}); });