1
1. Quick start
AlCalzone edited this page 2019-08-23 15:34:58 +02:00
-
Install this library as a dependency in your project
npm i zwave-js
-
Load the module.
IMPORTANT: The main entry point of this library is the very first thing you need to load. It installs a polyfill that is required for this library to work.import { Driver } from "zwave-js"; // main entry point ⤴
-
Create and start a driver instance
// The following needs to be inside an async method: // Tell the driver which serial port to use const driver = new Driver("COM3"); // Listen for the driver ready event, which driver.once("driver ready", () => { /* Now the controller interview is complete. This means we know which nodes are included in the network, but they might not be ready yet. The node interview will continue in the background */ driver.controller.nodes.forEach( // e.g. add event handlers to all known nodes ); // After a node was interviewed, it is safe to control it const node = driver.controller.nodes.get(2); node.once("interview completed", async () => { // e.g. perform a BasicCC::Set with target value 50 await node.commandClasses.Basic.set(50); }); }); // Start the driver await driver.start();
-
When you're done, don't forget to shut down the driver
driver.destroy();