Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/0x7466/python-nuki-client
A python client for the Nuki KT. https://nuki.io/
https://github.com/0x7466/python-nuki-client
Last synced: 3 months ago
JSON representation
A python client for the Nuki KT. https://nuki.io/
- Host: GitHub
- URL: https://github.com/0x7466/python-nuki-client
- Owner: 0x7466
- License: mit
- Archived: true
- Created: 2017-10-06T17:56:53.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-10-06T17:57:16.000Z (over 7 years ago)
- Last Synced: 2024-08-01T22:49:04.334Z (6 months ago)
- Language: Python
- Size: 110 KB
- Stars: 6
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Nuki client for Python 3
This python library let's you talk with the Nuki smart lock (https://nuki.io/)
## Get started
### 1. Hardware
Install a BLE-compatible USB dongle (or use the built-in bluetooth stack if available)### 2. Install dependencies
```
$ sudo apt install libffi-dev pkg-config libboost-python-dev libboost-thread-dev libbluetooth-dev libglib2.0-dev python3-dev bluetooth libbluetooth-dev
```### 3. Install bluez
You'll get more infos [here](https://learn.adafruit.com/install-bluez-on-the-raspberry-pi/installation)### 4. Some hacks
Replace the `/usr/local/lib/python3.[YOUR-PY-VERSION]/dist-packages/pygatt/backends/gatttool/gatttool.py` file with the file from this repository.### 5. Install Nuki Client
```
$ sudo pip3 install python-nuki-client
```### That's all!
You are now ready to use the library in python!## Example usage
### Authenticate
Before you will be able to send commands to the Nuki lock using the library, you must first authenticate (once!) yourself with a self-generated public/private keypair (using NaCl):```python
from nukiclient import Nuki
from nacl.public import PrivateKey
import binasciinuki_mac_address = "00:00:00:00:00:01"
# generate the private key which must be kept secret
key_pair = PrivateKey.generate()
public_key_hex = binascii.hexlify(key_pair.public_key.encode())
private_key_hex = binascii.hexlify(key_pair.encode())
id = 50
# id-type = 00 (app), 01 (bridge) or 02 (fob)
# take 01 (bridge) if you want to make sure that the 'new state available'-flag is cleared on the Nuki if you read it out the state using this library
id_type = '01'
name = "PiBridge"nuki = Nuki(nuki_mac_address, config_path='path_to_your_config/config.ini')
nuki.authenticate_user(public_key_hex, private_key_hex, id, id_type, name)
```**REMARK 1** The credentials are stored in the file you define at instantiation : Default is `./nuki.cfg`
**REMARK 2** Authenticating is only possible if the lock is in 'pairing mode'. You can set it to this mode by pressing the button on the lock for 5 seconds until the complete LED ring starts to shine.
**REMARK 3** You can find out your Nuki's MAC address by using 'hcitool lescan' for example.
### Commands to the Nuki KT
Once you are authenticated (and the nuki.cfg file is created on your system), you can use the library to send command to your Nuki lock:```python
from nukiclient import Nukinuki_mac_address = "00:00:00:00:00:01"
pin = 0000nuki = Nuki(nuki_mac_address, config_path='path_to_your_config/config.ini')
# Reads the lock state
nuki.read_lock_state()# Performs an action
nuki.lock_action("UNLOCK")# Gets log entries
logs = nuki.get_log_entries(10, pin)
print("received {} log entries".format(len(logs)))# Requests calibration
nuki.request_calibration(pin)# Checks if a new state is available
available = nuki.is_new_nuki_state_available()
print("New state available: {}".format(available))
```**REMARK** the method `is_new_nuki_state_available()` only works if you run your python script as root (sudo). All the other methods do not require root privileges