Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ sftp-config*.json
d.ts


database
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ node-zwave

Control your z-wave devices on node.js

THIS IS NOT READY!
THIS IS NOT READY! IT IS IN LARGE TORN APART, HARD CODED, AND NOT USEFUL FOR ANYTHING BUT MY STUFF.

This code is essentially ported from a C library that does the same thing. The C lib was written by a genius and also a close friend whose blog resides here: http://www.squarepenguin.com/wordpress/

Expand Down
35 changes: 31 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,39 @@

var zwave = require('./src/node-zwave');

var promise = zwave.connect();
var promise = zwave.connect('/dev/ttyUSB0');
//var promise = zwave.connect();

promise.then(function(connection) {
console.log("I connected! Sweet!");
zwave.getNodeAbilities(1);
//console.log(zwave);

/*
var nodes = zwave.getNodes();
nodes.then(function(data){
console.log('woot! '+data);
});


zwave.getNodes(function(data){
//console.log('Woot!! '+data);
//console.log(data);
//console.log(data.length);
for(var i=0;i<data.length;i++){
console.log('looking for' +i+ ': '+data[i])
//zwave.getNodeProtocol(data[i],function(node){console.log(node);});
}
});
*/

//zwave.associateNode(5,function(node){console.log(node);});
//zwave.getNodeProtocol(2,function(node){console.log(node);});
//zwave.getNodeProtocol(3,function(node){console.log(node);});
//zwave.getNodeAbilities(2);
//zwave.getNodeAbilities(3);
//zwave.getNodeAbilities(4);
//zwave.getNodeAbilities(5);
//zwave.thermostat.setMode(5,'heat');
//zwave.thermostat.setSetpoint(5, 62, 'heating');

});

}).catch(function (error) {console.log(error)});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"gitHead": "54eb3808258d8b2da247407479cde7cf4c0bdfe1",
"dependencies": {
"moment": "~2.0.0",
"q": "~0.9.3"
"q": "~0.9.3",
"serialport": "latest"
},
"devDependencies": {
}
Expand Down
279 changes: 279 additions & 0 deletions src/command_classes/energyMonitor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,279 @@

var fdefs = require('../functions/definitions');
var globals = require('../globals');
var iface = require('../interface');

var energyMonitor = {};

// Define constants

// HEM command classes
var COMMAND_CLASS_CONFIGURATION = 0x70;
var COMMAND_CLASS_SENSOR_MULTILEVEL = 0x31;
var COMMAND_CLASS_METER = 0x32;
var CONFIGURATION_SET = 0x04;
var CONFIGURATION_GET = 0x05;

var INTERVAL_GROUPS = [
110,
111,
112,
113
];

var REPORT_GROUPS = [
100,
101,
102,
103
];

var REPORT_TYPES = {
watt: 0x04,
kwh: 0x08
};

/*******************************************************************************
Getters
*******************************************************************************/

/**
* Get the multilevel report of the entire HEM
* @param {Number} nodeId The node ID of the HEM
* @param {Function} [callback] Callback is optional. A promise is returned
*/
energyMonitor.getMultilevelReport = function(nodeId, callback) {
var command = [
COMMAND_CLASS_SENSOR_MULTILEVEL,
0x04 //SENSOR_MULTILEVEL_GET
];

command = prepData(nodeId,command,'send');

var promise = iface.sendMessage(command, 'request', listener);
promise.then(function(data){
callback(data);
});
return promise; // not sure if this promise works?
}

/**
* Get the meter report for the entire HEM
* @param {Number} nodeId The node ID of the HEM
* @param {Function} [callback] Callback is optional. A promise is returned
*/
energyMonitor.getMeterReport = function(nodeId, callback) {
var command = [
COMMAND_CLASS_METER,
0x01 //METER_GET
];

command = prepData(nodeId,command,'send');

var promise = iface.sendMessage(command, 'request', listener);
promise.then(function(data){
callback(data);
});
return promise; // not sure if this promise works?
}

/**
* Get the voltage the HEM is currently set to
* @param {Number} nodeId The node ID of the HEM
* @param {Function} [callback] Callback is optional. A promise is returned
*/
energyMonitor.getVoltage = function(nodeId, callback) {
//zwave.sendRequestData(4,[0x70,0x05,0x01],function(reply){
// console.log('BBBBBBBOOOOOOOOOOOOOOOOOOOMMMMMMMMM!!!!!!!!!!!');
// console.log(reply);
//
//}); //get param 1 (voltage)


var paramId = 1; // voltage param

var command = [
COMMAND_CLASS_CONFIGURATION,
CONFIGURATION_GET,
paramId
];

command = prepData(nodeId,command,'request');

var promise = iface.sendMessage(command, 'request', listener);
promise.then(function(data){
//<Buffer 01 0c 00 04 00 04 06 70 06 01 02 00 6e ee> // 110 volts (6e)
//<Buffer 01 0c 00 04 00 04 06 70 06 01 02 00 78 f8> // Aftter setting to 120
callback(data);
});
return promise; // not sure if this promise works?
}


/*******************************************************************************
Setters
*******************************************************************************/

/**
* Set the voltage of the HEM
* @param {Number} nodeId The node ID of the HEM
* @param {Number} voltage The voltage to set it to, note, this is usually 120 for USA, or 240 outside the USA
* @param {Function} [callback] Callback is optional. A promise is returned
*/
energyMonitor.setVoltage = function(nodeId, voltage, callback) {
var paramId = 1; // voltage param
var paramLength = 2;

var command = [
COMMAND_CLASS_CONFIGURATION,
CONFIGURATION_SET,
paramId,
paramLength,
0x00, // MSB
voltage // LSB
];

command = prepData(nodeId,command,'config');

var promise = iface.sendMessage(command, 'request', listener);
promise.then(function(data){
callback(data);
});
return promise; // not sure if this promise works?
}

