New openHAB2 Binding for Nuki Smart Locks

openhab2
binding
Tags: #<Tag:0x00007fe0548692c8> #<Tag:0x00007fe054869160>

(Markus) #1

Hi,
I opened a pull request for a new openHAB2 binding for Nuki Smart Locks.

Pull request can be found here:


Further information regarding the binding can be found here:


A binding .jar of the current state of the pull request can be downloaded here:
https://openhab.jfrog.io/openhab/libs-pullrequest-local/org/openhab/binding/org.openhab.binding.nuki/


Issues and Feature Requests can be opened here:

Any help in testing, any feedback and feature requests are more than welcome! :slight_smile:

Thx & have fun!

Markus


NEW BINDING creation support Request - NUKI SMART LOCK
Homematic integration with Nuki smart lock
(kevin) #2

Where does the callback port come from? I’m new to both OH2 and the callback stuff. Is the callback port just the OH2 HTTP Port - default 8080 - or something else? I can see how to make the request to the bridge, but I don’t know what to put in it.


(Markus) #3

The callbackPort is used by the Nuki Bridge API to report Lock State changes to openHAB. Please see Nuki Bridge API topic /callback.
You can use any free port on your openHAB2 server. It is not the openHAB2 port 8080.

For example:
Nuki Bridge: IP 192.168.0.50, PORT 8080
openHAB server: IP 192.168.0.100, PORT 8080
I freely chose callbackPort 8081 (so the Nuki Bridge should callback openHAB on port 8081 for Lock State changes).
And that’s why I added the callback URL on the Nuki Bridge via the endpoint ‘/callback/add’ like this:
http://192.168.0.50:8080/callback/add?token=1a2b3c4d5e&url=http%3A%2F%2F192.168.0.100%3A8081
and I configured callbackPort 8081 in PaperUI or callbackPort=8081 in .things file.

Please note: The need of configuration of the callbackPort will be removed very soon and just the configuration of the callback URL on the Nuki Bridge is necessary.


(kevin) #4

Thanks for the informative reply. I have configured the callback, and also added a things file. The smartlock and bridge both show up as “UNINITIALIZED” Restarting the bundle puts this in the log

2017-04-03 09:32:53.121 [DEBUG] [org.openhab.binding.nuki            ] - BundleEvent STARTING - org.openhab.binding.nuki
2017-04-03 09:32:53.160 [DEBUG] [org.openhab.binding.nuki            ] - ServiceEvent REGISTERED - {org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory}={component.name=binding.nuki, component.id=201, service.id=338, service.bundleid=236, service.scope=bundle} - org.openhab.binding.nuki
2017-04-03 09:32:53.169 [DEBUG] [org.openhab.binding.nuki            ] - BundleEvent STARTED - org.openhab.binding.nuki

sending a command to it gives

2017-04-03 09:37:24.627 [WARN ] [ome.core.thing.internal.ThingManager] - Cannot delegate update 'ON' for item 'TestLock' to handler for channel 'nuki:smartLock:NukiBridge1:TestLock:smartLockOpenClose', because no handler is assigned. Maybe the binding is not installed or not propertly initialized.

What am I missing? Do I need a service file? If I do what do I put in it?


(Markus) #5

Did you configure .things and .items file like documented it in the README.md?
I got this error when I edited these files on my windows pc over a share running openHAB on a RaspberryPi3. Connecting over SSH and editing the files via nano or vim works for me. Also, if I use PaperUI I never got this error message.
If the error still shows up, please restart openHAB via SSH:
systemctl stop openhab2.service systemctl start openhab2.service


(kevin) #6

I Configured items from designer
I Configured things initially from notepad++, then from designer.
nuki.things

Bridge nuki:bridge:NukiBridge1 [ ip="192.168.xx.xx", port="8080", apiToken="ABCDEFGH", callbackPort="8081" ] { 
Thing smartLock TestDoorLock [ nukiId="12345678" ]
}

testitems.items

Switch Testdoor "Testdoor" <switch> { channel="nuki:smartLock:NukiBridge1:TestDoorLock:smartLockOpenClose" }

After a reboot I got this in the logs

2017-04-03 10:27:31.170 [DEBUG] [org.openhab.binding.nuki            ] - BundleEvent STARTING - org.openhab.binding.nuki
2017-04-03 10:27:31.172 [DEBUG] [org.openhab.binding.nuki            ] - BundleEvent STARTED - org.openhab.binding.nuki
2017-04-03 10:27:31.203 [DEBUG] [org.openhab.binding.nuki            ] - ServiceEvent REGISTERED - {org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory}={component.name=binding.nuki, component.id=198, service.id=339, service.bundleid=236, service.scope=bundle} - org.openhab.binding.nuki
2017-04-03 10:27:33.049 [TRACE] [ing.nuki.internal.NukiHandlerFactory] - ThingHandler:createHandler(org.eclipse.smarthome.core.thing.internal.BridgeImpl@ce099edc)
2017-04-03 10:27:33.053 [TRACE] [nding.nuki.handler.NukiBridgeHandler] - Instantiating NukiBridgeHandler(org.eclipse.smarthome.core.thing.internal.BridgeImpl@ce099edc)

then after operating the switch item

