# nubli

> Nuki Bluetooth Library

Latest version **1.0.1** (published 2019-09-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install nubli
pnpm add nubli
yarn add nubli
bun add nubli
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2019-09-10 |
| First published | 2019-02-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 120.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 15 |
| Author | Henry Spanka |
| Maintainers | henryspanka |
| Keywords | node, nuki, smartlock, smart-lock, smarthome, bluetooth, library |

## Links

- npm: https://www.npmjs.com/package/nubli
- Repository: https://github.com/henry-spanka/nubli
- Homepage: https://github.com/henry-spanka/nubli#readme
- Issues: https://github.com/henry-spanka/nubli/issues
- npm.io page: https://npm.io/package/nubli

## Dependencies (5)

- [crc](https://npm.io/package/crc.md) ^3.8.0
- [noble](https://npm.io/package/noble.md) ^1.9.1
- [libsodium-wrappers](https://npm.io/package/libsodium-wrappers.md) ^0.7.4
- [array-buffer-to-hex](https://npm.io/package/array-buffer-to-hex.md) ^1.0.0
- [hex-to-array-buffer](https://npm.io/package/hex-to-array-buffer.md) ^1.1.0

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2019-09-10
- 1.0.0 — 2019-02-17
- 0.1.0 — 2019-02-05

## README

# Nubli

Nubli is a Node.JS library for Nuki Smart Locks (**Nu**ki **B**luetooth **Li**brary)
Nubli is very energy efficient when used properly and should't drain more power than a Nuki bridge. It uses the same protocol the App and Bridge uses and therefore communicates securely with the Smart Lock.

[![NPM](https://nodei.co/npm/nubli.png?compact=true)](https://npmjs.org/package/nubli)

# Features
* Get Lock State of Nuki Smart Lock (including door sensor)
* Unlock/Lock/Unlatch/LockNGo Door
* Listen for Lock State and Door Sensor changes
* Get Authorizations
* Get Configuration
* Get Advanced Configuration

# Supported devices
- Nuki Smart Lock v2
- Nuki Smart Lock v1 (not yet 100% compatible - Please open an issue if something doesn't work)

# Requirements
- Linux-based Server (e.g. Raspberry Pi)
- Bluetooth 4.x Dongle (Tested with $5 CSR Module)

**Note**: Do not use the built-in Bluetooth in a Raspberry Pi. Due to bad hardware design it will not reliably connect to your Smart Lock and cause unexpected disconnects. I've been there and invested a whole week into fixing it.

# Setup / Installation
1. `npm install nubli --save`
2. See [Examples](examples/) or [Usage](#usage)
3. Star the repository ;)

# Notes
* You can only run one instance of this library simultaneously with one dongle. If want to integrate this library into multiple applications running at the same time on the same device, either pin the applications to different bluetooth dongles or communicate with a single instance of this library via a webserver/websocket/mqtt instead.

# Usage
```typescript
    const nubli = require('nubli').default;

    nubli.onReadyToScan()
    .then(() => {
        nubli.startScanning();
    })
    .catch((err) => {
        console.log(err);
    });
```

## Actions

### Start Scanning for Nuki devices
```typescript
    nubli.startScanning(): void;
```

### Start Actively Scanning for Nuki devices (Required for pairing)
```typescript
    nubli.startActiveScanning(): void;
```

**Notes**:
* Scanning requires the bluetooth device to be powered on. This may take a few milliseconds. Make sure to wait for the promise ```nubli.readyToScan()``` to resolve first.
* Only use active scanning when you are trying to pair a new device. Active Scanning will drain your Smart Lock's battery very quickly. Passive Scanning only listens for advertisements from the Smart Lock and does not request additionaly information from the Smart Lock.

### Stop Scanning for Nuki devices
```typescript
    nubli.stopScanning(): void;
```

### Connect to a Smart Lock
```typescript
    smartlock.connect(): Promise<void>;
```

### Disconnect from a Smart Lock
```typescript
    smartlock.disconnect(): Promise<void>;
```

### Check if a config for the Smart Lock already exists
```typescript
    smartlock.configExists(path?: string): boolean;
```

### Read Smart Lock config
```typescript
    smartlock.readConfig(path?: string): Promise<void>;
```

### Save Smart Lock config
```typescript
    smartlock.saveConfig(path?: string): Promise<void>;
```

### Pair with a Smart Lock
```typescript
    smartlock.pair(asBridge = true): Promise<void>;
```

**Note**: By default it will pair as bridge. If you do have a bridge, make sure to pass false as a parameter. The reason is, that when no bridge exists, Nuki will not push any state changes automatically via advertisements, so we set ourselves as a bridge instead.

### Read lock state from Smart Lock
```typescript
    smartlock.readLockState(): Promise<SmartLockResponse>;
```

### Unlock door
```typescript
    smartlock.unlock(updateCallback?: (response: SmartLockResponse) => void): Promise<SmartLockResponse>;
```

### Lock door
```typescript
    smartlock.lock(updateCallback?: (response: SmartLockResponse) => void): Promise<SmartLockResponse>;
```

### Unlatch Door
```typescript
    smartlock.unlatch(updateCallback?: (response: SmartLockResponse) => void): Promise<SmartLockResponse>;
```

### Lock N Go Door
```typescript
    smartlock.lockNGo(updateCallback?: (response: SmartLockResponse) => void): Promise<SmartLockResponse>;
```

### Lock N Go Unlatch Door
```typescript
    smartlock.lockNGoUnlatch(updateCallback?: (response: SmartLockResponse) => void): Promise<SmartLockResponse>;
```

### Get Config from Smart Lock
```typescript
    smartlock.requestConfig(): Promise<SmartLockResponse>;
```

### Get Advanced Config from Smart Lock
```typescript
    smartlock.requestAdvancedConfig(): Promise<SmartLockResponse>;
```

## Properties

### Check whether a Smart Lock is already paired
```typescript
    smartlock.paired: boolean;
```
## Events

### Nubli Smart Lock Discovered Event
```typescript
    nubli.on('smartLockDiscovered', (smartlock: SmartLock) => void);
```

### Nubli started scanning
```typescript
    nubli.on('startedScanning', () => void);
```

### Nubli stopped scanning
```typescript
    nubli.on('stoppedScanning', () => void);
```

### Smart Lock Connected Event
```typescript
    smartlock.on('connected', () => void);
```

### Smart Lock Disconnected Event
```typescript
    smartlock.on('disconnected', () => void);
```

### Smart Lock Error Event
```typescript
    smartlock.on('error', (err: string) => void);
```

### Smart Lock Activity Log Changed Event
```typescript
    smartlock.on('activityLogChanged', () => void);
```

**Note**: The `activityLogChanged` event only works while scanning because the Smart Lock advertises activity log changes via bluetooth. To get notified when the door opens or closes (Door Sensor) make sure to enable 'Log door sensor status' in the Nuki app.

# Help
If you have any questions or help please open an issue on the GitHub project page.

# Contributing
Pull requests are always welcome. If you have an issue or feature request please open a GitHub issue.

# License
The project is subject to the MIT license unless otherwise noted. A copy can be found in the root directory of the project [LICENSE](LICENSE).

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