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

Mike, I found a small bug regarding input_text.nuki_bridge_opener_ringaction_state, I updated the code to beta3, please test the ring action and let me know if you notice any change. Thanks.

I’m still thinking how to best solve the auto-reset after 30 secs…:slight_smile:

Ok, updated, rebootet HA. While RTO is on and ringing, the input_text goes to true and stays there (and the binary_sensor to on and stays there too). Normal behavior as with 11.2.

Yes, like I said, I’m still thinking how to solve the auto-reset after 30s. It was a small bug related to the update of the input_text.nuki_bridge_opener_ringaction_state when polled via /list. Thanks for the test.

Since I only have a couple of testers right now who provided feedback, and there were not major bugs, also in my local tests, I think I’ll release v11.

I also see no bigger problem, you can. Mainly (without the weakness of the bridge) it does what it should.
One stupid question, how do i unlatch the door in the house from an automation, i only find lock and unlock?

lock/unlock are the default actions of a lock template sensor. I adapted them to be configurable, so you decide which real action you want the lock/unlock buttons to execute. If you want to execute unlatch, just configure the appropriate action on the Nuki Card like this:

Then call the unlock action from the automation, the rest_command will execute the unlatch function on the Nuki Smart Lock.

If you want full control of the lock/unlock command externally, leveraging Nuki Card, then read this post: Nuki Card with Callback support (supports both Lock & Opener, it replaces the official integration) - #972 by alexdelprete

Mike, I spoke with Nuki devs, they told me that the callback not being sent after ringactionState turns off after 30s is by design. So the only way is auto-reset it after 30s. I published beta4 on gist, if you can test it and tell me if this autoreset is working, I will then finally publish v2.0 official. Thanks.

Trigger:

      - platform: state
        id: "trigger_nuki_opener_ring_action_state"
        entity_id: binary_sensor.nuki_opener_ring_action_state
        to: "on"
        for: "00:00:05"  

Action:

          - conditions: >
              {{ trigger.id == 'trigger_nuki_opener_ring_action_state' }}
            sequence:
              - service: input_text.set_value
                target:
                  entity_id: input_text.nuki_bridge_opener_ringaction_state
                data:
                  value: "off"

Hey. Really thanks for this, I like it.

Is there a way how to “filter out” all Nuki opener parts from the config? I suspect that I am getting a lot of errors because there are some Nuki opener stuff being executed on HA start (and I don’t have Nuki Opener - only keypad and lock):

2021-09-07 20:52:40 ERROR (MainThread) [homeassistant.components.rest.data] Error fetching data: http:// failed with The request to ':///' is missing either an 'http://'                         or 'https://' protocol.
2021-09-07 20:52:40 ERROR (MainThread) [homeassistant.components.rest.data] Error fetching data: http:// failed with The request to ':///' is missing either an 'http://'                         or 'https://' protocol.
2021-09-07 20:52:40 ERROR (MainThread) [homeassistant.components.rest.data] Error fetching data: http:// failed with The request to ':///' is missing either an 'http://'                         or 'https://' protocol.
2021-09-07 20:52:42 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-09-07 20:52:42 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-09-07 20:52:42 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-09-07 20:52:42 ERROR (MainThread) [homeassistant.components.binary_sensor] rpi_power: Error on device update!
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 431, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 633, in async_device_update
    await task
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/rpi_power/binary_sensor.py", line 42, in update
    self._is_on = self._under_voltage.get()
