Git Product home page Git Product logo

nubli's Introduction

Nubli

Nubli is a Node.JS library for Nuki Smart Locks (Nuki Bluetooth Library) 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

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 or 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

    const nubli = require('nubli').default;

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

Actions

Start Scanning for Nuki devices

    nubli.startScanning(): void;

Start Actively Scanning for Nuki devices (Required for pairing)

    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

    nubli.stopScanning(): void;

Connect to a Smart Lock

    smartlock.connect(): Promise<void>;

Disconnect from a Smart Lock

    smartlock.disconnect(): Promise<void>;

Check if a config for the Smart Lock already exists

    smartlock.configExists(path?: string): boolean;

Read Smart Lock config

    smartlock.readConfig(path?: string): Promise<void>;

Save Smart Lock config

    smartlock.saveConfig(path?: string): Promise<void>;

Pair with a Smart Lock

    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

    smartlock.readLockState(): Promise<SmartLockResponse>;

Unlock door

    smartlock.unlock(updateCallback?: (response: SmartLockResponse) => void): Promise<SmartLockResponse>;

Lock door

    smartlock.lock(updateCallback?: (response: SmartLockResponse) => void): Promise<SmartLockResponse>;

Unlatch Door

    smartlock.unlatch(updateCallback?: (response: SmartLockResponse) => void): Promise<SmartLockResponse>;

Lock N Go Door

    smartlock.lockNGo(updateCallback?: (response: SmartLockResponse) => void): Promise<SmartLockResponse>;

Lock N Go Unlatch Door

    smartlock.lockNGoUnlatch(updateCallback?: (response: SmartLockResponse) => void): Promise<SmartLockResponse>;

Get Config from Smart Lock

    smartlock.requestConfig(): Promise<SmartLockResponse>;

Get Advanced Config from Smart Lock

    smartlock.requestAdvancedConfig(): Promise<SmartLockResponse>;

Properties

Check whether a Smart Lock is already paired

    smartlock.paired: boolean;

Events

Nubli Smart Lock Discovered Event

    nubli.on('smartLockDiscovered', (smartlock: SmartLock) => void);

Nubli started scanning

    nubli.on('startedScanning', () => void);

Nubli stopped scanning

    nubli.on('stoppedScanning', () => void);

Smart Lock Connected Event

    smartlock.on('connected', () => void);

Smart Lock Disconnected Event

    smartlock.on('disconnected', () => void);

Smart Lock Error Event

    smartlock.on('error', (err: string) => void);

Smart Lock Activity Log Changed Event

    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.

nubli's People

Contributors

henry-spanka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

nubli's Issues

Use abandonwares noble fork

Apparently, noble is not maintained anymore (See noble/node-bluetooth-hci-socket#84). I noticed this when I tried to install nubli-homebridge on my Raspberry 3 B, which failed to build on Node 10. I would suggest to switch to @abandonware/noble, which appears to be a well maintained fork.

Disconnected ?

Hello, I have a problem : After installing everything I launch pair.js to pair my nuki smart lock v2.0 and I have a "disconnected" line. The program stop and do nothing anymore.

Somebody can help me ?
Screenshot from 2019-04-18 17-06-01

questions using nubli

Hello Henry,

thanks for your great work!
I have a few questions about the use of nubli.
I would like to operate 2 door locks in parallel. What are the possibilities here. If i understood it correctly i could use 2 Bluetooth dongles, how do i address them or does it work automatically?
How can I specify which door lock should be addressed when I call up the library?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.