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

You either have an old version of the bridge firmware or you re having communication problems from HA to the bridge.

Please report firmware version first. Then issue that curl list command from a terminal to see how the bridge answers: http://192.168.1.47:8080/callback/list?&token=ucqbkj

Alessandro, Thank again for your support. Firmware is 2.9.3 and return for the command is
|callbacks||
|0||
|id|0|
|url|unknown|

Hi Alessandro,

Just an update from my PM, using the lock for unlock or lock, causes a warning in the log:

Logger: homeassistant.components.automation.nuki_card_callback
Source: helpers/script.py:1344
Integration: Automatisering (documentation, issues)
First occurred: 14:24:30 (2 occurrences)
Last logged: 14:25:30

Nuki Card Callback: Already running

It’s a warning, not an error, it happens when the automation is triggered by two events in parallel. But I configured mode: single, so it prevents the parallel execution but issues the warning. I will optimize it, but for now I’m concentrated on making it work stable.

A solution might be setting the automation mode to queued and max it to 2 or so, see Automation Modes - Home Assistant

Nope, I already thought about that, it will create problems. We have to serialize the execution. Single is good, but it issues that warning. No big deal.

When using queued, the automations are serialized as far as I know, because the next one will start after the first one has ended instead of restart, then the running one will be ended and the newly triggerd one will start.

Are you sure that’s the fw of the bridge and not the lock?

The output of the command doesn’t make sense, did you run curl from a terminal? Try this command:

curl -X GET -H “Content-Type: application/json” ‘http://bridge-ip:8080/list?token=xxxxx

the output should see something like this:

[{“deviceType”: 0, “nukiId”: 469204325, “name”: “Porta Casa Fiano”, “firmwareVersion”: “2.11.1”, “lastKnownState”: {“mode”: 2, “state”: 3, “stateName”: “unlocked”, “batteryCritical”: false, “batteryCharging”: false, “batteryChargeState”: 54, “keypadBatteryCritical”: false, “doorsensorState”: 2, “doorsensorStateName”: “door closed”, “timestamp”: “2021-07-23T10:23:34+00:00”}}]

If you see nothing in output, you have no communication with the bridge, or you didn’t enable the API in the app, but you should because I see you have a token.

You can also use “max_exceeded: silent” in the automation, then these messages will be ignored

You are right, I was thinking at the parallel option. I will think about it…have to do some tests first…

Unfortunately, I discovered in last 2 days that the bridge resets itself and reboots often, even if you send no commands, I think it does it when it loses communication with the lock, or for some scheduled events. If you send commanda in those 5-10 secs, you have no return info, and that’s a problem. I’ve tried to make the automation as resilient as possible for these events, but obviously there are drawbacks. I’ll optimize when I know it’s working pretty stable. Thanks for the hint on queued. :slight_smile:

Alessandro, Firmware is what HA reports in Nuki Bridge FW Version. Output of the last command is
|0||
|deviceType|0|
|nukiId|422231005|
|name|Schleiferberg|
|firmwareVersion|2.10.8|
|lastKnownState||
|mode|2|
|state|3|
|stateName|unlocked|
|batteryCritical|false|
|batteryCharging|false|
|batteryChargeState|64|
|doorsensorState|2|
|doorsensorStateName|door closed|
|timestamp|2021-07-23T11:33:54+00:00|

getting this additional error as well
Logger: homeassistant.components.automation.nuki_card_callback
Source: components/automation/init.py:517
Integration: Automation (documentation, issues)
First occurred: 2:19:09 PM (14 occurrences)
Last logged: 2:45:09 PM

Error while executing automation automation.nuki_card_callback: Error rendering data template: JSONDecodeError: Expecting value: line 1 column 1 (char 0)

I think then using the “max_exeeded: silent” option is best to use instead of queued, it keeps everything running as is now, without adding entries to the log.

Have you tried restarting HA. I have seen the same errors in the log as you, after a restart of HA, they disappeared.

Ok, so the basics are there, so you see the card populated with info of the sensors right? Can you show me the screenshot of the card with all the sensors please?

2021-07-23 14:09:09 ERROR (MainThread) [homeassistant.components.rest.data] Error fetching data: http://192.168.1.47:8080/callback/list?&token=ucqbkj failed with illegal status line: bytearray(b’155’)

2021-07-23 14:09:09 WARNING (MainThread) [homeassistant.components.rest.sensor] Empty reply found when expecting JSON data

these are communication errors, the rest sensors called the urls and received bad or no data in return…strange. I have to check if the automation is calling the bridge too often…

I just did restart just to be shure (the last restart I did after addibg the patch)


In the moment no errors in HA log except for the warning of nuki card running already

Is the callback working? when you open the door or action the lock, you see the update quickly?

I’ll check all these options tonight, want to read the details first. thanks a lot for the help.

when I opened the door no status change on card but the following error in log
Logger: homeassistant.components.rest.data
Source: components/rest/data.py:69
Integration: RESTful (documentation, issues)
First occurred: 3:09:32 PM (1 occurrences)
Last logged: 3:09:32 PM

Error fetching data: http://192.168.1.47:8080/list?&token=ucqbkj failed with illegal status line: bytearray(b’155’)
and the following notification

another error came up
Logger: homeassistant.helpers.template
Source: helpers/template.py:1366
First occurred: 3:11:31 PM (5 occurrences)
Last logged: 3:11:31 PM

Template variable warning: 'None' has no attribute 'batteryCritical' when rendering '{% if states('sensor.nuki_bridge_endpoint_list') == "OK" %} {{ state_attr('sensor.nuki_bridge_endpoint_list','lastKnownState')['batteryCritical'] }} {% endif %}'
Template variable warning: 'None' has no attribute 'timestamp' when rendering '{% if states('sensor.nuki_bridge_endpoint_list') == "OK" %} {{ (as_timestamp(state_attr('sensor.nuki_bridge_endpoint_list','lastKnownState')['timestamp'])) | timestamp_custom("%H:%M:%S (%b %d)") }} {% endif %}'
Template variable warning: 'None' has no attribute 'batteryCharging' when rendering '{% if states('sensor.nuki_bridge_endpoint_list') == "OK" %} {% set battery_level = state_attr('sensor.nuki_bridge_endpoint_list', 'lastKnownState')['batteryChargeState'] | default(0) | int %} {% if state_attr('sensor.nuki_bridge_endpoint_list', 'lastKnownState')['batteryCharging'] %} {{ battery_level }} {% else %} {{ battery_level }} {% endif %} {% endif %}'
Template variable warning: dict object has no element Undefined when rendering '{% if states('sensor.nuki_bridge_endpoint_list') == "OK" %} {% set my_state = {1: 'deactivated', 2: 'closed', 3: 'open', 4: 'unknown', 5: 'calibrating'} %} {{ my_state[state_attr('sensor.nuki_bridge_endpoint_list', 'lastKnownState')['doorsensorState']] }} {% endif %}'
Template variable warning: dict object has no element Undefined when rendering '{% if states('sensor.nuki_bridge_endpoint_list') == "OK" %} {% set my_state = {0: 'uncalibrated', 1: 'locked', 2:'unlocking', 3: 'unlocked', 4: 'locking', 5: 'unlatched', 6: "unlocked (lock ‘n’ go)", 7: 'unlatching', 254: 'motor blocked', 255: 'undefined'} %} {{ my_state[state_attr('sensor.nuki_bridge_endpoint_list', 'lastKnownState')['state']] }} {% endif %}'