New openHAB2 Binding for Nuki Smart Locks

@Falk Good to hear and thanks for the feedback! :+1:

Iā€™ve been using the binding to control my Nuki Lock for several months now, and its most used to lock the door after I close it. Once OH detects the door has closed it waits for a few seconds in case its opened again before locking. Iā€™ve also found itā€™s possible to open and close the door before it notices its unlocked which can result in the door not locking. Iā€™ve used a rule to get around this which is below in case it helps anyone.

 var boolean LockBusy = false

rule "Nuki Available"
when Item NukiLockState changed then {
LockBusy = true
createTimer(now.plusSeconds(2)[|
   LockBusy = false
   ]
} 
end

rule "lock door"
when Item Door changed from OPEN to CLOSED then {
createTimer(now.plusSeconds(5))[|
if (Door.state == CLOSED && !LockBusy && NukiLockState.state == OFF) {
   NukiLockState.sendCommand(ON)
   logInfo("Nuki", "Door Locked on first attempt") } else {
   createTimer(now.plusSeconds(10))[|
      if (Door.state == CLOSED && !LockBusy && NukiLockState.state == OFF) {
          NukiLockState.sendCommand(ON)
          logInfo("Nuki", "Door Locked on second attempt") } else {
          createTimer(now.plusSeconds(10))[|
          if (Door.state == CLOSED && !LockBusy && NukiLockState.state == OFF) {
              NukiLockState.sendCommand(ON)
              logInfo("Nuki", "Door Locked on third attempt")
              } else {
              logInfo("Nuki", "Door couldn't be locked")
              }
           ]
         }
        ]
       }
  end

Thanks for sharing! :+1:

Maybe I get your problem wrong but why are you not simply using the ā€œAuto Lockā€ feature of the Smart Lock?
The SL will automatically lock the door after your configured time. And the Nuki Bridge will report the SL state back via the callback to openHAB. This works fine for me.

Regarding unrecognized state changes if unlock and lock are executed in a very short period of time:
Yes it is very likely to happen in an every day scenario: Unlock the door e.g. via App from the outside (1sec), open the door, enter the hall, close the door (3secs), lock the door via SL button from the inside (1sec).
The Bridge will not report the unlocked state via the callback to openHAB. Simply because it is to ā€œslowā€, meaning it is ā€œdoing other more important thingsā€ before it is executing the callback. But it will report the very last state, here locked, via the callback to openHAB. This also works fine for me.

What I am saying is, use the features of the SL (if possible) and use the callback of the Bridge for handling the state.

BTW: The latest dev build (see first post) manages the callback on the Bridge by itself.

Oh forgot to ask: What additional systems or sensors are you using?

I donā€™t use the ā€œAuto Lockā€ as the lock doesnā€™t know whether the door is open or not. I have contacts on the door handle so when the handle is moved into the ready to lock position it tells OH to lock the door. If for example I want to leave the door open for ventilation Nuki would lock it even though the handle wasnā€™t in the closed and locked position,
With my door its:
1)Press button on Nuki to unlock
2)Turn Handle 1/4 turn
3)Pull door open
and
1)Close door
2)Turn Handle 1/4 Turn
3)OH detects Handle turn
4)OH locks Nuki via Bridge and Binding

I also use the system to unlock the door when I return on my ebike using a combination of OH, Bluetooth Beacons and OwnTracks Geofencing. Nukiā€™s auto unlocking didnā€™t allow for us getting home by car or when the phone was in deep sleep mode.

Additional systems and sensors - you mean for Nuki or in general? I have a lot going on here and outgrew the Pi sometime back :slight_smile:

Just to get it right: With your door locking system it is not possible to lock until you pulled the handle 1/4 turn up?

Yes, I meant sensors in general. Like the one you are using to recognize the handle turns.
I think I understand your set-up now. What sensors are you using to recognize the handle turns? Do you also have sensors to check if the door itself is closed/opened?

Yes 1/4 turn is correct. Moving this moves 4 rollers on the door mechanism so they lock against 4 hooks on the uPVC door frame. I pass a voltage through the hooks via an ESP8266, this detects the door is closed and the handle has been turned. I donā€™t have a door open sensor.
I also use the hook and roller setup on other doors for detection purposes.
In the case of the Nuki equipped door I donā€™t have an outside keyhole making ā€œbumpingā€ the lock impossible

