Based on Nuki BLE API implementation for ESP32, I’ve built an ESPHome lock component for Nuki smart door lock.
The component acts as a bridge for the Nuki, and creates lock (and other) entities in HA. Notice that once paired to ESPHome, the existing Nuki bridge (if you have any) will be disconnected.
Disclaimer: I’m not related to Nuki in anyway, and I created this as a quick learning project. I’ll be able to offer very little support, but PRs are always welcomed.
Thanks so much for this component! It works very fast. However, it is a bit unstable for me for my 2 doors. Both esp32’s have excellent wifi but somehow, in HA it mentions it goes unavailable every x minutes. Someone recognize this? I will add a syslogger to it to be able to debug it a better.
Compiling .pioenvs/sheddoor/libc13/NukiBleEsp/NukiLock.cpp.o
In file included from .piolibdeps/sheddoor/NukiBleEsp/src/NukiBle.cpp:13:0:
.piolibdeps/sheddoor/NukiBleEsp/src/NukiBle.h: In constructor 'Nuki::NukiBle::NukiBle(const string&, uint32_t, NimBLEUUID, NimBLEUUID, NimBLEUUID, NimBLEUUID, std::__cxx11::string)':
.piolibdeps/sheddoor/NukiBleEsp/src/NukiBle.h:323:14: error: 'Nuki::NukiBle::deviceId' will be initialized after [-Werror=reorder]
uint32_t deviceId; //The ID of the Nuki App, Nuki Bridge or Nuki Fob to be authorized.
^
.piolibdeps/sheddoor/NukiBleEsp/src/NukiBle.h:281:22: error: 'const NimBLEUUID Nuki::NukiBle::pairingServiceUUID' [-Werror=reorder]
const NimBLEUUID pairingServiceUUID;
^
.piolibdeps/sheddoor/NukiBleEsp/src/NukiBle.cpp:30:1: error: when initialized here [-Werror=reorder]
NukiBle::NukiBle(const std::string& deviceName,
^
Archiving .pioenvs/sheddoor/libc9d/libBleScanner.a
Compiling .pioenvs/sheddoor/libc13/NukiBleEsp/NukiLockUtils.cpp.o
Indexing .pioenvs/sheddoor/libc9d/libBleScanner.a
.piolibdeps/sheddoor/NukiBleEsp/src/NukiBle.cpp: In member function 'Nuki::PairingState Nuki::NukiBle::pairStateMachine(Nuki::PairingState)':
.piolibdeps/sheddoor/NukiBleEsp/src/NukiBle.cpp:677:78: warning: ignoring return value of 'int crypto_scalarmult_curve25519(unsigned char*, const unsigned char*, const unsigned char*)', declared with attribute warn_unused_result [-Wunused-result]
crypto_scalarmult_curve25519(sharedKeyS, myPrivateKey, remotePublicKey);
^
Compiling .pioenvs/sheddoor/libc13/NukiBleEsp/NukiOpener.cpp.o
cc1plus: some warnings being treated as errors
*** [.pioenvs/sheddoor/libc13/NukiBleEsp/NukiBle.cpp.o] Error 1
===================================================================== [FAILED] Took 170.79 seconds
I did a esphome clean command and removed the temp folders but still no luck. Any idea?
Edit: After also changing the esp32 block to the one you posted, it works. I thought that should just remain as is and point to my az-delivery-devkit-d4 but I guess I was wrong:)
Oct 19 14:12:08 sheddoor api: [D][api:102]: Accepted ::FFFF:192.168.2.15
Oct 19 14:12:08 sheddoor api.connection: [D][api.connection:861]: Home Assistant 2022.8.6 (::FFFF:192.168.2.15): Connected successfully
Oct 19 14:20:00 sheddoor api: [D][api:102]: Accepted ::FFFF:192.168.2.15
Oct 19 14:20:00 sheddoor api.connection: [D][api.connection:861]: Home Assistant 2022.8.6 (::FFFF:192.168.2.15): Connected successfully
Oct 19 14:20:07 sheddoor api.connection: [W][api.connection:078]: Home Assistant 2022.8.6 (::FFFF:192.168.2.15): Connection reset
Oct 19 14:24:30 sheddoor api.connection: [W][api.connection:080]: Home Assistant 2022.8.6 (::FFFF:192.168.2.15): Connection closed
Oct 19 14:24:31 sheddoor api: [D][api:102]: Accepted ::FFFF:192.168.2.15
Oct 19 14:24:31 sheddoor api.connection: [D][api.connection:861]: Home Assistant 2022.8.6 (::FFFF:192.168.2.15): Connected successfully
Oct 19 14:33:30 sheddoor api.connection: [W][api.connection:078]: Home Assistant 2022.8.6 (::FFFF:192.168.2.15): Connection reset
Oct 19 14:33:30 sheddoor api: [D][api:102]: Accepted ::FFFF:192.168.2.15
Oct 19 14:33:30 sheddoor api.connection: [D][api.connection:861]: Home Assistant 2022.8.6 (::FFFF:192.168.2.15): Connected successfully
Oct 19 14:35:45 sheddoor api.connection: [W][api.connection:080]: Home Assistant 2022.8.6 (::FFFF:192.168.2.15): Connection closed
Oct 19 14:35:45 sheddoor api: [D][api:102]: Accepted ::FFFF:192.168.2.15
Oct 19 14:35:45 sheddoor api.connection: [D][api.connection:861]: Home Assistant 2022.8.6 (::FFFF:192.168.2.15): Connected successfully
Oct 19 14:41:23 sheddoor api.connection: [W][api.connection:080]: Home Assistant 2022.8.6 (::FFFF:192.168.2.15): Connection closed
Oct 19 14:41:24 sheddoor api: [D][api:102]: Accepted ::FFFF:192.168.2.15
Oct 19 14:41:25 sheddoor api.connection: [D][api.connection:861]: Home Assistant 2022.8.6 (::FFFF:192.168.2.15): Connected successfully
Oct 19 14:45:53 sheddoor api.connection: [W][api.connection:080]: Home Assistant 2022.8.6 (::FFFF:192.168.2.15): Connection closed
Oct 19 14:45:54 sheddoor api: [D][api:102]: Accepted ::FFFF:192.168.2.15
Oct 19 14:45:54 sheddoor api.connection: [D][api.connection:861]: Home Assistant 2022.8.6 (::FFFF:192.168.2.15): Connected successfully
Oct 19 14:57:10 sheddoor api: [D][api:102]: Accepted ::FFFF:192.168.2.15
Oct 19 14:57:10 sheddoor api.connection: [D][api.connection:861]: Home Assistant 2022.8.6 (::FFFF:192.168.2.15): Connected successfully
Oct 19 14:57:20 sheddoor api.connection: [W][api.connection:080]: Home Assistant 2022.8.6 (::FFFF:192.168.2.15): Connection closed
The wifi should be pretty stable and I’m also seeing the same behavior for my other lock which is just next to the router. Can’t seem to figure out why there might be a reset or disconnect happening every hour for x seconds.
Edit:
Tried to add the power_save_mode: none option after reading through some GitHub issues. Unfortunately that prevents the API port from being accessible, “not able to connect” messages. The device is pingable so wifi works fine.
Thank you for your reply.
This is the only device that cannot connect to the hotspot when it is hidden. Prior to installing your firmware (with the base firmware installed via the web tool), it was able to connect to the same access point (hidden). I may be wrong, but I think it is related to a version of library that handles WiFi or something like that.
Edit:
Ok, I solved the problem by adding the variable hidden set to true, based on the documentation found at WiFi Component — ESPHome.