Using Nuki Lock 3.0 Fully Local without Bridge

This is what the terminal shows:

That output shouldn’t show all that connections. Don’t you have something else running on that port so the bridge server can’t start?

Run

docker ps | grep nuki

Post the output so we can check the port mapping.

Also you can change the port of the addon to something different. I have mine running on 8087 and try the pair the integration again.

I will try another port aswell

port 8088

Hey guys, I’m on the same boat here.

Home Assistant 2022.12.8
Supervisor 2022.12.1
Operating System 9.4
Frontend-versie: 20221213.1 - latest

In the log of the nuki virtual bridge it says service is running on http://0.0.0.0:8080. Doesn’t change when changing ports either.

If anything needed to help out, let me know.

@DevoEvoLevo that’s because it is running in a docker container, which uses port mapping between the container and the host. The bridge runs on the 8080 and is not aware of that mapping. Docker then maps the specified port on the config to the internal port. So connections received on the container’s external portl, et’s say port 8087, will be redirected to the 8080 internal port.

Also further debugging steps would be:

  1. Get a shell into the container with docker exec -it <container_name> bash and run python3 /opt/main.py --lock. The file may be named differently so check the existing files in the /opt die.
    This should lock the Nuki Lock

  2. Call the addon using curl and passing thr bridge token.

The Nuki-Bridge container?

Yes, the ome returned by docker ps

This is the output of the terminal after the lock command, but the lock is still unlocked.

Ok so now we knoeñw the problem is with the bridge itself we can take HA and network issues out of the equation. I’ve been reading the code and that error originates when calling a command and the queue has not started, which makes me think that the pairing was not successfull. Few things:

  1. Which Nuki Lock do you have?
  2. Do you have multiple Locks or Nuki devices?
  3. Were there any other erros during the add-on installation? Please re-install it from scratch and post any other errors.

I saw you opened an issue in the addon’s Github repo and that’s were this discussion should be addressed since we know now it’s not a problem related to HA. Although let’s try to fix it here.

Thank you for the support and your patience. I will install everything new this evening, when I am at home.

I hope Im not interfering with @Daniel76 here.

So I configured the add-on Virtual Nuki Bridge. Followed the steps in the documentation and the log shows no error regarding connection to Nuki device over Bluetooth. Sends and receives.

When using one of the two integrations I try to use the IP for localhost and include the port as set up in the add on: http://127.0.0.1:8087

In the logs I find the following error.