@mkatter

I would like to buy a second NUKI SMARTLOCK.
Is it possible to add two smartlocks to Openhab via one bridge?

@The-Elk Yes, just configure another Thing smartlock under the same bridge. But keep in mind that both Smart Locks have to have a good/stable BLE connection to the Bridge!

Iā€™m interested in buy a nuki device. This month they released the version 2.0. Does anyone tried the new version with the binding? Iā€™m reading some comments online and it seems that the improvements developed (better auto-unlock, open/close faster) are not met as promised, any comments on that?

I have the 2.0. Canā€™t compare with the old one though. It works as advertised, except that the door sensor isnā€™t really functional right now. It keeps throwing errors.

I canā€™t see the lock over Zigbee, I guess that it is not enabled yet. I havenā€™t implemented any unlocking functions via Openhab, but I did program a notification via OH whenever the door unlocks, and that works. Havenā€™t tried the auto-unlocking yet.

I also replaced my 1.0 Yuki with the 2.0 Version. Seems a little quieter and faster, Auto Unlock now works more consistent. And the door sensor is nice. But I can not get the callback to work again, it is set up in the bridge (I kept my old bridge), but openHAB does not get the status messages from the lock. Locking and unlocking works, thoughā€¦

Bye, Frido.

Hi Guys, Iā€™m new to this forum so excuse any mistakes. Just bought a new Nuki 2 with bridge and followed all the threads here and there seems like a problem with the callback (might have worked with the Nuki 1 but not v2). I am running the latest snapshot 2.5.0 - 17th Dec. Seems like the Nuki name search on the bridge gets confused between the Nuki ID and the BLE name.Debug file below (I hope).

Hi @townlema ,

to me it seems you got the Nuki ID wrong! Please check the sticker on the back of the Smartlock, it should be ā€­14E2F50Fā€¬!

BR Markus

Hi Markus, yep that fixed it and the callback now works - thanks a lot. Great binding!

Did you solve this? I just replaced my v1 Nuki with the v2 Nuki also.
Iā€™m using 2.4 stable and the Nuki 2.4 binding - just replaced the Smartlock Thing with the new Nuki ID.
Locking/Unlocking works - but the callback wonā€™t. Do you need to add a new callback or something?

http://192.168.xx.yy:8080/callback/list?token=XXXX

{"callbacks": [{"id": 2, "url": "http://192.168.xxx.yyy:8080/nuki/bcb"}]}

http://192.168.xx.yy:8080/list?token=XXXX

[{"nukiId": 12345, "name": "BinderTĆ¼r2", "firmwareVersion": "2.3.1", "lastKnownState": {"state": 3, "stateName": "unlocked", "batteryCritical": false, "timestamp": "2019-01-07T20:37:26+00:00"}},{"nukiId": 54321, "name": "BinderTĆ¼r"}]

Sorry, but I did not resolve it yet. Did the same thing you did and just replaced the NukiID with the new one. Also deleted all Callbacks and let the Binding recreate it, but to no avail, Callbacks still do not work.

Bye, Frido.

one quick Dummy question:
Do I need both The nuki Lock and the Nuki Bridge Hardware as well or can I operate the lock without the bridge from OH?

Without a bridge you canā€™t operate the Smartlock via OH2. Itā€™s an encrypted Bluetooth protocol.
If you have an spare Android device, you could use the Software Bridge in the AppStore instead.
I never used the App, but it seems it is identical to the hardware bridge.

Hi Thomas,

thanks for your quick help.
Nuki seems to be a good smart lock and I will consider to buy one.

I have the Nuki 2.0 Combo (Bridge, Smartlock, Fobs). Itā€™s working perfectly with iobroker for about two month now. Since a week Iā€™m trying to switch over to openHAB. All devices and bindings are fully functional except Nuki.
It installs without issues. The callback is registered automatically in the bridge. Sometimes it reacts to actions sent via openHAB sometimes not. Whatā€™s never working is updating the state in openHAB when lockstate is changed via Android App.

Iā€™m running openHAB 2.4 (Release) + 2.4 Binding in Docker on a Synology Diskstation 418play (2 Network Interfaces).

All things and items were created in PaperUI.

Any tips for me?