/**
* Resets the configuration of the HEM
* @param {Number} nodeId The node ID of the HEM
* @param {Function} [callback] Callback is optional. A promise is returned
*/
energyMonitor.resetConfiguration = function(nodeId) {
var paramId = 255; // reset param
var paramLength = 1;

var command = [
COMMAND_CLASS_CONFIGURATION,
CONFIGURATION_SET
paramId,
paramLength,
0x00 // ??
];

command = prepData(nodeId,command,'config');

var promise = iface.sendMessage(command, 'request', listener);
promise.then(function(data){
callback(data);
});
return promise; // not sure if this promise works?
}

/**
* Resets the configuration of the HEM
* @param {Number} nodeId The node ID of the HEM
* @param {Number} group The group you would like to set the interval for (1,2, or 3)
* @param {Number} seconds The number of seconds between auto reports, default is 720, ma you can set till I fix this up is 255
* @param {Function} [callback] Callback is optional. A promise is returned
*/
energyMonitor.setReportingInterval = function(nodeId, group, seconds) {
var paramId = INTERVAL_GROUPS[group];
var paramLength = 4;

var command = [
COMMAND_CLASS_CONFIGURATION,
CONFIGURATION_SET
paramId,
paramLength,
0x00, // MSB
0x00,
0x00,
seconds // LSB TODO: fix this so you can use the full 4 bytes ansd go above 255 seconds
];

command = prepData(nodeId,command,'config');

var promise = iface.sendMessage(command, 'request', listener);
promise.then(function(data){
callback(data);
});
return promise; // not sure if this promise works?
}

/**
* Resets the configuration of the HEM
* @param {Number} nodeId The node ID of the HEM
* @param {Number} group The group you would like to set the interval for (1,2, or 3)
* @param {Number} report Which report to send to that group (watt or kwh)
* @param {Function} [callback] Callback is optional. A promise is returned
*/
energyMonitor.addReportToGroup = function(nodeId, group, report) {
var paramId = REPORT_GROUPS[group];
var paramLength = 4;

var command = [
COMMAND_CLASS_CONFIGURATION,
CONFIGURATION_SET
paramId,
paramLength,
0x00, // MSB reserved
0x00, // reserved
0x00, // see page 6 of the engineering spec from aeon labs, this byte bit 0-5 allows for automatic individual clamp readings
REPORT_TYPES[report] // see page 6 of the engineering spec from aeon labs, this byte bit 0-3 allows for automatic overall readings
];

command = prepData(nodeId,command,'config');

var promise = iface.sendMessage(command, 'request', listener);
promise.then(function(data){
callback(data);
});
return promise; // not sure if this promise works?
}

energyMonitor.enableDeltaReporting = function(nodeId) {
// TODO: zwave.sendRequestData(4,[0x70,0x04,0x03,0x00,0x00],function(reply){console.log(reply);}); // Turn on Delta function of the whole HEM

}

// helper method to prepare the command packets to send
function prepData(nodeId,cmd,type) {
var mysteryVal = 0;
if(type=='config'){
mysteryVal = 4+cmd[3];
}
else if(type=='send'){
mysteryVal = 2;
}
else if(type=request){
mysteryVal = 3;
}

var command = [
0x01,
0x00, // length, calculated after we get a command
0x00, // I believe this signifies it is a request?
defs.DATA,
nodeId, // nodeid
mysteryVal // This was required to get the HEM configuration working, probably breaks other stuff
];

command = command.concat(cmd);
command.push(0x05);
command.push(0x03);

command[1] = parseInt(command.length-1);

return command;
}

/*******************************************************************************
Listener - handles responses from zwave controller
*******************************************************************************/

function listener(data) {
console.log('Energy monitor response received...');
console.log(data);
}

module.exports = energyMonitor;

1 change: 1 addition & 0 deletions src/command_classes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ var funcs = {};

funcs.thermostat = require('./thermostat');
funcs.binarySwitch = require('./binarySwitch');
funcs.energyMonitor = require('./energyMonitor');

module.exports = funcs;
25 changes: 20 additions & 5 deletions src/functions/definitions.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@

var d = {};

d.GET_NODES = 0x02;
d.APP_DATA = 0x04;
d.APP_DATA = 0x04; // this does not look to be correct?
d.DATA = 0x13;
d.GET_NETWORK_ID = 0x20;
d.GET_NETWORK_ID = 0x20; // this does not look to be correct?
d.GET_NODE_PROTOCOL = 0x41;
d.GET_NODE_ABILITIES = 0x49;
d.GET_NODE_SUPPORTED_CLASSES = 0x49;
d.GET_NODE_ABILITIES = 0x49; // this does not look to be correct?
d.GET_NODE_SUPPORTED_CLASSES = 0x49; // this does not look to be correct?
d.GET_NODE_INFO = 0x60;
d.ADD_NODE_TO_NETWORK = 0x4a;
d.REMOVE_NODE_FROM_NETWORK = 0x4a;

d.DEVICE_TYPE = {0x01:{type:'basic controller'},
0x02:{type:'static controller'},
0x03:{type:'basic slave'},
0x04:{type:'routing slave'},
0x08:{type:'thermostat'},
0x10:{type:'switch'},
0x11:{type:'dimmer'},
0x12:{type:'basic switch remote'},
0x13:{type:'basic switch toggle'},
0x17:{type:'generic security panel'},
0x20:{type:'binary sensor'},
0x21:{type:'multilevel sensor'},
0x31:{type:'meter'}
};

module.exports = d;
Loading