AttributeError: 'NoneType' object has no attribute 'get'
2021-09-07 20:52:42 WARNING (MainThread) [homeassistant.components.nmap_tracker.device_tracker] Your Nmap Tracker configuration has been imported into the UI, please remove it from configuration.yaml. 
2021-09-07 20:52:42 ERROR (MainThread) [homeassistant.components.device_tracker] Error setting up platform legacy nmap_tracker
2021-09-07 20:52:46 ERROR (MainThread) [homeassistant.components.openuv] Giving up _async_request(...) after 4 tries (aiohttp.client_exceptions.ClientResponseError: 403, message='Forbidden', url=URL('https://api.openuv.io/api/v1/uv?lat=50.11113738900304&lng=14.321984946727754&alt=150.0'))
2021-09-07 20:52:46 ERROR (MainThread) [homeassistant.components.openuv] Error during uv index data update: Invalid API key
2021-09-07 20:52:47 ERROR (MainThread) [homeassistant.components.openuv] Giving up _async_request(...) after 4 tries (aiohttp.client_exceptions.ClientResponseError: 403, message='Forbidden', url=URL('https://api.openuv.io/api/v1/protection?from=3.5&to=3.5&lat=50.11113738900304&lng=14.321984946727754&alt=150.0'))
2021-09-07 20:52:47 ERROR (MainThread) [homeassistant.components.openuv] Error during protection data update: Invalid API key
2021-09-07 20:52:48 WARNING (MainThread) [homeassistant.components.rest.sensor] JSON result was not a dictionary or list with 0th element a dictionary
2021-09-07 20:52:48 WARNING (MainThread) [homeassistant.components.rest.sensor] JSON result was not a dictionary or list with 0th element a dictionary
2021-09-07 20:52:48 ERROR (MainThread) [homeassistant.components.automation.nuki_card_callback] Nuki Card Callback: Choose at step 1: choice 2: Error executing script. Invalid data for call_service at pos 8: expected float for dictionary value @ data['value']
2021-09-07 20:52:48 ERROR (MainThread) [homeassistant.components.automation.nuki_card_callback] Nuki Card Callback: Error executing script. Invalid data for choose at pos 1: expected float for dictionary value @ data['value']
2021-09-07 20:52:48 ERROR (MainThread) [homeassistant.components.automation.nuki_card_callback] Error while executing automation automation.nuki_card_callback: expected float for dictionary value @ data['value']
2021-09-07 20:52:49 ERROR (MainThread) [homeassistant.components.automation.nuki_card_callback] Nuki Card Callback: Choose at step 1: choice 2: Error executing script. Invalid data for call_service at pos 8: expected float for dictionary value @ data['value']
2021-09-07 20:52:49 ERROR (MainThread) [homeassistant.components.automation.nuki_card_callback] Nuki Card Callback: Error executing script. Invalid data for choose at pos 1: expected float for dictionary value @ data['value']
2021-09-07 20:52:49 ERROR (MainThread) [homeassistant.components.automation.nuki_card_callback] Error while executing automation automation.nuki_card_callback: expected float for dictionary value @ data['value']
2021-09-07 20:52:54 WARNING (MainThread) [homeassistant.components.rest.sensor] JSON result was not a dictionary or list with 0th element a dictionary
2021-09-07 20:52:54 ERROR (MainThread) [homeassistant.components.automation.nuki_card_callback] Nuki Card Callback: Choose at step 1: choice 2: Error executing script. Invalid data for call_service at pos 8: expected float for dictionary value @ data['value']
2021-09-07 20:52:54 ERROR (MainThread) [homeassistant.components.automation.nuki_card_callback] Nuki Card Callback: Error executing script. Invalid data for choose at pos 1: expected float for dictionary value @ data['value']
2021-09-07 20:52:54 ERROR (MainThread) [homeassistant.components.automation.nuki_card_callback] Error while executing automation automation.nuki_card_callback: expected float for dictionary value @ data['value']
2021-09-07 20:52:54 ERROR (MainThread) [homeassistant.components.automation.nuki_card_callback] Nuki Card Callback: Choose at step 1: choice 2: Error executing script. Invalid data for call_service at pos 8: expected float for dictionary value @ data['value']
2021-09-07 20:52:54 ERROR (MainThread) [homeassistant.components.automation.nuki_card_callback] Nuki Card Callback: Error executing script. Invalid data for choose at pos 1: expected float for dictionary value @ data['value']
2021-09-07 20:52:54 ERROR (MainThread) [homeassistant.components.automation.nuki_card_callback] Error while executing automation automation.nuki_card_callback: expected float for dictionary value @ data['value']
2021-09-07 20:52:54 WARNING (MainThread) [homeassistant.components.rest.sensor] JSON result was not a dictionary or list with 0th element a dictionary
2021-09-07 20:53:16 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'click' when rendering '{{ value_json.click }}'

