A Node.JS BLE library for the Nuki Smartlock
npm install node-nuki-bleThis library provides an API to interface with a Nuki Smartlock using bluetooth.
* 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.
Install the module using NPM:
```
$ npm install -g node-nuki-ble
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
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
* remove-authorization-entry
* request-states
* request-battery-report
* request-authorization-entries
* unlatch
* unlock
To execute an action enter the desired command and press enter.
The following example demonstrates how to execute a lock action on a previously paired Nuki.
`javascript
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.
The source of this library is almost fully documented using JSDoc. The public API documentation can be found here:
Public API Documentation
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]
``
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.
* Coming SOON: homebridge-nuki-ble - A homebridge plugin for the Nuki Smartlock using the bluetooth API