node-nuki-ble
v0.9.1
Published
A Node.JS BLE library for the Nuki Smartlock
Downloads
3
Readme
node-nuki-ble
This library provides an API to interface with a Nuki Smartlock using bluetooth.
Important Notes
- The library has been developed with the Raspberry Pi / Raspbian in mind. It has been tested on a Raspberry Pi 3 with the latest release of Raspbian only.
- The library has been tested with a Nuki v1. Compatibility with Nuki v2 has not been confirmed at this point. Feel free to test and post your results.
- For bluetooth communication this library uses noble which only works with Node.JS v8. Please make sure to use the appropriate version or otherwise the library will crash.
Installation
Install the module using NPM:
$ npm install -g node-nuki-ble
Getting Started using the CLI
The module comes a CLI tool which can pair and control Nuki devices.
Pairing a new device
First a new Nuki devices need to be paired. Please follow the instructions of the Nuki manual to put it into pairing mode. Then run the following command. Replace the name with the desired display name for the pairing in the Nuki app and choose a device type.
$ nuki pair --name <name> --type <app|fob|bridge>
If the pairing completes without any error it will be store in the file pairing.bin
.
Controlling the Nuki Smartlock
Once paired the following command can be user to enter the main Nuki CLI:
$ nuki cli --pairing pairing.bin
> help
The following commands are available:
* fob1
* fob2
* fob3
* help
* lock
* lockngo
* lockngo-unlatch
* pin <pin>
* remove-authorization-entry
* request-states
* request-battery-report
* request-authorization-entries
* unlatch
* unlock
To execute an action enter the desired command and press enter.
Getting Started using the Node.JS API
The following example demonstrates how to execute a lock action on a previously paired Nuki.
const nuki = require('node-nuki-ble'); // Returns an instance of NukiManager
(async function () {
let pairing = nuki.pairing('pairing.bin'); // Returns an instance of NukiPairing
let peripheral = await nuki.discoverPeripheral(pairing.macAddress); // Returns an instance of NukiPeripheral
let lock = peripheral.lock(pairing); // Returns an instance of NukiLockService
lock.lockAction(nuki.Constants.LockAction.Lock); // Performs the actual lock action
})();
For more examples also see the implementation of the included CLI tools and service.
Documentation
The source of this library is almost fully documented using JSDoc. The public API documentation can be found here: Public API Documentation
systemd Service
The library also comes with a systemd service which can be installed globally using the following command:
$ nuki service install --pairing ./pairing.bin
The service can either be controlled using systemctl
and journalctl
or by using the included CLI tool:
$ nuki service --help
Usage: nuki-service [options] [command]
Options:
-v, --version output the version number
-h, --help output usage information
Commands:
install [options]
uninstall [options]
start [options]
stop [options]
restart [options]
status [options]
logs [options]
Contribution
User contributions to this library are always welcome. Please use the issues sections and feel free to create Pull Requests for bug fixes, imrovements or new features.
The library is still a work in progress. Most parts have been refined multiple times but there are still some bugs and missing features. The public API may change in the future.
Projects using this library
- Coming SOON: homebridge-nuki-ble - A homebridge plugin for the Nuki Smartlock using the bluetooth API