zwaveip

1.0.0 • Public • Published

zwaveip-node

A Z-Wave IP implementation for Node.js. Unofficial library, not supported by Sigma Designs.

This library enables node.js application to communicate with Z-Wave devices via a Z/IP (Z-Wave IP) Gateway.

To install the library

npm install zwaveip

To import the library

let ZWaveIP = require('zwaveip');

To convert the Z-Wave network's PSK (Pre-Shared Key) password from a hex string to the required binary representation

let convertHexStringToBinaryPsk = function(hexString) {
    let result = Buffer.alloc(hexString.length / 2);

    for (let i = 0; i < hexString.length; i += 2) {
        result[i / 2] = parseInt("0x" + hexString.substr(i, 2), 16);
    }

    return result;
}

To connect to a Z-Wave device

let deviceConnection = ZWaveIP.connectToZWaveDevice(ipAddress, pskIdentity, pskPassword);

To send a message to the connected Z-Wave device (example)

deviceConnection.sendMessage(ZWaveIP.CommandClass.SwitchBinary, ZWaveIP.SwitchBinaryCommand.Set, [0xFF]);

To send a message and then wait for an acknowledgment using Promises (example)

deviceConnection.sendMessage(ZWaveIP.CommandClass.SwitchBinary, ZWaveIP.SwitchBinaryCommand.Set, [0xFF])
.then(
    function() {
        console.log('Message acknowledged.');
    },
    function(err) {
        console.log('Message failure: ' + JSON.stringify(err));
    }
);

To request device status from the connected Z-Wave device (example)

deviceConnection.sendMessageAndWaitForResponse(ZWaveIP.CommandClass.SwitchBinary, ZWaveIP.SwitchBinaryCommand.Get, [], ZWaveIP.SwitchBinaryCommand.Report)
.then(
    function(response) {
        let powerStateAsByte = response.data[0];
        let powerStateAsBoolean = (powerStateAsByte != 0);
        console.log("powerState: " + powerStateAsBoolean + " (" + powerStateAsByte + ")");
    },
    function(err) {
        console.log('Message failure: ' + JSON.stringify(err));
    }
);

To close a Z-Wave device connection

deviceConnection.close(callback);

To prevent a Z-Wave device connection from blocking the Node.JS process from exiting (identical to udp socket functionality)

deviceConnection.unref();

To discover the virtual IPv4 address of a Z-Wave Gateway Controller on your local network

ZWaveIP.findGatewayControllerIpv4Address()
.then(
    function(ipv4Address) {
        console.log(" FOUND: Z/IP Gateway controller IPv4 address is: " + ipv4Address + "\n");
    },
    function(err) {
        console.log('Could not discover the Z-Wave Gateway Controller's virtual IPv4 address: ' + JSON.stringify(err));
    }
);

To discover all Z-Wave devices in your Z-Wave network

ZWaveIP.requestNodeListFromGatewayController(gatewayIpAddress, pskIdentity, pskPassword)
.then(
    function(nodeList) {
        let ipAddress = nodeList[index].ipv4Address === null ? nodeList[index].ipv6Address : nodeList[index].ipv4Address;
        console.log('Z-Wave Node # ' + nodeList[index].nodeId + ' (' + ipAddress + ')');
    },
    function(err) {
        console.log('Could not request node lsit from the specified Z-Wave Gateway Controller: ' + JSON.stringify(err));
    }
);

Documentation on Z-Wave command classes and Z-Wave commands

For full documentation, see: http://zwavepublic.com/downloads
For JavaScript enumerations, see the 'index.js' within this package's folder

Readme

Keywords

Package Sidebar

Install

npm i zwaveip

Weekly Downloads

0

Version

1.0.0

License

Apache-2.0

Last publish

Collaborators

  • zwaveiot