2017-04-03 10:30:05.248 [WARN ] [ome.core.thing.internal.ThingManager] - Cannot delegate command 'ON' for item 'Testdoor' to handler for channel 'nuki:smartLock:NukiBridge1:TestDoorLock:smartLockOpenClose', because no handler is assigned. Maybe the binding is not installed or not propertly initialized.
2017-04-03 10:30:05.253 [WARN ] [ome.core.thing.internal.ThingManager] - Cannot delegate update 'ON' for item 'Testdoor' to handler for channel 'nuki:smartLock:NukiBridge1:TestDoorLock:smartLockOpenClose', because no handler is assigned. Maybe the binding is not installed or not propertly initialized.

(Markus) #7

What version (date?) of the Nuki Binding have you installed?

Please see README.md (https://github.com/mkatter/openhab2-addons/tree/nuki/addons/binding/org.openhab.binding.nuki#troubleshooting-debugging-and-tracing)
and send me a full openHAB / Nuki Binding startup log.


(kevin) #8

01/04/2017 12:19, on my filesystem, its the one showing as 30th March @12:00 on your server
Those logs ARE from a reboot with the settings at trace

openhab> log:get org.openhab.binding.nuki
Logger                   | Level
--------------------------------
org.openhab.binding.nuki | TRACE

(Phil) #9

I have been waiting for this and love to see it! (Even tried to develop it myself.) I will test it and report back how it works.

Thanks a lot for the effort! :blush:

Edit: The review might take some time, I think it would be a good idea to distribute the Binding
in the marketplace(Distributing bindings through the IoT Marketplace) in the meantime.


(Markus) #10

Correct, I was allready thinking about providing the Nuki Binding via the IoT Marketplace untill it is incorporated into the openHAB2 distro… but you can actually download the current development state (of the pull request). See first post!

Please note: At the moment the Jenkins build fails for any reason (still waiting on clarification). So the current .jar for download is not the current development state as it is in my repo! I will keep you updated once the Jenkins build succeeds and the download .jar is up-to-date.

(Markus) #11

Yes, but still, I would need the full log not just some snippets.

Your problem could also be related to the fact that your .jar is an “old” version but you are using the config for the current version (see New openHAB2 Binding for Nuki Smart Locks).
Try to use upper case letters for all configuration parameters like:

Bridge nuki:bridge:NukiBridge1 [ IP="192.168.xx.xx", PORT="8080", APITOKEN="ABCDEFGH", CALLBACK_PORT="8081" ] { 
    Thing smartLock TestDoorLock [ NUKIID="12345678" ]
}

Once the Jenkins build succeeds again, please use the README.md as configuration reference again!


(Wolfgang) #12

Hey there!

I am pretty sure you might not be the only one with build problems, see: Jenkins build problems


(kevin) #13

All parameters changed to upper case, but still no go, I’ve sent you a PM with a link to the full log after a reboot, and my nuki things file


(Markus) #14

You have to be careful about the type of the config parameters. I overlooked it too!! :slight_smile:
Try this:

Bridge nuki:bridge:NukiBridge1 [ IP="192.168.x.x", PORT=8080, APITOKEN="xxxxxx", CALLBACK_PORT=8081 ] { 
  Thing smartLock FrontDoorLock [ NUKIID="123456789" ]
}

(Markus) #15

Yes, you are right! Thanks for sharing this thread

@all I provided an alternative download URL - please see https://community.openhab.org/t/new-openhab2-binding-for-nuki-smart-locks/25940?u=mkatter

(kevin) #16

Progress! I can now lock and unlock via the Openhab Switch item, BUT a manual unlock or lock doesn’t update the item. As you are changing the way callback works is it better to wait for a later version and test some more?
This isn’t on a door yet so waiting isn’t a problem


(Markus) #17

Neither the Smart Lock nor the Binding will work correctly, if the Smart Lock is not mounted on a door!

I definitely recommend to mount and set up the Smart Lock and the the Nuki Bridge first. Then, if everything is working as expected, you should start with the next challenge: testing the Nuki Binding :slight_smile:

The binding .jar which I uploaded to Google Drive (link is in the first post) is the current development state and it works fine for me.


(kevin) #18

It was mounted on the door, so as far as Nuki is concerned all is normal :wink: It seems to store the lock and unlock position somewhere, so with care to not pull out the batteries it still thinks its on a door. I guess they didn’t want to stall the motor after every lock and unlock as it would kill the batteries.
I’ve got it working with the Google Drive version, but I think the callback server terminates once it has had a reply from the lock after a lock / unlock operation. This means it doesn’t catch an operation from the button. See the last but one line in the log I PM’d you. Is this the way it should work?


(Markus) #19

Correct, once the Smart Lock is calibrated you can “use” it also unmounted :slight_smile:

The Nuki Bridge is not posting its Lock State change to openHAB2.

  1. Did the Smart Lock unlock / lock when you toggled the Switch Item in the Sitemap?
  2. Did you also change the callback URI on the Nuki Bridge (to http://openHAB2ServerIP:8080/nuki/bcb)? It’s documented in the README.md in the shared Google Drive folder.

(kevin) #20

It turns out that the bridge hadn’t retained the callback, I have entered it again and it works.
I’ll keep an eye out for any updates and test again if it helps, otherwise I’ll wait for the released version. :joy: