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

  1. The tokens you showed are not the same
  2. in the second screenshot, the token is disabled. Where did you get this screenshot? What section of HA?

image

The Long-Lived Tokens are created here, it’s a section of the Profile page:

image

I don’t know where are you creating it…

Hey, I created it exactly there. The other one is under: settings, home assistant cloud, scroll down and there is a webhook section. When I create the long lived token, this is created automatically. I used the long lived access token. But again, it will not work.

Right. But the string shown there should be the same as the webhook. Just when you enable the hook there, a string with gAAAAA is generated or shown.

btw: this has nothing to do with what we are trying to archive here. This webhook can be enabled for using it with Nabu Casa.

Hi Allessandro,
I had a look to Peters HA with teamviewer, just to rule out he configured it wrong.
As far I could see everything is okay, but to be sure we generated a new LL and also pasted the code again to nuki_card_callback.yaml
After a restart he gets this:

Logger: homeassistant.components.rest.sensor
Source: components/rest/sensor.py:177
Integration: RESTful (documentation, issues)
First occurred: 11:28:06 (1 occurrences)
Last logged: 11:28:06

REST result could not be parsed as JSON
Logger: homeassistant.helpers.template
Source: helpers/template.py:1417
First occurred: 11:28:06 (1 occurrences)
Last logged: 11:28:06

Template variable error: 'value_json' is undefined when rendering '{% set ns = namespace() %} {% set ns.callback_list = [] %} {% if (value_json.callbacks | count) > 0 %} {% set hook = states('input_text.nuki_bridge_callback_url') %} {% for callback in value_json.callbacks %} {% if hook == (callback.url|urlencode) %} {% set ns.callback_list = ns.callback_list + [ callback.id ] %} {% endif %} {% endfor %} {% endif %} {{ ns.callback_list }}'

I am getting mad/stupid
Worked before now not.
I have successfull cals on nuki’s side (web ui log)
OnHa side however several sensors are not defined (door status etc)


In the log if I add the yaml I have this:

2021-08-08 12:00:18 WARNING (MainThread) [homeassistant.components.sensor] Platform rest not ready yet: The request to ':///' is missing either an 'http://'                         or 'https://' protocol.; Retrying in background in 30 seconds
2021-08-08 12:00:18 WARNING (MainThread) [homeassistant.components.sensor] Platform rest not ready yet: The request to ':///' is missing either an 'http://'                         or 'https://' protocol.; Retrying in background in 30 seconds
2021-08-08 12:00:18 WARNING (MainThread) [homeassistant.components.sensor] Platform rest not ready yet: The request to ':///' is missing either an 'http://'        

furthermore the sensors from where the data is populated seem to be populated:

This means the REST call got strange result back from the bridge, it was not a valid JSON structure.

It can happen, but if it ALWAYS happens, there’s a problem.

Did you check on the bridge if the callback was configured? because even if the callback sensor doesn’t work, you can make the integration work by adding the callback manually on the bridge, Nuki Card will receive it and update the sensor.

I made the callback sensor just to autoconfigure and check the bridge config, but you can always configure it manually. The important thing is that the callbacks are sent by the bridge and that Nuki Card receives them.

Just trigger a callback, locking/unlocking or opening/closing the door manually, and the sensors should refresh.

Does it do it every time you restart HA?

2021-08-08 12:00:18 WARNING (MainThread) [homeassistant.components.sensor] Platform rest not ready yet: The request to ':///' is missing either an 'http://'                         or 'https://' protocol.; Retrying in background in 30 seconds
2021-08-08 12:00:18 WARNING (MainThread) [homeassistant.components.sensor] Platform rest not ready yet: The request to ':///' is missing either an 'http://'                         or 'https://' protocol.; Retrying in background in 30 seconds
2021-08-08 12:00:18 WARNING (MainThread) [homeassistant.components.sensor] Platform rest not ready yet: The request to ':///' is missing either an 'http://'

This is normal when you restart HA, it depends on how fast the hw platform is, sometimes the REST sensor is called before its configuration, but it’s not a problem, it’s a warning. I have it too…but only one line, not three. But I’m running on a powerful intel NUC. Do you use it on a RPi?

Nope, I didn’t. Maybe you can post the command for checking and adding a callback manually, so Peter can try.
Another question: does Nuki Web have to be enabled?

I posted it several times to Peter above. Here it is:

curl -X GET 'http://nuki-bridge.axel.dom:8080/callback/list?token=xxxxxx

This to remove the callback (make sure ID is correct):

curl -X GET 'http://nuki-bridge.axel.dom:8080/callback/remove?id=0&token=xxxxx'

This to add a callback:

curl -X GET 'http://nuki-bridge.axel.dom:8080/callback/add?url=HA_WEBHOOK_COMPLETE_URL&token=xxxxx'

Not necessary, the Nuki Card uses the Bridge API, that one must be activated:

But if he has the token, it means he activated it.

Thank for clarifying.

no i use a pc

I went in and out of home and now notice the following:

A failure in the logs with a 408 code and i did not notice if there was as usual an autounlock with the iphone

Good catch, I notice the web logs are far more detailed, never used those, I will in the future.

When http calls from Nuki Card fail, it’s because there’s some other http call from another app/sw, either the official integration, or the Nuki App on the mobile, or whatever. Try to minimize this, because the bridge is limited, it can process only one call at a time and doesn’t have a queue. So if it’s processing an http request, the other will fail.

1 Like

Keep in mind that I had him enable debug for webhook. And he told me that HA wrote that the webhook was not registered. That means the LL token configured on the bridge is not the one configured in HA.

ok, so it’s fast, and it tries to initialize all 3 REST sensors before they’re configured. Unfortunately I can’t do anything for that: the startup of HA can lead to warnings like that.

The only solution I thought of is not use REST sensors anymore and just use command_line with curl, so I have total control and don’t have to worry of the startup phase of HA.

I am struggling .
Is there a simple way to “reset” everything to initial state ?
Delete the WebHook in ha
reset auth in nuki.
In short start from scratch

ty / grazie

Hey Ale, I checked the Callback with the Hook. They were different. So

  1. I deleted it with the Curl (curl -X GET ‘http://nuki-bridge.axel.dom:8080/callback/remove?id=0&token=xxxxx’)
  2. HA restart
  3. check for Callback with curl -X GET 'http://nuki-bridge.axel.dom:8080/callback/list?token=xxxxxx

(I did 2 + 3 two times to be sure)

RESULT: No new Callback generated.
Peter

Remove the webhook on the bridge: http://nuki-bridge.axel.dom:8080/callback/remove?id=0&token=xxxxx
Restart HA, the Nuki Card should then check that the bridge has no callback configured and add it back, that’s it.

Don’t know why you refer to nuki auth…that is only needed to activate the API, once it’s activated, and you have a token, you’re ok. In any case, you can disable and re-enable from the Nuki mobile app.

1 Like