mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Merge branch 'master' of https://github.com/node-red/node-red-nodes
This commit is contained in:
commit
a32e87ff96
@ -67,6 +67,10 @@ Copyright 2013 IBM Corp. under [the Apache 2.0 license](LICENSE).
|
||||
|
||||
**79-sensorTag** - Reads data from the Ti BLE SensorTag device.
|
||||
|
||||
**100-heatmiser-in** - Writes settings for temperature and frost protection to Heatmiser thermostats.
|
||||
|
||||
**101-heatmiser-out** - Reads settings from Heatmiser thermostats at a polling interval.
|
||||
|
||||
**101-scanBLE** - Scans for a particular Bluetooth Low Energy (BLE) device.
|
||||
|
||||
**145-BBB-hardware** - A collection of analogue & digital input & output nodes for the Beaglebone Black
|
||||
|
62
hardware/heatmiser-in/100-heatmiser-in.html
Normal file
62
hardware/heatmiser-in/100-heatmiser-in.html
Normal file
@ -0,0 +1,62 @@
|
||||
<!--
|
||||
Copyright 2014 Sean Bedford
|
||||
|
||||
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="heatmiser-in">
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
||||
<input type="text" id="node-input-name" placeholder="Name">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-uuid"><i class="icon-tag"></i> IP Address</label>
|
||||
<input type="text" id="node-input-ip" placeholder="192.168.0.1">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="icon-tag"></i> PIN</label>
|
||||
<input type="text" id="node-input-pin" placeholder="1234">
|
||||
</div>
|
||||
<div class="form-tips">Expects a msg.payload with a JSON object that contains settings for the Heatmiser thermostat</div>
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="heatmiser-in">
|
||||
<p>Heatmiser Input node.</p>
|
||||
<p>Expects a msg.payload with a JSON object that contains settings for the Heatmiser thermostat</p>
|
||||
<p>msg.payload can currently be either a heating boost option, or a run mode, as below:</p>
|
||||
<h3>Heating boost</h3>
|
||||
<p><pre>{heating: {target: TARGET_TEMPERATURE, hold: MINUTES_TO_STAY_ON_FOR}}</pre></p>
|
||||
<h3>Run mode</h3>
|
||||
<p><pre>{runmode:"frost" OR "heating"}</pre></p
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('heatmiser-in',{
|
||||
category: 'advanced-function',
|
||||
color:"GoldenRod",
|
||||
defaults: {
|
||||
name: {value:""},
|
||||
ip: {value:""},
|
||||
pin: {value:""}
|
||||
},
|
||||
inputs:1,
|
||||
outputs:0,
|
||||
icon: "timer.png",
|
||||
label: function() {
|
||||
return this.name||"heatmiser-in";
|
||||
},
|
||||
labelStyle: function() {
|
||||
return this.name?"node_label_italic":"";
|
||||
}
|
||||
});
|
||||
</script>
|
191
hardware/heatmiser-in/100-heatmiser-in.js
Normal file
191
hardware/heatmiser-in/100-heatmiser-in.js
Normal file
@ -0,0 +1,191 @@
|
||||
/**
|
||||
* Copyright 2014 Sean Bedford
|
||||
*
|
||||
* 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.
|
||||
**/
|
||||
|
||||
var RED = require(process.env.NODE_RED_HOME+"/red/red");
|
||||
|
||||
var Heatmiser = require("heatmiser");
|
||||
var util = require('util');
|
||||
|
||||
function HeatmiserInputNode(n) {
|
||||
// TODO - holiday and hot water cases when confirmed working
|
||||
var DEBUG = false;
|
||||
RED.nodes.createNode(this,n);
|
||||
this.ip = n.ip || "192.168.0.1";
|
||||
this.pin = n.pin || "1234";
|
||||
this.multiWriteFunc = undefined;
|
||||
hminnode = this;
|
||||
this.pollIntervalRef = undefined;
|
||||
|
||||
this.hm = new Heatmiser(this.ip, this.pin);
|
||||
|
||||
this.hm.on('success', function(data) {
|
||||
if (DEBUG) {
|
||||
util.log("[100-heatmiser-in.js] - Successfully wrote data. Response : " + JSON.stringify(data));
|
||||
}
|
||||
hminnode.currentStatus = data.dcb;
|
||||
if (hminnode.multiWriteFunc) {
|
||||
hminnode.multiWriteFunc();
|
||||
hminnode.multiWriteFunc = undefined;
|
||||
return;
|
||||
}
|
||||
hminnode.send({topic: "", payload:JSON.stringify(data.dcb)});
|
||||
});
|
||||
this.hm.on('error', function(data) {
|
||||
if (DEBUG) {
|
||||
util.log("[100-heatmiser-in.js] - Error during data setting : " + JSON.stringify(data));
|
||||
}
|
||||
hminnode.send(data);
|
||||
});
|
||||
|
||||
this.on("close", function() {
|
||||
if (this.pollIntervalRef) {
|
||||
clearInterval(this.pollIntervalRef);
|
||||
this.pollIntervalRef = undefined;
|
||||
}
|
||||
});
|
||||
|
||||
this.read = function() {
|
||||
if (hminnode.hm) {
|
||||
hminnode.hm.read_device();
|
||||
}
|
||||
};
|
||||
|
||||
if (!this.currentStatus) {
|
||||
this.read();
|
||||
this.pollIntervalRef = setInterval(this.read, 30*60*1000);
|
||||
}
|
||||
|
||||
this.write = function(dcb) {
|
||||
if (hminnode.hm) {
|
||||
hminnode.hm.write_device(dcb);
|
||||
}
|
||||
};
|
||||
|
||||
this.validateAndWrite = function(message) {
|
||||
for (var key in message.payload) {
|
||||
// Ensure our valid keys contain valid values
|
||||
switch(key) {
|
||||
case "runmode" :
|
||||
if (DEBUG) {
|
||||
util.log("[100-heatmiser-in.js] Hit the runmode case");
|
||||
}
|
||||
if (message.payload[key] !== "frost" && message.payload[key] !== "heating") {
|
||||
util.log("[100-heatmiser-in.js] Warning: Unsupported 'runmode' value passed!");
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
// case "holiday" :
|
||||
// if (DEBUG) {
|
||||
// util.log("[100-heatmiser-in.js] Hit the holiday case");
|
||||
// }
|
||||
// if (!('enabled' in message.payload[key]) && !('time' in message.payload[key])) {
|
||||
// util.log("[100-heatmiser-in.js] Warning: Unsupported 'holiday' value passed!");
|
||||
// return;
|
||||
// }
|
||||
// var time = message.payload[key].time;
|
||||
// // Ensure hminnode time is a date
|
||||
// if (typeof(time) == "string") {
|
||||
// util.log("Typeof time was " +typeof(message.payload[key].time));
|
||||
// // message.payload[key].time = new Date(message.payload[key].time);
|
||||
// message.payload[key].time = new Date(2014, 02, 15, 12, 0, 0);
|
||||
// util.log("Typeof time is now " +typeof(message.payload[key].time));
|
||||
// }
|
||||
// // Also add in away mode (for hot water) if we're on hols
|
||||
// if (message.payload[key].time) {
|
||||
// message.payload.away_mode = 1;
|
||||
// }
|
||||
// else {
|
||||
// message.payload.away_mode = 0;
|
||||
// }
|
||||
// break;
|
||||
|
||||
// case "hotwater" :
|
||||
// if (DEBUG) {
|
||||
// util.log("[100-heatmiser-in.js] Hit the hotwater case");
|
||||
// }
|
||||
// if (message.payload[key] !== "on" && message.payload[key] !== "boost" && message.payload[key] !== "off") {
|
||||
// util.log("[100-heatmiser-in.js] Warning: Unsupported 'hotwater' value passed!");
|
||||
// return;
|
||||
// }
|
||||
// break;
|
||||
|
||||
case "heating" :
|
||||
// Ensure heating stays last! It's got a multi write scenario
|
||||
if (DEBUG) {
|
||||
util.log("[100-heatmiser-in.js] Hit the heating case");
|
||||
}
|
||||
if (!('target' in message.payload[key]) && !('hold' in message.payload[key])) {
|
||||
util.log("[100-heatmiser-in.js] Warning: Unsupported 'heating' value passed!");
|
||||
return;
|
||||
}
|
||||
// Set sane temp and time ranges and sanitise to float/int
|
||||
var target = parseFloat(message.payload[key].target);
|
||||
var hold = parseInt(message.payload[key].hold);
|
||||
(target > 30.0) ? message.payload[key].target = 30.0 : message.payload[key].target = target;
|
||||
(hold > 1440) ? message.payload[key].hold = 1440 : message.payload[key].hold = hold;
|
||||
(target <= 10.0) ? message.payload[key].target = 10.0 : message.payload[key].target = target;
|
||||
(hold <= 0) ? message.payload[key].hold = 0 : message.payload[key].hold = hold;
|
||||
|
||||
// Ensure hminnode runmode == heating first
|
||||
if (hminnode.currentStatus.run_mode === "frost_protection") {
|
||||
// Use the multiWriteFunc as a callback in our success case
|
||||
hminnode.multiWriteFunc = function() {
|
||||
hminnode.write(message.payload);
|
||||
}
|
||||
hminnode.write({"runmode" : "heating"});
|
||||
// End the flow here to ensure no double-writing
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
default :
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Valid set of key messages, construct DCB and write
|
||||
var dcb = message.payload;
|
||||
if (DEBUG) {
|
||||
util.log("[100-heatmiser-in.js] Injecting " + JSON.stringify(dcb));
|
||||
}
|
||||
hminnode.write(dcb);
|
||||
};
|
||||
|
||||
this.on("input", function(message) {
|
||||
// Valid inputs are heating:{target:, hold:}, read:, runmode:frost/heating, holiday:{enabled:, time:}, hotwater:{'on':1/0 / 'boost':1/0}
|
||||
if (message.payload) {
|
||||
if (typeof(message.payload) === "string") {
|
||||
message.payload = JSON.parse(message.payload);
|
||||
}
|
||||
// Compare message.payload data to confirm valid and send to thermostat
|
||||
var validInputs = ["heating", "runmode"];
|
||||
for (var key in message.payload) {
|
||||
if (message.payload.hasOwnProperty(key)) {
|
||||
if (validInputs.indexOf(key) < 0) {
|
||||
util.log("[100-heatmiser-in.js] Warning: Unsupported key ("+key+") passed!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
hminnode.validateAndWrite(message);
|
||||
}
|
||||
else {
|
||||
util.log("[100-heatmiser-in.js] Warning: Invalid input passed!");
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
RED.nodes.registerType("heatmiser-in",HeatmiserInputNode);
|
62
hardware/heatmiser-out/101-heatmiser-out.html
Normal file
62
hardware/heatmiser-out/101-heatmiser-out.html
Normal file
@ -0,0 +1,62 @@
|
||||
<!--
|
||||
Copyright 2014 Sean Bedford
|
||||
|
||||
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="heatmiser-out">
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
||||
<input type="text" id="node-input-name" placeholder="Name">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-uuid"><i class="icon-tag"></i> IP Address</label>
|
||||
<input type="text" id="node-input-ip" placeholder="192.168.0.1">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="icon-tag"></i> PIN</label>
|
||||
<input type="text" id="node-input-pin" placeholder="1234">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="icon-tag"></i> Poll time (in minutes)</label>
|
||||
<input type="text" id="node-input-pollTime" placeholder="30">
|
||||
</div>
|
||||
<div class="form-tips">Expects a msg.payload with a JSON object that contains settings for the Heatmiser thermostat</div>
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="heatmiser-out">
|
||||
<p>Heatmiser Output node.</p>
|
||||
<p>Will read and send a status update at a configurable time interval. This is set to every 30 minutes by default</p>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('heatmiser-out',{
|
||||
category: 'advanced-function',
|
||||
color:"GoldenRod",
|
||||
defaults: {
|
||||
name: {value:""},
|
||||
ip: {value:""},
|
||||
pin: {value:""},
|
||||
pollTime : {value:""}
|
||||
},
|
||||
inputs:0,
|
||||
outputs:1,
|
||||
icon: "timer.png",
|
||||
label: function() {
|
||||
return this.name||"heatmiser-out";
|
||||
},
|
||||
labelStyle: function() {
|
||||
return this.name?"node_label_italic":"";
|
||||
}
|
||||
});
|
||||
</script>
|
91
hardware/heatmiser-out/101-heatmiser-out.js
Normal file
91
hardware/heatmiser-out/101-heatmiser-out.js
Normal file
@ -0,0 +1,91 @@
|
||||
/**
|
||||
* Copyright 2014 Sean Bedford
|
||||
*
|
||||
* 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.
|
||||
**/
|
||||
|
||||
var RED = require(process.env.NODE_RED_HOME+"/red/red");
|
||||
|
||||
var Heatmiser = require("heatmiser");
|
||||
var util = require('util');
|
||||
|
||||
function HeatmiserOutputNode(n) {
|
||||
// TODO - holiday and hot water cases when confirmed working
|
||||
var DEBUG = false;
|
||||
RED.nodes.createNode(this,n);
|
||||
this.ip = n.ip || "192.168.0.1";
|
||||
this.pin = n.pin || "1234";
|
||||
this.pollTime = n.pollTime*60*1000 || 30*60*1000;
|
||||
this.pollIntervalRef = undefined;
|
||||
hmoutnode = this;
|
||||
|
||||
this.hm = new Heatmiser(this.ip, this.pin);
|
||||
|
||||
this.hm.on('success', function(data) {
|
||||
if (DEBUG) {
|
||||
util.log("[100-heatmiser-in.js] - Successfully wrote data. Response : " + JSON.stringify(data));
|
||||
}
|
||||
hmoutnode.send({topic: "", payload:JSON.stringify(data.dcb)});
|
||||
});
|
||||
this.hm.on('error', function(data) {
|
||||
if (DEBUG) {
|
||||
util.log("[100-heatmiser-in.js] - Error during data setting : " + JSON.stringify(data));
|
||||
}
|
||||
hmoutnode.send(data);
|
||||
});
|
||||
|
||||
this.read = function() {
|
||||
if (hmoutnode.hm) {
|
||||
hmoutnode.hm.read_device();
|
||||
}
|
||||
};
|
||||
|
||||
if (!this.currentStatus) {
|
||||
this.read();
|
||||
this.pollIntervalRef = setInterval(this.read, this.pollTime);
|
||||
}
|
||||
|
||||
this.on("close", function() {
|
||||
if (this.pollIntervalRef) {
|
||||
clearInterval(this.pollIntervalRef);
|
||||
this.pollIntervalRef = undefined;
|
||||
}
|
||||
});
|
||||
|
||||
this.on("input", function(message) {
|
||||
// Valid inputs are heating:{target:, hold:}, read:, runmode:frost/heating, holiday:{enabled:, time:}, hotwater:{'on':1/0 / 'boost':1/0}
|
||||
if (message.payload == "undefined" || !message.payload) {
|
||||
message.payload = {read : true};
|
||||
}
|
||||
if (typeof(message.payload) == "string") {
|
||||
message.payload = JSON.parse(message.payload);
|
||||
}
|
||||
if (message.payload.read) {
|
||||
hmoutnode.read();
|
||||
}
|
||||
else if (message.payload) {
|
||||
// Compare message.payload data to confirm valid and send to thermostat
|
||||
var validInputs = ["heating", "runmode"];
|
||||
for (var key in message.payload) {
|
||||
if (message.payload.hasOwnProperty(key)) {
|
||||
if (validInputs.indexOf(key) < 0) {
|
||||
util.log("[100-heatmiser.js] Warning: Unsupported key ("+key+") passed!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
hmoutnode.validateAndWrite(message);
|
||||
}
|
||||
});
|
||||
}
|
||||
RED.nodes.registerType("heatmiser-out",HeatmiserOutputNode);
|
@ -13,6 +13,7 @@
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
-->
|
||||
|
||||
<script type="text/x-red" data-template-name="HueNode">
|
||||
@ -35,6 +36,11 @@
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<label for="node-input-brightness"><i class="icon-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="icon-tag"></i>Select color:</label>
|
||||
<input type="text" id="node-input-color" placeholder="color">
|
||||
@ -50,29 +56,38 @@
|
||||
<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 and also set its color. </p><p>By setting the status to AUTO, you can set the ON/OFF status as a message payload (e.g., msg.payload="ON") and the color through the message topic (e.g., msg.topic="EBF5FF") on the node input. Please note, in case you use both, the status selection overides the msg.payload!</p><p>Also, if you pass something like msg.payload="ALERT" the Lamp will flash once.</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>
|
||||
</script>
|
||||
|
||||
<!-- Finally, the node type is registered along with all of its properties -->
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('HueNode',{
|
||||
category: 'advanced-input',
|
||||
category: 'advanced-input', // the palette category
|
||||
color:"#EFEFEF",
|
||||
defaults: {
|
||||
name: {value:""},
|
||||
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},
|
||||
color: {value:"EBF5FF"},
|
||||
brightness: {value:"100"},
|
||||
lamp_status:{}
|
||||
},
|
||||
inputs:1,
|
||||
outputs:1,
|
||||
icon: "hue.png",
|
||||
label: function() {
|
||||
return this.name||"HueNode";
|
||||
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() {
|
||||
labelStyle: function() { // sets the class to apply to the label
|
||||
return this.name?"node_label_italic":"";
|
||||
}
|
||||
});
|
||||
|
@ -18,14 +18,19 @@
|
||||
* 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;
|
||||
|
||||
|
||||
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);
|
||||
@ -36,21 +41,32 @@ function hexToRgb(hex) {
|
||||
} : null;
|
||||
}
|
||||
|
||||
|
||||
// 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;
|
||||
var node = this;
|
||||
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) {
|
||||
@ -63,35 +79,62 @@ function HueNode(n) {
|
||||
//save the IP address of the 1st bridge found
|
||||
this.gw_ipaddress = result[0].ipaddress;
|
||||
|
||||
|
||||
//set light status
|
||||
var api = new HueApi(this.gw_ipaddress, node.username);
|
||||
var lightState = hue.lightState;
|
||||
var state = lightState.create();
|
||||
|
||||
var status;
|
||||
if(msg.payload=="ALERT"){
|
||||
status = "ALERT";
|
||||
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;
|
||||
}
|
||||
else if(node.lamp_status=="ON" || msg.payload=="ON") status = "ON";
|
||||
else if(node.lamp_status=="OFF" || msg.payload=="OFF") status = "OFF";
|
||||
|
||||
|
||||
if(status=="ALERT") {
|
||||
api.setLightState(node.lamp_id, state.alert()).then(displayResult).fail(displayError).done();
|
||||
//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();
|
||||
}
|
||||
else if(status=="ON") {
|
||||
if(node.color==null) {
|
||||
api.setLightState(node.lamp_id, state.on().rgb(hexToRgb(msg.topic).r,hexToRgb(msg.topic).g,hexToRgb(msg.topic).b)).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(node.lamp_id, state.on().rgb(hexToRgb(node.color).r,hexToRgb(node.color).g,hexToRgb(node.color).b)).then(displayResult).fail(displayError).done();
|
||||
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();
|
||||
}
|
||||
|
||||
msg2.payload = 'Light with ID: '+node.lamp_id+ ' was set to '+status;
|
||||
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);
|
||||
}
|
||||
else {
|
||||
@ -104,6 +147,7 @@ function HueNode(n) {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
this.on("close", function() {
|
||||
// Called when the node is shutdown - eg on redeploy.
|
||||
// Allows ports to be closed, connections dropped etc.
|
||||
@ -121,6 +165,9 @@ 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);
|
||||
|
@ -20,25 +20,20 @@
|
||||
<input type="text" id="node-input-emonServer">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-topic"><i class="icon-tasks"></i> Topic</label>
|
||||
<input type="text" id="node-input-topic" placeholder="">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-nodegroup"><i class="icon-tag"></i> Node Group</label>
|
||||
<label for="node-input-nodegroup"><i class="icon-tag"></i> Node</label>
|
||||
<input type="text" id="node-input-nodegroup" placeholder="">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
||||
<input type="text" id="node-input-name" placeholder="Emoncms">
|
||||
</div>
|
||||
<div class="form-tips">Topic is not mandatory, if Topic is left blank <b>msg.topic</b> will used. Topic overrides <b>msg.topic</b></br>
|
||||
Node Group (numeric) is not mandatory, if Node Group is left blank <b>msg.nodegrpup</b> will used. Node Group overrides <b>msg.nodegroup</b></div>
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="emoncms">
|
||||
<p>Performs post to Emoncms.</p>
|
||||
<p>Topic is not mandatory, if Topic is left blank <b>msg.topic</b> will used. Topic overrides <b>msg.topic</b></p>
|
||||
<p>Node Group (numeric) is not mandatory, if Node Group is left blank <b>msg.nodegrpup</b> will used. Node overrides <b>msg.nodegrpup</b></p>
|
||||
<p>Emoncms post.</p>
|
||||
<p>The <b>msg.payload</b> can contain either a comma separated list of name value pairs ex. name:value,... or a comma separated list of values ex. 1,2,.. .
|
||||
<p>If Node is left blank <b>msg.nodegrpup</b> will used.</p>
|
||||
<p>Insertion time can be manipulated by setting <b>msg.time</b>.</p>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
@ -48,7 +43,6 @@
|
||||
defaults: {
|
||||
name: {value:"Emoncms"},
|
||||
emonServer: {type:"emoncms-server", required:true},
|
||||
topic: {value:""},
|
||||
nodegroup: {value:""}
|
||||
},
|
||||
inputs:1,
|
||||
@ -85,7 +79,6 @@
|
||||
category: 'config',
|
||||
defaults: {
|
||||
server: {value:"http://localhost",required:true},
|
||||
// apikey: {value:"",required:true},
|
||||
name: {value:""}
|
||||
},
|
||||
label: function() {
|
||||
|
@ -71,19 +71,25 @@ function Emoncms(n) {
|
||||
this.baseurl = sc.server;
|
||||
this.apikey = sc.apikey;
|
||||
|
||||
this.topic = n.topic ||"";
|
||||
this.nodegroup = n.nodegroup || "";
|
||||
var node = this;
|
||||
if (this.baseurl.substring(0,5) === "https") { var http = require("https"); }
|
||||
else { var http = require("http"); }
|
||||
this.on("input", function(msg) {
|
||||
|
||||
var topic = this.topic || msg.topic;
|
||||
this.url = this.baseurl + '/input/post.json?';
|
||||
if(msg.payload.indexOf(':') > -1){
|
||||
this.url += 'json={' + msg.payload + '}';
|
||||
} else {
|
||||
this.url += 'csv='+msg.payload;
|
||||
}
|
||||
this.url += '&apikey='+this.apikey;
|
||||
var nodegroup = this.nodegroup || msg.nodegroup;
|
||||
this.url = this.baseurl + '/input/post.json?json={' + topic + ':' + msg.payload+'}&apikey='+this.apikey;
|
||||
if(nodegroup != ""){
|
||||
this.url += '&node=' + nodegroup;
|
||||
}
|
||||
if(typeof msg.time !== 'undefined'){
|
||||
this.url += '&time=' + msg.time;
|
||||
}
|
||||
node.log("[emoncms] "+this.url);
|
||||
http.get(this.url, function(res) {
|
||||
node.log("Http response: " + res.statusCode);
|
||||
|
Loading…
Reference in New Issue
Block a user