Failed to get list of devices from bridge: HTTPConnectionPool(host='127.0.0.1', port=80): Max retries exceeded with url: /info?token=xxx (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f667524a530>: Failed to establish a new connection: [Errno 111] Connection refused'))
Failed to get list of devices from bridge: HTTPConnectionPool(host='http', port=80): Max retries exceeded with url: //127.0.0.1:80/info?token=xxxx (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f6674e1cd30>: Failed to establish a new connection: [Errno -2] Name does not resolve'))
Failed to get list of devices from bridge: HTTPConnectionPool(host='http', port=80): Max retries exceeded with url: //127.0.0.1:8087/info?token=xxx (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f6674b42290>: Failed to establish a new connection: [Errno -2] Name does not resolve'))

To show the configuration running on the add on see here:


-----------------------------------------------------------
 Add-on: Nuki Bridge
 Virtual Nuki Bridge to use instead of the physical device
-----------------------------------------------------------
 Add-on version: 0.0.23
 You are running the latest version of this add-on.
 System: Home Assistant OS 9.4  (amd64 / generic-x86-64)
 Home Assistant Core: 2022.12.8
 Home Assistant Supervisor: 2022.12.1
-----------------------------------------------------------
 Please, share the above information when looking for help
 or support in, e.g., GitHub, forums or the Discord chat.
-----------------------------------------------------------
[cont-init.d] 00-banner.sh: exited 0.
[cont-init.d] 01-log-level.sh: executing... 
[cont-init.d] 01-log-level.sh: exited 0.
[cont-init.d] done.
[services.d] starting services
[services.d] done.
2023-01-02 19:50:36.888|I|config.py:72|********************************************************************
2023-01-02 19:50:36.888|I|config.py:73|*                                                                  *
2023-01-02 19:50:36.888|I|config.py:74|*                            Access Token                          *
2023-01-02 19:50:36.888|I|config.py:75|* xxxxxxxxx *
2023-01-02 19:50:36.889|I|config.py:76|*                                                                  *
2023-01-02 19:50:36.889|I|config.py:77|********************************************************************
2023-01-02 19:50:36.896|I|nuki.py:254|Waiting for more tasks with timeout
======== Running on http://0.0.0.0:8080 ========
(Press CTRL+C to quit)
2023-01-02 19:50:46.907|I|nuki.py:258|No more tasks - cleaning up
2023-01-02 19:50:46.908|I|nuki.py:181|Starting a scan
2023-01-02 19:50:46.908|I|nuki.py:184|Scanning attempt 1
2023-01-02 19:50:46.989|I|nuki.py:186|Scanning succeeded on attempt 1
2023-01-02 19:50:46.989|I|nuki.py:267|Waiting for next task
2023-01-02 19:50:49.201|I|nuki.py:221|Nuki: 54:D2:72:BA:19:EC, adapter: hci0, RSSI: -51 AdvertisementData(local_name='Nuki_2EBA19EC', manufacturer_data={76: b'\x02\x15\xa9.\xe2\x00U\x01\x11\xe4\x91l\x08\x00 \x0c\x9af.\xba\x19\xec\xc8'}, service_data={'a92ee100-5501-11e4-916c-0800200c9a66': b'.\xba\x19\xec'}, service_uuids=['0000003e-0000-1000-8000-0026bb765291', '00000044-0000-1000-8000-0026bb765291', '00000045-0000-1000-8000-0026bb765291', '00000055-0000-1000-8000-0026bb765291', '00000096-0000-1000-8000-0026bb765291', '000000a2-0000-1000-8000-0026bb765291', '00001800-0000-1000-8000-00805f9b34fb', '0000180a-0000-1000-8000-00805f9b34fb', 'a92ee100-5501-11e4-916c-0800200c9a66', 'a92ee200-5501-11e4-916c-0800200c9a66'])
2023-01-02 19:50:49.203|I|nuki.py:198|Stop scanning
2023-01-02 19:50:49.222|I|nuki.py:201|Scanning stopped
2023-01-02 19:50:49.223|I|nuki.py:275|Working on task
2023-01-02 19:50:49.223|I|nuki.py:676|Nuki connecting
2023-01-02 19:50:52.012|I|nuki.py:367|Device type: DeviceType.SMARTLOCK_1_2
2023-01-02 19:50:52.078|I|nuki.py:688|Connected
2023-01-02 19:50:52.078|I|nuki.py:277|Finished task
2023-01-02 19:50:52.079|I|nuki.py:254|Waiting for more tasks with timeout
2023-01-02 19:50:52.080|I|nuki.py:701|Querying Nuki state
2023-01-02 19:50:52.081|I|nuki.py:275|Working on task
2023-01-02 19:50:52.082|I|nuki.py:642|Trying to send data. Attempt 1
2023-01-02 19:50:52.082|I|nuki.py:674|Connected
2023-01-02 19:50:52.082|I|nuki.py:647|Sending data to a92ee202-5501-11e4-916c-0800200c9a66: b'c\x1bY\xde\xe0\xb8\xc9\xe5\xeb#\xc6_J\xc8\xbc\x18\xb0\xac\xffF\xf8\x9d\\\xd6\xe6\\4\x00\x1a\x00\xf4\xaa!J\x8f\xee\t1\xd2(\xf7\x90\x98\x04\x8e\xab.)\x96"vB~\xdd\xcc\xcc'
2023-01-02 19:50:52.106|I|nuki.py:657|Data sent on attempt 1
2023-01-02 19:50:52.107|I|nuki.py:277|Finished task
2023-01-02 

Some details:

  • Using a Unifi Network application on port 8080, hence my config change to 8087.
  • I retried installing the add-on and thus repairing the nuki. It seems connected and functioning as expected.

I hope you can give me any lead on what’s next…

Hey @DevoEvoLevo,

:warning::warning:GUYS PLEASE DON’T POST YOUR BRIDGE API TOKEN SINCE ANYONE WITH THAT TOKEN COULD INTERACT DIRECTLY WITH THE LOCK. It’s like giving someone the key of your house.
Either trim the key or redact it!
I realize the author of the addon should have written a note about that.

Looks like the bridge is working correctly, it must be an IP problem between the integration and the addon. If you are running HA Docker or Supervisor you will need to use the IP without the port of the container. In my original post there is a command on how to get the IP.
This is the command to find the container IP:

docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker ps --format '{{.Names}}' | grep nuki)

If you specify an IP <bridge_ip>, by default the integrations will try to connect to <bridge_ip>:8080

You don’t need the port because containers communicate through their internal ports and not the external ones.

If you have HAOS and changed the port you will need to specify the loopback IP and the port ONLY if you changed it. In your case 127.0.0.1:8087

TL;DR: The IP will depend on your HA installation: 1. Use 127.0.0.1:8087 if HAOS
2. Use <container_ip> without port if Docker or Supervisor

Thanks for your reply. Let me check it out.

To be fair, the authorization key might be usable but it changes and is Bluetooth connection only. So I really didn’t think it would be an issue and just posted it.

When using the web connected nuki or in general, yes you’re definitely right. Redacted !

Thanks again for helping out.

So I’m using:

Home Assistant 2022.12.8
Supervisor 2022.12.1
Operating System 9.4
Frontend-versie: 20221213.1 - latest