I am on v11 beta 3

Those REST calls are made even without the Opener. With 2 REST calls, the bridge answers with the staus of all devices, not specifically for one.

2021-09-07 20:52:40 ERROR (MainThread) [homeassistant.components.rest.data] Error fetching data: http:// failed with The request to ':///' is missing either an 'http://'                         or 'https://' protocol.
2021-09-07 20:52:40 ERROR (MainThread) [homeassistant.components.rest.data] Error fetching data: http:// failed with The request to ':///' is missing either an 'http://'                         or 'https://' protocol.
2021-09-07 20:52:40 ERROR (MainThread) [homeassistant.components.rest.data] Error fetching data: http:// failed with The request to ':///' is missing either an 'http://'                         or 'https://' protocol.
2021-09-07 20:52:42 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-09-07 20:52:42 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-09-07 20:52:42 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

This is normal, the REST sensors are not initialized when HA restarts, but they do get initialized asynchronously some seconds after. You can safely ignore those.

2021-09-07 20:52:42 WARNING (MainThread) [homeassistant.components.nmap_tracker.device_tracker] Your Nmap Tracker configuration has been imported into the UI, please remove it from configuration.yaml. 
2021-09-07 20:52:42 ERROR (MainThread) [homeassistant.components.device_tracker] Error setting up platform legacy nmap_tracker
2021-09-07 20:52:46 ERROR (MainThread) [homeassistant.components.openuv] Giving up _async_request(...) after 4 tries (aiohttp.client_exceptions.ClientResponseError: 403, message='Forbidden', url=URL('https://api.openuv.io/api/v1/uv?lat=50.11113738900304&lng=14.321984946727754&alt=150.0'))
2021-09-07 20:52:46 ERROR (MainThread) [homeassistant.components.openuv] Error during uv index data update: Invalid API key
2021-09-07 20:52:47 ERROR (MainThread) [homeassistant.components.openuv] Giving up _async_request(...) after 4 tries (aiohttp.client_exceptions.ClientResponseError: 403, message='Forbidden', url=URL('https://api.openuv.io/api/v1/protection?from=3.5&to=3.5&lat=50.11113738900304&lng=14.321984946727754&alt=150.0'))
2021-09-07 20:52:47 ERROR (MainThread) [homeassistant.components.openuv] Error during protection data update: Invalid API key
2021-09-07 20:52:48 WARNING (MainThread) [homeassistant.components.rest.sensor] JSON result was not a dictionary or list with 0th element a dictionary
2021-09-07 20:52:48 WARNING (MainThread) [homeassistant.components.rest.sensor] JSON result was not a dictionary or list with 0th element a dictionary

These are not related to Nuki Card.

