mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
remove old hue node and update README
(there is a better node-red-contrib-hue node on npm)
This commit is contained in:
parent
f4973cf189
commit
dd79a64de9
33
README.md
33
README.md
@ -4,13 +4,13 @@ A collection of nodes for [Node-RED](http://nodered.org). See below for a list.
|
|||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
Most of these nodes are available as npm packages. See the list below for the npm p
|
Most of these nodes are available as npm packages. See the list below for the
|
||||||
ackage names, or [search npm](https://www.npmjs.org/search?q=node-red-node-).
|
npm package names, or [search npm](https://www.npmjs.org/search?q=node-red-node-).
|
||||||
|
|
||||||
To install
|
To install - change to your Node-RED user directory.
|
||||||
|
|
||||||
cd node-red
|
cd ~/.node-red
|
||||||
npm install node-red-node-{*filename*}
|
npm install node-red-node-{filename}
|
||||||
|
|
||||||
This repository acts as an overall store for these nodes - and is no longer
|
This repository acts as an overall store for these nodes - and is no longer
|
||||||
intended as a way to install them - unless you really do want some bloat.
|
intended as a way to install them - unless you really do want some bloat.
|
||||||
@ -19,15 +19,15 @@ To manually install using this repo:
|
|||||||
|
|
||||||
1. cd into the `nodes` directory of Node-RED
|
1. cd into the `nodes` directory of Node-RED
|
||||||
2. Either:
|
2. Either:
|
||||||
- download the zip of the repository and extract it
|
- download the zip of the repository and extract it
|
||||||
- run `git clone https://github.com/node-red/node-red-nodes.git`
|
- run `git clone https://github.com/node-red/node-red-nodes.git`
|
||||||
3. npm install in any of the node subfolders to install individual node's dependencies
|
3. run `npm install` in any of the node subfolders to install individual node's dependencies
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
Now that we support npm installaton of nodes we recommend people post their own
|
Now that we support npm installaton of nodes we recommend people post their own
|
||||||
via [npm](https://www.npmjs.org/). Please read
|
nodes via [npm](https://www.npmjs.org/). Please read the
|
||||||
the [packaging guide notes](http://nodered.org/docs/creating-nodes/packaging.html).
|
[packaging guide notes](http://nodered.org/docs/creating-nodes/packaging.html).
|
||||||
|
|
||||||
If you are an IBMer, please contact us directly as the contribution process
|
If you are an IBMer, please contact us directly as the contribution process
|
||||||
is slightly different.
|
is slightly different.
|
||||||
@ -37,14 +37,13 @@ our mistakes. If you need to raise a pull request please read our
|
|||||||
[contribution guidelines](https://github.com/node-red/node-red/blob/master/CONTRIBUTING.md)
|
[contribution guidelines](https://github.com/node-red/node-red/blob/master/CONTRIBUTING.md)
|
||||||
before doing so.
|
before doing so.
|
||||||
|
|
||||||
|
|
||||||
## Copyright and license
|
## Copyright and license
|
||||||
|
|
||||||
Copyright 2013,2015 IBM Corp. under [the Apache 2.0 license](LICENSE).
|
Copyright 2013, 2015 IBM Corp. under [the Apache 2.0 license](LICENSE).
|
||||||
|
|
||||||
# Extra Node Information
|
# Extra Node Information
|
||||||
|
|
||||||
NPM name - File-link - Description
|
**NPM name** - *File-link* - Description
|
||||||
|
|
||||||
### Analysis
|
### Analysis
|
||||||
|
|
||||||
@ -90,11 +89,7 @@ NPM name - File-link - Description
|
|||||||
|
|
||||||
**N/A** - *[101-scanBLE](hardware/scanBLE)* - Scans for a particular Bluetooth Low Energy (BLE) device.
|
**N/A** - *[101-scanBLE](hardware/scanBLE)* - Scans for a particular Bluetooth Low Energy (BLE) device.
|
||||||
|
|
||||||
**N/A** - *[103-hue_discover](hardware/hue)* - Looks for a Philips Hue Bridge in the local network.
|
### I/O
|
||||||
|
|
||||||
**N/A** - *[104-hue_manage](hardware/hue)* - Implements some basic functionality for managing a Philips Hue wireless Lamp system.
|
|
||||||
|
|
||||||
### IO
|
|
||||||
|
|
||||||
**node-red-node-stomp** - *[18-stomp](io/stomp)* - A Node-RED node to publish and subscribe to and from a [STOMP server](https://stomp.github.io/implementations.html#STOMP_Servers).
|
**node-red-node-stomp** - *[18-stomp](io/stomp)* - A Node-RED node to publish and subscribe to and from a [STOMP server](https://stomp.github.io/implementations.html#STOMP_Servers).
|
||||||
|
|
||||||
@ -156,8 +151,6 @@ NPM name - File-link - Description
|
|||||||
|
|
||||||
**node-red-node-daemon** - *[daemon](utility/daemon)* - starts up (calls) a long running system program and pipes STDIN, STDOUT and STDERR to and from that process. Good for monitoring long running command line applications,
|
**node-red-node-daemon** - *[daemon](utility/daemon)* - starts up (calls) a long running system program and pipes STDIN, STDOUT and STDERR to and from that process. Good for monitoring long running command line applications,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Misc
|
### Misc
|
||||||
|
|
||||||
**N/A** - *[99-sample](./)* - A sample node with more comments than most to try to help you get started without any other docs...
|
**N/A** - *[99-sample](./)* - A sample node with more comments than most to try to help you get started without any other docs...
|
||||||
|
@ -1,54 +0,0 @@
|
|||||||
<!--
|
|
||||||
Copyright 2013 Charalampos Doukas.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
|
|
||||||
|
|
||||||
-->
|
|
||||||
|
|
||||||
<script type="text/x-red" data-template-name="Discover">
|
|
||||||
<div class="form-row">
|
|
||||||
<label for="node-input-username"><i class="fa fa-tag"></i> Username:</label>
|
|
||||||
<input type="text" id="node-input-username" placeholder="username">
|
|
||||||
</div>
|
|
||||||
<div class="form-row">
|
|
||||||
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
||||||
<input type="text" id="node-input-name" placeholder="Name">
|
|
||||||
</div>
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<!-- Next, some simple help text is provided for the node. -->
|
|
||||||
<script type="text/x-red" data-help-name="Discover">
|
|
||||||
<p>This node looks for a Philips Hue Bridge in the local network.</p><p> The node has 2 outputs, the first one contains the IP address of the first discovered bridge and the second one the lights registered to that bridge (in JSON format).</p> <p>To use the node you need to have obtained a valid auth token (or username) from your Philips Hue Bridge. Read <a href="http://developers.meethue.com/gettingstarted.html" target="_blank">here</a> on how to do this.</p>
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<!-- Finally, the node type is registered along with all of its properties -->
|
|
||||||
<script type="text/javascript">
|
|
||||||
RED.nodes.registerType('Discover',{
|
|
||||||
category: 'advanced-input', // the palette category
|
|
||||||
color:"#EFEFEF",
|
|
||||||
defaults: { // defines the editable properties of the node
|
|
||||||
name: {value:""}, // along with default values.
|
|
||||||
username: {value:"", required:true}
|
|
||||||
},
|
|
||||||
inputs:1, // set the number of inputs - only 0 or 1
|
|
||||||
outputs:2, // set the number of outputs - 0 to n
|
|
||||||
icon: "huediscover.png", // set the icon (held in public/icons)
|
|
||||||
label: function() { // sets the default label contents
|
|
||||||
return this.name||this.topic||"Discover";
|
|
||||||
},
|
|
||||||
labelStyle: function() { // sets the class to apply to the label
|
|
||||||
return this.name?"node_label_italic":"";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
|
@ -1,104 +0,0 @@
|
|||||||
/**
|
|
||||||
* philips_hue.js
|
|
||||||
* Basic functionality for accessing a Philips Hue wireless Lamp
|
|
||||||
* Allows for bridge/gateway detection and light scanning.
|
|
||||||
* Requires node-hue-api https://github.com/peter-murray/node-hue-api
|
|
||||||
* Copyright 2013 Charalampos Doukas - @BuildingIoT
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
**/
|
|
||||||
|
|
||||||
|
|
||||||
//Require node-hue-api
|
|
||||||
var hue = require("node-hue-api");
|
|
||||||
var HueApi = require("node-hue-api").HueApi;
|
|
||||||
|
|
||||||
// Require main module
|
|
||||||
var RED = require(process.env.NODE_RED_HOME+"/red/red");
|
|
||||||
|
|
||||||
//store the IP address of the Hue Gateway
|
|
||||||
var gw_ipaddress = "";
|
|
||||||
|
|
||||||
var username;
|
|
||||||
|
|
||||||
// The main node definition - most things happen in here
|
|
||||||
function HueNodeDiscovery(n) {
|
|
||||||
// Create a RED node
|
|
||||||
RED.nodes.createNode(this,n);
|
|
||||||
|
|
||||||
var node = this;
|
|
||||||
|
|
||||||
//get username from user input
|
|
||||||
this.username = n.username;
|
|
||||||
|
|
||||||
|
|
||||||
// Store local copies of the node configuration (as defined in the .html)
|
|
||||||
this.topic = n.topic;
|
|
||||||
|
|
||||||
this.on("input", function(msg){
|
|
||||||
|
|
||||||
//start with detecting the IP address of the Hue gateway in the local network:
|
|
||||||
hue.locateBridges(function(err, result) {
|
|
||||||
var msg = {};
|
|
||||||
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;
|
|
||||||
msg.payload = this.gw_ipaddress;
|
|
||||||
|
|
||||||
//get light info:
|
|
||||||
var api = new HueApi(this.gw_ipaddress, node.username);
|
|
||||||
api.lights(function(err, lights) {
|
|
||||||
var msg2 = {};
|
|
||||||
if (err) { throw err; }
|
|
||||||
var lights_discovered = JSON.stringify(lights, null, 2);
|
|
||||||
msg2.topic = "Lights";
|
|
||||||
msg2.payload = lights_discovered;
|
|
||||||
node.send([msg, msg2]);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
//bridge not found:
|
|
||||||
msg = {};
|
|
||||||
msg.payload = "Bridge not found!";
|
|
||||||
node.send(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
this.on("close", function() {
|
|
||||||
// Called when the node is shutdown - eg on redeploy.
|
|
||||||
// Allows ports to be closed, connections dropped etc.
|
|
||||||
// eg: this.client.disconnect();
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//hue debugging on the output:
|
|
||||||
var displayResult = function(result) {
|
|
||||||
console.log(result);
|
|
||||||
};
|
|
||||||
|
|
||||||
var displayError = function(err) {
|
|
||||||
console.error(err);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Register the node by name. This must be called before overriding any of the
|
|
||||||
// Node functions.
|
|
||||||
RED.nodes.registerType("Discover",HueNodeDiscovery);
|
|
@ -1,103 +0,0 @@
|
|||||||
<!--
|
|
||||||
Copyright 2013 Charalampos Doukas.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
|
|
||||||
|
|
||||||
-->
|
|
||||||
|
|
||||||
<script type="text/x-red" data-template-name="HueNode">
|
|
||||||
|
|
||||||
<div class="form-row">
|
|
||||||
<label for="node-input-topic"><i class="fa fa-tasks"></i>Hue App Username:</label>
|
|
||||||
<input type="text" id="node-input-username" placeholder="username">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-row">
|
|
||||||
<label for="node-input-name"><i class="fa fa-tag"></i>Lamp ID:</label>
|
|
||||||
<input type="text" id="node-input-lamp_id" placeholder="lamp_id">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-row">
|
|
||||||
<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">
|
|
||||||
<option value="AUTO">AUTO</option>
|
|
||||||
<option value="ON">ON</option>
|
|
||||||
<option value="OFF">OFF</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-row">
|
|
||||||
<label for="node-input-brightness"><i class="fa fa-tag"></i>Change Brightness (0->100):</label>
|
|
||||||
<input type="text" id="node-input-brightness" placeholder="brightness">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-row">
|
|
||||||
<label for="node-input-color"><i class="fa fa-tag"></i>Select color:</label>
|
|
||||||
<input type="text" id="node-input-color" placeholder="color">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-row">
|
|
||||||
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
||||||
<input type="text" id="node-input-name" placeholder="Name">
|
|
||||||
</div>
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<!-- Next, some simple help text is provided for the node. -->
|
|
||||||
<script type="text/x-red" data-help-name="HueNode">
|
|
||||||
<p>This node implements some basic functionality for managing a Philips Hue wireless Lamp system.</p>
|
|
||||||
<p>To use it you need to have obtained a valid auth token (or username) from your Philips Hue Bridge. Read <a href="http://developers.meethue.com/gettingstarted.html" target="_blank">here</a> on how to do this.</p>
|
|
||||||
<p>You can enter the ID (1, 2, ...) of a Lamp and turn it ON or OFF, set the color and the brightness (0->100). </p><p>By setting the status to AUTO, you can set the lamp parameters using the message on the input node as follows:</p>
|
|
||||||
<ul>
|
|
||||||
<li>msg.lamp sets the lamp ID</li>
|
|
||||||
<li>msg.color sets the lamp color (e.g., msg.color="DF0101" will set the color to red)</li>
|
|
||||||
<li>msg.brightness sets the lamp brightness (e.g., msg.brightness=50)</li>
|
|
||||||
<li>msg.payload is used to se the lamp status (on/off/alert) (e.g., msg.payload="alert" will flash the Lamp once</li>
|
|
||||||
</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>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>
|
|
||||||
|
|
||||||
<!-- Finally, the node type is registered along with all of its properties -->
|
|
||||||
<script type="text/javascript">
|
|
||||||
RED.nodes.registerType('HueNode',{
|
|
||||||
category: 'advanced-input', // the palette category
|
|
||||||
color:"#EFEFEF",
|
|
||||||
defaults: { // defines the editable properties of the node
|
|
||||||
name: {value:""}, // along with default values.
|
|
||||||
username: {value:"", required:true},
|
|
||||||
discovery_mode: {value: "", required:false},
|
|
||||||
lamp_id: {value:"", required:false},
|
|
||||||
ip_address: {value:"", required:false},
|
|
||||||
color: {value:"EBF5FF"},
|
|
||||||
brightness: {value:"100"},
|
|
||||||
lamp_status:{}
|
|
||||||
},
|
|
||||||
inputs:1, // set the number of inputs - only 0 or 1
|
|
||||||
outputs:1, // set the number of outputs - 0 to n
|
|
||||||
icon: "huemanage.png", // set the icon (held in public/icons)
|
|
||||||
label: function() { // sets the default label contents
|
|
||||||
return this.name||this.topic||"HueNode";
|
|
||||||
},
|
|
||||||
labelStyle: function() { // sets the class to apply to the label
|
|
||||||
return this.name?"node_label_italic":"";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
|
@ -1,184 +0,0 @@
|
|||||||
/**
|
|
||||||
* philips_hue.js
|
|
||||||
* Basic functionality for accessing and contolling a Philips Hue wireless Lamp
|
|
||||||
* Allows for bridge/gateway and light scanning, as well as Light ON/OFF/ALERT status update
|
|
||||||
* Requires node-hue-api https://github.com/peter-murray/node-hue-api
|
|
||||||
* Copyright 2013 Charalampos Doukas - @BuildingIoT
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
**/
|
|
||||||
|
|
||||||
|
|
||||||
//Require node-hue-api
|
|
||||||
var hue = require("node-hue-api");
|
|
||||||
var HueApi = require("node-hue-api").HueApi;
|
|
||||||
|
|
||||||
// Require main module
|
|
||||||
var RED = require(process.env.NODE_RED_HOME+"/red/red");
|
|
||||||
|
|
||||||
//store the IP address of the Hue Gateway
|
|
||||||
var gw_ipaddress = "";
|
|
||||||
|
|
||||||
|
|
||||||
var username, lamp_status, lamp_id, color, brightness;
|
|
||||||
|
|
||||||
function hexToRgb(hex) {
|
|
||||||
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
||||||
return result ? {
|
|
||||||
r: parseInt(result[1], 16),
|
|
||||||
g: parseInt(result[2], 16),
|
|
||||||
b: parseInt(result[3], 16)
|
|
||||||
} : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function setLights(node, myMsg) {
|
|
||||||
|
|
||||||
var msg2 = {};
|
|
||||||
msg2.topic = this.topic;
|
|
||||||
|
|
||||||
//set light status
|
|
||||||
var api = new HueApi(node.gw_ipaddress, node.username);
|
|
||||||
var lightState = hue.lightState;
|
|
||||||
var state = lightState.create();
|
|
||||||
|
|
||||||
var status;
|
|
||||||
var lamp = -1;
|
|
||||||
|
|
||||||
//check for AUTO status (lamp settings set through node input)
|
|
||||||
if(node.lamp_status=="AUTO") {
|
|
||||||
var color;
|
|
||||||
var brightness;
|
|
||||||
|
|
||||||
//get lamp id from msg.lamp:
|
|
||||||
lamp = myMsg.lamp;
|
|
||||||
|
|
||||||
//get brightness:
|
|
||||||
brightness = myMsg.brightness;
|
|
||||||
|
|
||||||
//get colour either from msg.color or msg.topic
|
|
||||||
if(myMsg.color!=null && myMsg.color.length>0) {
|
|
||||||
color = myMsg.color;
|
|
||||||
}
|
|
||||||
else if(myMsg.topic!=null && myMsg.topic.length>0) {
|
|
||||||
color = myMsg.topic;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//check the payload for on/off/alert:
|
|
||||||
//case of ALERT:
|
|
||||||
if(myMsg.payload=="ALERT" || myMsg.payload=="alert"){
|
|
||||||
api.setLightState(lamp, state.alert()).then(displayResult).fail(displayError).done();
|
|
||||||
}
|
|
||||||
|
|
||||||
//case of ON:
|
|
||||||
if(myMsg.payload=="ON" || myMsg.payload=="on") {
|
|
||||||
api.setLightState(lamp, state.on().rgb(hexToRgb(color).r,hexToRgb(color).g,hexToRgb(color).b).brightness(brightness)).then(displayResult).fail(displayError).done();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
api.setLightState(lamp, state.off()).then(displayResult).fail(displayError).done();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
//set lamp according to node settings
|
|
||||||
if(node.lamp_status=="ON") {
|
|
||||||
api.setLightState(node.lamp_id, state.on().rgb(hexToRgb(node.color).r,hexToRgb(node.color).g,hexToRgb(node.color).b).brightness(node.brightness)).then(displayResult).fail(displayError).done();
|
|
||||||
} else {
|
|
||||||
api.setLightState(node.lamp_id, state.off()).then(displayResult).fail(displayError).done();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(lamp!=-1) {
|
|
||||||
msg2.payload = 'Light with ID: '+lamp+ ' was set to '+myMsg.payload;
|
|
||||||
} else {
|
|
||||||
msg2.payload = 'Light with ID: '+node.lamp_id+ ' was set to '+node.lamp_status;
|
|
||||||
}
|
|
||||||
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 {
|
|
||||||
//bridge not found:
|
|
||||||
var msg = {};
|
|
||||||
msg.payload = "Bridge not found!";
|
|
||||||
node.send(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
this.on("close", function() {
|
|
||||||
// Called when the node is shutdown - eg on redeploy.
|
|
||||||
// Allows ports to be closed, connections dropped etc.
|
|
||||||
// eg: this.client.disconnect();
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//hue debugging on the output:
|
|
||||||
var displayResult = function(result) {
|
|
||||||
console.log(result);
|
|
||||||
};
|
|
||||||
|
|
||||||
var displayError = function(err) {
|
|
||||||
console.error(err);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Register the node by name. This must be called before overriding any of the
|
|
||||||
// Node functions.
|
|
||||||
RED.nodes.registerType("HueNode",HueNode);
|
|
Binary file not shown.
Before Width: | Height: | Size: 8.7 KiB |
Loading…
Reference in New Issue
Block a user