# node-nuki-ble

> A Node.JS BLE library for the Nuki Smartlock

Latest version **0.9.1** (published 2019-02-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-nuki-ble
pnpm add node-nuki-ble
yarn add node-nuki-ble
bun add node-nuki-ble
```

Provides the command `nuki`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.9.1 |
| Published | 2019-02-17 |
| First published | 2019-02-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | =8 |
| Dependencies | 8 |
| Unpacked size | 138 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Marc-Peter Eisinger |
| Maintainers | eisvogel |
| Keywords | node, js, nuki, ble, bluetooth |

## Links

- npm: https://www.npmjs.com/package/node-nuki-ble
- Repository: https://github.com/DerEisvogel/node-nuki-ble
- Homepage: https://github.com/DerEisvogel/node-nuki-ble#readme
- Issues: https://github.com/DerEisvogel/node-nuki-ble/issues
- npm.io page: https://npm.io/package/node-nuki-ble

## Dependencies (8)

- [crc](https://npm.io/package/crc.md) ^3.8.0
- [ini](https://npm.io/package/ini.md) ^1.3.5
- [noble](https://npm.io/package/noble.md) ^1.9.1
- [semver](https://npm.io/package/semver.md) 5.6.0
- [sodium](https://npm.io/package/sodium.md) ^2.0.3
- [is-root](https://npm.io/package/is-root.md) ^2.0.0
- [commander](https://npm.io/package/commander.md) ^2.19.0
- [libsodium](https://npm.io/package/libsodium.md) ^0.7.3

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.9.1 (latest) — 2019-02-17
- 0.9.0 — 2019-02-17

## README

# node-nuki-ble

This library provides an API to interface with a [Nuki Smartlock](https://nuki.io/de/) 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](https://www.github.com/noble/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.
```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](cli) and [service](bin/service.js).


## Documentation

The source of this library is almost fully documented using JSDoc. The public API documentation can be found here:
[Public API Documentation](docs/api.md)


## 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](https://github.com/DerEisvogel/homebridge-nuki-ble) - A homebridge plugin for the Nuki Smartlock using the bluetooth API

---
_Source: https://npm.io/package/node-nuki-ble · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
