Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include libraries via codegenerator #60

Merged
merged 3 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions .github/example-project-dev.yaml

This file was deleted.

18 changes: 0 additions & 18 deletions .github/example-project-main.yaml

This file was deleted.

4 changes: 4 additions & 0 deletions .github/shared-config.yaml → .github/test-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ esphome:

esp32:
board: "esp32dev"
framework:
type: arduino
version: 2.0.16
platform_version: 6.7.0

wifi:
ssid: "My Network"
Expand Down
11 changes: 2 additions & 9 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,7 @@
- name: Checkout
uses: actions/checkout@v3

- name: Compile for main
if: github.ref == 'refs/heads/main'
- name: Compile Firmware
uses: esphome/build-action@v4.0.1
with:
yaml-file: .github/example-project-main.yaml

- name: Compile for dev
if: github.ref != 'refs/heads/main'
uses: esphome/build-action@v4.0.1
with:
yaml-file: .github/example-project-dev.yaml
yaml-file: .github/test-config.yaml
98 changes: 72 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
# ESPHome Nuki Lock Component (ESP32) [![Build Component](https://github.com/uriyacovy/ESPHome_nuki_lock/actions/workflows/build.yaml/badge.svg)](https://github.com/uriyacovy/ESPHome_nuki_lock/actions/workflows/build.yaml)

This module builds an ESPHome lock platform for Nuki Smartlocks (nuki_lock) that creates [24 entities](#entities) in Home Assistant.
This module brings seamless integration of Nuki Smartlocks into ESPHome, creating a rich Home Assistant lock platform with [24 entities](#entities).

The lock entity is updated whenever the look changes state (via Nuki App, HA, or manually) using the Nuki BLE advertisement mechanism.
The lock entity updates whenever the lock's state changes - whether through the Nuki app, Home Assistant, or manually. This is achieved via the efficient Nuki BLE advertisement mechanism, ensuring your lock status is always up-to-date.

![some dashboard entites](./docs/nuki_dashboard.png)


## How to use
Add the following to the ESPHome yaml file:
## How to Use
To integrate your Nuki Smartlock, add the following code snippet to your ESPHome YAML file:

```yaml
esphome:
libraries:
- Preferences
- https://github.com/h2zero/NimBLE-Arduino#1.4.0
- Crc16
- https://github.com/uriyacovy/NukiBleEsp32

external_components:
- source: github://uriyacovy/ESPHome_nuki_lock

Expand Down Expand Up @@ -108,14 +101,20 @@ lock:
- lambda: ESP_LOGI("nuki_lock", "Paired sucessfuly");
```

After running ESPHome (esphome run <yamlfile.yaml>), you have to activate the pairing mode of the ESPHome Component to pair your Nuki.
You can use the `Pairing Mode` Switch Entity or use the `nuki_lock.set_pairing_mode` Automation Action to do so.
To set Nuki for paring mode, press the Button on your Smart Lock for 5 seconds until the led turns on.
Once Nuki is paired, the new ESPHome entities will get the updated state and pairing mode is turned off.
After running ESPHome (`esphome run <yamlfile.yaml>`), follow these steps to pair your Nuki Smartlock:

1. **Activate Pairing Mode**: Enable pairing mode on the ESPHome component. You can do this by toggling the `Pairing Mode` switch entity in Home Assistant or by triggering the `nuki_lock.set_pairing_mode` action in an automation.

2. **Set Nuki to Pairing Mode**: On your Nuki Smart Lock, press and hold the button for 5 seconds until the LED lights up to enter pairing mode.

3. **Complete Pairing**: Once paired, the ESPHome entities will automatically update with the current lock status, and pairing mode will turn off.

## Supported Services ##
### Unlatch ###
To unlatch doors without a handle, call open service from Home Assistant:
Your Nuki Smartlock is now connected and ready to use!


## Supported Services
### Unlatch
To unlatch doors without a handle, call the `open` service in Home Assistant:
```yaml
service: lock.open
data: {}
Expand All @@ -124,30 +123,70 @@ target:
```

### Lock and Go
To run lock and go, call this service from Home Assistant:
To activate the Lock 'n' Go feature on your Nuki Smart Lock, call the following service in Home Assistant:

```yaml
service: esphome.<NODE_NAME>_lock_n_go
data: {}
```

## Automation
### Print Keypad Entries
To print the Keypad Entries in the ESPHome Console call the following service in Home Assistant:

```yaml
service: esphome.<NODE_NAME>_print_keypad_entries
data: {}
```

### Add a Keypad Entry
To add a Keypad Entry, call the following service in Home Assistant:

```yaml
service: esphome.<NODE_NAME>_add_keypad_entry
data:
name: "Name"
code: 12345678
```

### Remove a Keypad Entry
To remove a Keypad Entry, call the following service in Home Assistant:

```yaml
service: esphome.<NODE_NAME>_delete_keypad_entry
data:
id: 1
```

### Update a Keypad Entry
To update a Keypad Entry, call the following service in Home Assistant:

```yaml
service: esphome.<NODE_NAME>_update_keypad_entry
data:
id: 1
name: "Name"
code: 12345678
enabled: True
```

## ESPHome Automations
### Action: Pairing Mode
You can use this action to turn on/off the pairing mode:
To toggle the components Pairing Mode, use the following action:
```yaml
on_...:
- nuki_lock.set_pairing_mode:
pairing_mode: True
```

### Action: Unpair
You can use this action to unpair your Nuki Smartlock:
To unpair your Nuki Smart Lock, use the following action:
```yaml
on_...:
- nuki_lock.unpair:
```

### Callbacks
You can use this callbacks to run specific actions:
To run specific actions when certain events occur, you can use the following callbacks:
```yaml
on_pairing_mode_on_action:
- lambda: ESP_LOGI("nuki_lock", "Pairing mode turned on");
Expand All @@ -158,9 +197,16 @@ on_paired_action:
```

### Events
By default this component sends the Nuki logs as events to Home Assistant.
You can use them in automations. If you want to disable events, set the `event` property in your yaml to `none`.
If you want to check the log events, go to the Home Assistant Developer tools -> Events and listen for `esphome.nuki` events.
By default, this component sends Nuki logs as events to Home Assistant, enabling you to use them in automations.

- **To Disable Logs**: Set the `event` property in your YAML configuration to `none` if you don't want to receive log events.

- **To View Log Events**: Go to **Home Assistant Developer Tools** -> **Events**, and listen for `esphome.nuki` events to monitor log activity.

These log events provide insights into lock operations and help fine-tune automations based on real-time lock data.


Example Event:
```yaml
event_type: esphome.nuki
data:
Expand Down
10 changes: 10 additions & 0 deletions components/nuki_lock/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,16 @@ async def to_code(config):
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
await automation.build_automation(trigger, [], conf)

# Libraries
cg.add_library("Preferences", None)
cg.add_library("h2zero/NimBLE-Arduino", "1.4.0")
cg.add_library("Crc16", None)
cg.add_library(
None,
None,
"https://github.com/I-Connect/NukiBleEsp32#93e7da927171c8973b7ef857c7fa644c174ed47d",
)


# Actions
NukiLockUnpairAction = nuki_lock_ns.class_(
Expand Down
Loading