Nuki Card with Callback support (supports both Lock & Opener, it replaces the official integration)

Yeah, the easy way still requires the Nuki official integration. My goal was different. But it’s good to have choices. :slight_smile:

1 Like

It’s a nice feeling being able to click “ignore” while still having a fully working integration, that provides all info about the Nuki, and faster status feedback. :slight_smile:

image

1 Like

Great work! This method is so much faster then just using the rest api.
Is it possible to get the lock_state on callback? The current binary sensor only updates when a door status change is triggered.
I’m trying to create a binary sensor, which is on when the lock is unlatching or unlocking (7 or 2) but can’t get it working.

Thank you, glad you liked it.

It’s already like that. Lock state and Door state are separate and update independently, each time a callback is received.

If it doesn’t work for you, make sure you configured everything correctly.

If you look at the code of the trigger sensor you should be able to understand how to do it. Take into account that the way I implemented it is a special case: it is a device_class door binary sensor and it is a sensor that is updated BOTH via callbacks from the bridge and polling via REST sensors.

You can create a simpler template trigger binary sensor, that is updated only by callback, and when called, you check the lock state (2 or 7) to turn it on/off. Or you could use this integration: The Lock state is represented by this attribute of the binary door sensor: state_attr('binary_sensor.nuki_door_state', 'lock_state'). If you check the code of the lock sensor, you will see that its state is retrieved by that attribute.

Thanks for the help! Yes I’ve seen the attribute, but for me it only updates from locked to unlocked (and vice versa).
It never reaches unlocking/unlatching (2/7). I’ve looked at the callback content and it seems like Nuki doesn’t send one on lock state change to 2/7, but rather it goes directly to 1 or 3. Seems like my use-case doesn’t work with the current callback logic.

I think the callback is done only on 1/3, check this log from the bridge: at 32:27 I do the unlock, at 32:31 the lock is completed, at 32:37 the callback is done. That means the callback is done only at the end of the action, so you will never receive the status changes you were looking for.

When you say paste the code above in the file templates.yaml, do i need to create such a file in the config directory? How do i reference it then in configuration.yaml?

You are right, I took for granted that every user knows how to better organize the config.yaml file when it becomes too complex, I’ll show you the end of my config.yaml, so you can understand what I mean in the instructions. Let me know if it’s clear.

automation: !include automations.yaml
climate: !include climate.yaml
group: !include groups.yaml
http: !include http.yaml
influxdb: !include influxdb.yaml
input_boolean: !include input_booleans.yaml
light: !include lights.yaml
lock: !include locks.yaml
logger: !include logger.yaml
panel_custom: !include panel_custom.yaml
rest_command: !include rest_commands.yaml
scene: !include scenes.yaml
sensor: !include sensors.yaml
script: !include scripts.yaml
switch: !include switches.yaml
template: !include templates.yaml
utility_meter: !include utility_meter.yaml
weather: !include weather.yaml
zha: !include zha.yaml

if i add this line (template: !include templates.yaml) i get this error, if i remove it all is good

Error loading /config/configuration.yaml: ‘utf-8’ codec can’t decode byte 0x91 in position 1210: invalid start byte

what do you have at line 1210? You probably have strange characters in config.yaml. Type it instead of copy&pasting the line. HA is telling you that there’s an illegal character in that position.

i figured it out, it ws the n´ in lock n´ go, it was written in ansi encoding and when i switched it to utf 8 , questionamarks appeared so i had to retype it.
Go figure

Maybe I’ll edit it to show a simple ' character.

DONE: renamed it to (lock 'n' go)

So everything is working as expected i can lock and unlock and get all the info, but the binary sensor does not get the updates via the webhook i guess.

I see this error in the logs

Logger: homeassistant.components.template
Source: components/webhook/__init__.py:36
Integration: Template (documentation, issues)
First occurred: 2:01:30 PM (1 occurrences)
Last logged: 2:01:30 PM

Error setting up trigger
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/webhook/trigger.py", line 40, in async_attach_trigger
    hass.components.webhook.async_register(
  File "/usr/src/homeassistant/homeassistant/components/webhook/__init__.py", line 36, in async_register
    raise ValueError("Handler is already defined!")
ValueError: Handler is already defined!

EDIT: At some point there was an update done and it showed the status right, but this is not instant

Hello !
I “replaced” the old configuration (like v2) with this new one (I did it yesterday, so the latest version)
everything works, but from time to time, I have these errors (and all the sensors no longer work)
did I do something wrong? what can i check?
thank you very much ^^

You are having communication problems with the bridge. Check its location, check the strength of the wifi signal of the bridge.

This leads me to think you are using the same webhook for other automations. An LT token can be used only for one trigger, probably you are using it also for something else. Double-check that.

You should not have those errors in the logs.

1 Like

You were right, i had set up a webhook in nodered to debug stuff with the lack and the callbacks. All is good now

Good to know it’s working fine also for you. :slight_smile:

Hi everybody,

After I discovered the packages functionality, I was smiling because I thought: “now finally I can put all the code of the Nuki Card in one file”. :slight_smile:

Unfortunately, after moving all the code to the single package file, I found out that the Template Trigger sensor is not supported in packages. :frowning:

There is a FR here with all details, I gently ask all users of this integration to please vote for it, it would really help simplify the configuration process and help new HA users.

Thanks for your help and support.

Alessandro

1 Like

Caro Alessandro,

thank you for this great work. I have a Nuki smart lock integrated in HA but was always unhappy with the very limited features. Your solution is a huge step forward. I am not yet very experienced in the HA world but I hope to get it up and running. Sorry for this beginner’s like question: where can I get the current versions of the yaml files for the Nuki Card (is there a GitHub repo?)
By the way: I totally share your love for Italian coffee (even if the Austrian football team will lose the Euro 2020 match an Saturday :wink:
best regards
Walter from Austria