2021-09-07 20:52:48 WARNING (MainThread) [homeassistant.components.rest.sensor] JSON result was not a dictionary or list with 0th element a dictionary
2021-09-07 20:52:48 WARNING (MainThread) [homeassistant.components.rest.sensor] JSON result was not a dictionary or list with 0th element a dictionary
2021-09-07 20:52:48 ERROR (MainThread) [homeassistant.components.automation.nuki_card_callback] Nuki Card Callback: Choose at step 1: choice 2: Error executing script. Invalid data for call_service at pos 8: expected float for dictionary value @ data['value']
2021-09-07 20:52:48 ERROR (MainThread) [homeassistant.components.automation.nuki_card_callback] Nuki Card Callback: Error executing script. Invalid data for choose at pos 1: expected float for dictionary value @ data['value']
2021-09-07 20:52:48 ERROR (MainThread) [homeassistant.components.automation.nuki_card_callback] Error while executing automation automation.nuki_card_callback: expected float for dictionary value @ data['value']
2021-09-07 20:52:49 ERROR (MainThread) [homeassistant.components.automation.nuki_card_callback] Nuki Card Callback: Choose at step 1: choice 2: Error executing script. Invalid data for call_service at pos 8: expected float for dictionary value @ data['value']
2021-09-07 20:52:49 ERROR (MainThread) [homeassistant.components.automation.nuki_card_callback] Nuki Card Callback: Error executing script. Invalid data for choose at pos 1: expected float for dictionary value @ data['value']
2021-09-07 20:52:49 ERROR (MainThread) [homeassistant.components.automation.nuki_card_callback] Error while executing automation automation.nuki_card_callback: expected float for dictionary value @ data['value']
2021-09-07 20:52:54 WARNING (MainThread) [homeassistant.components.rest.sensor] JSON result was not a dictionary or list with 0th element a dictionary
2021-09-07 20:52:54 ERROR (MainThread) [homeassistant.components.automation.nuki_card_callback] Nuki Card Callback: Choose at step 1: choice 2: Error executing script. Invalid data for call_service at pos 8: expected float for dictionary value @ data['value']
2021-09-07 20:52:54 ERROR (MainThread) [homeassistant.components.automation.nuki_card_callback] Nuki Card Callback: Error executing script. Invalid data for choose at pos 1: expected float for dictionary value @ data['value']
2021-09-07 20:52:54 ERROR (MainThread) [homeassistant.components.automation.nuki_card_callback] Error while executing automation automation.nuki_card_callback: expected float for dictionary value @ data['value']
2021-09-07 20:52:54 ERROR (MainThread) [homeassistant.components.automation.nuki_card_callback] Nuki Card Callback: Choose at step 1: choice 2: Error executing script. Invalid data for call_service at pos 8: expected float for dictionary value @ data['value']
2021-09-07 20:52:54 ERROR (MainThread) [homeassistant.components.automation.nuki_card_callback] Nuki Card Callback: Error executing script. Invalid data for choose at pos 1: expected float for dictionary value @ data['value']
2021-09-07 20:52:54 ERROR (MainThread) [homeassistant.components.automation.nuki_card_callback] Error while executing automation automation.nuki_card_callback: expected float for dictionary value @ data['value']
2021-09-07 20:52:54 WARNING (MainThread) [homeassistant.components.rest.sensor] JSON result was not a dictionary or list with 0th element a dictionary

These are related to Nuki Card, and it means that a REST call has failed. It can happen, but if it happens too often, it means you have a specific issue with the communication with the bridge. Can’t telly you why it failed though.

Can you show me the list of sensors in the lovelace card? Want to check which worked and which didn’t.

I see you’re running on an RPi…and that you have a lot of errors, not only related to Nuki Card…are you sure the system works ok? Is it powerful enough for HA? I had awful experience with RPi and HA untortunately.

Installed and mainly it works.
First Question, the state of the input_text is normally True or False, now it is off, is that right?
Second you should set the for in the trigger to 30 seconds (the time the ringaction stays on in the nuki). As i tried with open house door ringing, the state of the ringaction went back to on as i closed the house door, i think there was another callback which sended the ringing state as it still was on. So in HA it looks like it rang twice. If the for: is 30 seconds this couldnt happen i think.
But that’s all, looks like you can publish V2.0 soon :wink:

Hey! Thanks for a quick support, I really appreciate it and am grateful :bowing_man: .

These are related to Nuki Card, and it means that a REST call has failed. It can happen, but if it happens too often, it means you have a specific issue with the communication with the bridge. Can’t telly you why it failed though.

My network is pretty good so I am fairly surprised and not sure what could be wrong (I didn’t really touch bridge since it came from Nuki).

Can you show me the list of sensors in the lovelace card? Want to check which worked and which didn’t.