It’s installed on a NUC.

Therefore I configured as followed:
http://127.0.0.1

Sadly it’s still refusing connection:


Deze fout is ontstaan door een aangepaste integratie.

Logger: custom_components.nuki_ng.config_flow
Source: custom_components/nuki_ng/nuki.py:78 
Integration: Nuki Lock (documentation, issues) 
First occurred: 20:28:29 (1 occurrences) 
Last logged: 20:28:29

Failed to get list of devices from bridge: HTTPConnectionPool(host='http', port=80): Max retries exceeded with url: //127.0.0.1:8080/info?token=redacted (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f6673502680>: Failed to establish a new connection: [Errno -2] Name does not resolve'))
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/urllib3/connection.py", line 174, in _new_conn
    conn = connection.create_connection(
  File "/usr/local/lib/python3.10/site-packages/urllib3/util/connection.py", line 72, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "/usr/local/lib/python3.10/socket.py", line 955, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name does not resolve

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 398, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/local/lib/python3.10/site-packages/urllib3/connection.py", line 239, in request
    super(HTTPConnection, self).request(method, url, body=body, headers=headers)
  File "/usr/local/lib/python3.10/http/client.py", line 1282, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/local/lib/python3.10/http/client.py", line 1328, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.10/http/client.py", line 1277, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.10/http/client.py", line 1037, in _send_output
    self.send(msg)
  File "/usr/local/lib/python3.10/http/client.py", line 975, in send
    self.connect()
  File "/usr/local/lib/python3.10/site-packages/urllib3/connection.py", line 205, in connect
    conn = self._new_conn()
  File "/usr/local/lib/python3.10/site-packages/urllib3/connection.py", line 186, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f6673502680>: Failed to establish a new connection: [Errno -2] Name does not resolve

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/requests/adapters.py", line 489, in send
    resp = conn.urlopen(
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 787, in urlopen
    retries = retries.increment(
  File "/usr/local/lib/python3.10/site-packages/urllib3/util/retry.py", line 592, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='http', port=80): Max retries exceeded with url: //127.0.0.1:8080/info?token=94649fc705cf19f602156262869d568a1b5b9c91d7690e64c92ba99caa736ac3 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f6673502680>: Failed to establish a new connection: [Errno -2] Name does not resolve'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/config/custom_components/nuki_ng/config_flow.py", line 34, in find_nuki_devices
    info = await nuki.bridge_info()
  File "/config/custom_components/nuki_ng/nuki.py", line 78, in bridge_info
    return await self.async_json(lambda r: r.get(self.bridge_url("/info"), timeout=BRIDGE_TIMEOUT))
  File "/config/custom_components/nuki_ng/nuki.py", line 37, in async_json
    response = await self.hass.async_add_executor_job(lambda: cb(requests))
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/nuki_ng/nuki.py", line 37, in <lambda>
    response = await self.hass.async_add_executor_job(lambda: cb(requests))
  File "/config/custom_components/nuki_ng/nuki.py", line 78, in <lambda>
    return await self.async_json(lambda r: r.get(self.bridge_url("/info"), timeout=BRIDGE_TIMEOUT))
  File "/usr/local/lib/python3.10/site-packages/requests/api.py", line 73, in get
    return request("get", url, params=params, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/requests/api.py", line 59, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 701, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/requests/adapters.py", line 565, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='http', port=80): Max retries exceeded with url: //127.0.0.1:8080/info?token=94649fc705cf19f602156262869d568a1b5b9c91d7690e64c92ba99caa736ac3 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f6673502680>: Failed to establish a new connection: [Errno -2] Name does not resolve'))

Use 127.0.0.1:8087 if HAOS

Since you are using HAOS, you need to set the IP AND the port because you changed it to 8087.
You need to use 127.0.0.1:8087

1 Like

Dude… This might be inappropriate but you’re a gifted fella!

I used:
127.0.0.1:8087 and it finally worked.

There was no need to use http:// in the beginning of the address. That did the trick.

Now let’s play :smirk:

Thanks again!

1 Like

You are welcome! Enjoy!

So I got it finally working, but I did a few mistakes.
First of all I had the internal WLAN enabled in my SL3.0 Pro which isn’t supposed to work with the Nuki Bridge or the Raspi Nuki Bridge together. It has to be the one or the other.
Next problem was the Bluetooth dongle. I now use an extension cable. I think this was the reason for better bluetooth connection. Finally I should have read the initial post more carefully about restarting the bridge after pairing. I couldn’t get the integration nuki ng setup without this restart.
And I also needed the

docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker ps --format '{{.Names}}' | grep nuki)

to find the IP of my host. So I used 172.30.33.10 without port. That’s it

Many Thanks @victorigualada for your help and your patience.

1 Like

That’s great! I’m glad you mamaged to solve it!