type: entities
entities:
  - entity: sensor.nuki_lock_friendly_name
  - entity: lock.nuki_lock_action
    secondary_info: last-updated
  - entity: binary_sensor.nuki_door_state
    secondary_info: last-updated
  - entity: binary_sensor.nuki_bridge_callback
    secondary_info: last-updated
  - entity: sensor.nuki_lock_last_update
  - entity: input_select.nuki_choose_lock_action
  - entity: input_select.nuki_choose_unlock_action
  - entity: sensor.nuki_bridge_fw_version
  - entity: sensor.nuki_bridge_wifi_fw_version
  - entity: binary_sensor.nuki_bridge_wifi_connected
  - entity: binary_sensor.nuki_bridge_cloud_connected
  - entity: sensor.nuki_lock_id
  - entity: sensor.nuki_lock_device_name
  - entity: binary_sensor.nuki_lock_bridge_bt_state
  - entity: sensor.nuki_lock_bridge_bt_rssi
  - entity: sensor.nuki_lock_battery_level
  - entity: sensor.nuki_lock_fw_version
  - entity: binary_sensor.nuki_lock_battery_critical_state
  - entity: binary_sensor.nuki_keypad_battery_critical_state
state_color: true
title: Nuki Card

I see you’re running on an RPi…and that you have a lot of errors, not only related to Nuki Card…are you sure the system works ok? Is it powerful enough for HA? I had awful experience with RPi and HA unfortunately.

How do you know it? :smiley: It’s actually not on RPi anymore, it’s on a 8GB ThinkPad with SSD and fairly strong i5, so I doubt it is an issue.

No problem.

Well, I don’t know if it happened only one time or it happens often. In the latter case, we have to investigate. :slight_smile:

I meant a screenshot of the card in lovelace, I know the code of the card, it’s in the first post. :slight_smile:

Good that you moved HA from the RPi. I know it from your logs, there is rpi in some lines. :slight_smile:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 431, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 633, in async_device_update
    await task
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/rpi_power/binary_sensor.py", line 42, in update
    self._is_on = self._under_voltage.get()
AttributeError: 'NoneType' object has no attribute 'get'

for a binary sensor, off/false and on/true are equivalent. but you know what, we should use an input_boolean instead, to shadow that sensor. So it’s more consistent, even if input_text works anyway. I’ll think about it.

Correct, I’ll modify it. Thanks.

Oh, yeah, sorry for that rubbish around RPi, I have removed the power sensor already.

Here is the screenshot

Looks like it’s working fine, doesn’t it? :slight_smile:

It does indeed. I am just trying to clean up the log + provide feedback on testing this.

I’m sorry, I misunderstood your initial post, thinking it didn’t work. :slight_smile:

Unfortunately the bridge is the weak point of the Nuki system: its hw is very limited, and it can only process one request at a time, that means that if 2 requests arrive at the same time (from the mobile app, or cloud, automation, etc.) only one is served, the others receive an HTTP error 503.

I implemented a queue mechanism to put all Nuki Card requests in a queue with a 1s delay, but I can’t prevent other apps that I can’t control sending requests to the bridge. So occasionally you will see errors in the log unfortunately.

Ah, I see, that’ annoying from Nuki Bridge :roll_eyes: (like, 3$ devices can handle multiple requests)… Thanks for the explanation though and all your hard work. Just for the records, I see these errors every time I restart HA.

the REST error “///” is normal, at every restart. The other errors/warnings should not happen often, only when the bridge doesn’t process the request. Anyway, I never see HA systems with zero warnings/errors in the log. The important thing is that generally everything’s working.

Nuki Card v11.0 released: finally added support for the Opener, highly requested feature. Improved refresh times for some sensors. Fixed some bugs.

Thanks in particular to @madface for testing the Opener integration.

Hope to receive feedbacks from the opener users. :slight_smile:

1 Like

Thanks a lot for your work Alex ! It’s working great for both my opener and my lock. Have there been any changes from beta 4 to public v11.0?

1 Like