kvj / hass_nuki_ng

Better support for Nuki devices in the Home Assistant
MIT License
185 stars 36 forks source link

Lost connenction to web api after last update #96

Open PetrMa opened 2 years ago

PetrMa commented 2 years ago

Hello,

I made an update from 0.3.9 to 0.3.10 today and after HA reboot I lost access to Web Api sensors. After downgrade back to 0.3.9 everything is OK. It is issue on my side or not?

Device: Nuki Smart Lock 3.0 Pro without bridge

thanks, Regards, Petr

forzewin commented 2 years ago

status is ok for me, but i have 404 error for lock/unlock actions

deku-m commented 2 years ago

Same for me

rdehuyss commented 2 years ago

Also a 404.

Inferi0r commented 2 years ago

raise ConnectionError(f"Http response for {response.request.url}: {response.status_code} {response.reason}") ConnectionError: Http response for https://api.nuki.io/smartlock/XXXXXXXXX/action: 404 Not Found

xtimmy86x commented 2 years ago

Same problem here with 0.3.9 and 0.3.10, i revert to 0.3.8 and everything is working again

kvj commented 2 years ago

The discussion is in #76 There's a regression detected, but the fix isn't known yet

chu11u commented 2 years ago

Hi, have the same here with thaat log message. I noticed that the integration is using wrong lock ID... even after removing and configuring a new, it is still the wrong lock ID. I hope this helps...

Se7enair commented 2 years ago

There should be a new device which is called Nuki WebApi. The device contains a entity for every user. Including a user for webapi. Make sure that it is on.

forzewin commented 2 years ago

device is there but switches are greyed out

forzewin commented 2 years ago

Reverted to 0.3.8, still same issue :/

I deleted/added the integration.

Generated new API token with all authorizations and i still have the 404 error..

I dont understand..

kvj commented 2 years ago

I need more details to help you resolving the issue.

@chu11u when you say "wrong lock ID", what is "wrong" value and what should be the correct one?

@forzewin which API call gives your 404 and what is the ID of your device?

chu11u commented 2 years ago

I need more details to help you resolving the issue.

@chu11u when you say "wrong lock ID", what is "wrong" value and what should be the correct one? The part in the URL wuch hold the lockid is different than my own lockid. I ran those api calls my self to get my lockid and got a different number. Than I ran the same lock action call with the right lockid, and the device locked and unlock. So now I use the integration only for the state of the lock and using direct calls for lock/unlock untill the integration is fixed.

@forzewin which API call gives your 404 and what is the ID of your device? I got the 404 when I tried to lock or unlock. It is the action URL call. It showed briefly on the Lovelace bottom and also in the log file.

forzewin commented 2 years ago

Sorry for the formatting, i am on my phone.

here the full error when trying to unlock the lock :

Échec d'appel du service "lock/unlock". Http response for https://api.nuki.io/smartlock/292XXXX48996/action: 404 Not Found

full log :

Logger: homeassistant.components.websocket_api.http.connection
Source: custom_components/nuki_ng/nuki.py:39
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 11:54:11 (17 occurrences)
Last logged: 13:57:27

[140127195676832] Http response for https://api.nuki.io/smartlock/292XXXXX996/action: 404 Not Found
[140127194185936] Http response for https://api.nuki.io/smartlock/292XXXXX48996/action: 404 Not Found
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 199, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1713, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1750, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 204, in handle_service
    await service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 676, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 930, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 713, in _handle_entity_call
    await result
  File "/config/custom_components/nuki_ng/lock.py", line 56, in async_unlock
    await self.coordinator.action(self.device_id, "unlock")
  File "/config/custom_components/nuki_ng/nuki.py", line 466, in action
    await self.api.web_lock_action(self.web_id(dev_id), action)
  File "/config/custom_components/nuki_ng/nuki.py", line 126, in web_lock_action
    await self.web_async_json(
  File "/config/custom_components/nuki_ng/nuki.py", line 184, in web_async_json
    return await self.async_json(
  File "/config/custom_components/nuki_ng/nuki.py", line 39, in async_json
    raise ConnectionError(f"Http response for {response.request.url}: {response.status_code} {response.reason}")
ConnectionError: Http response for https://api.nuki.io/smartlock/2928XXXX48996/action: 404 Not Found

the id of my lock in nuki app looks like this

ID Smart Lock: 30XXXF64

I lightly modified id's to anonymise them

Inferi0r commented 2 years ago

I need more details to help you resolving the issue. @forzewin which API call gives your 404 and what is the ID of your device? I got the 404 when I tried to lock or unlock. It is the action URL call. It showed briefly on the Lovelace bottom and also in the log file.

My API call is: [140186346527696] Http response for https://api.nuki.io/smartlock/292805081XXX/action: 404 Not Found

My device ID is: ID2C8AFXXX

I have a Smart Lock Pro 3.0 (Firmware: 197381 which is 3.3.5) without Bridge. I do have a bunch of openers laying around.

kvj commented 2 years ago

Thanks for the input. I've pushed a fix to the main branch, could you please test the it? (Install main version via HACS)

forzewin commented 2 years ago

Just did it and i can confirm that the fix works like a charm.

Everything is back and working again

Thanks a lot @kvj

Inferi0r commented 2 years ago

Thanks for the input. I've pushed a fix to the main branch, could you please test the it? (Install main version via HACS)

Yes, main version is working for me too!

chu11u commented 2 years ago

Thanks for the input. I've pushed a fix to the main branch, could you please test the it? (Install main version via HACS)

Sorry for being novice... how do I do that? i looked at the integration and there is no update. how do I install it?

kvj commented 2 years ago

how do I install it?

Go to HACS, click on the integration, select "Re-download" from the popup menu and pick "main" from the list of all versions available

forzewin commented 2 years ago

Thanks for the input. I've pushed a fix to the main branch, could you please test the it? (Install main version via HACS)

Sorry for being novice... how do I do that? i looked at the integration and there is no update. how do I install it?

Go to HACS > Integrations > Search for Nuki Lock and click on it > on the upper right, click on ... > Redownload > Select Main

chu11u commented 2 years ago

Thanks for the input. I've pushed a fix to the main branch, could you please test the it? (Install main version via HACS)

Sorry for being novice... how do I do that? i looked at the integration and there is no update. how do I install it?

Go to HACS > Integrations > Search for Nuki Lock and click on it > on the upper right, click on ... > Redownload > Select Main Done. Do i need to re-install the integration also?

forzewin commented 2 years ago

You just need to restart HA after the redownload

chu11u commented 2 years ago

You just need to restart HA after the redownload

well... still get the 404 message: Http response for https://api.nuki.io/smartlock/292882605412/action: 404 Not Found

I have no problem leaving the lockid because it is wrong one...

Ill try to remove and configure the lock again

chu11u commented 2 years ago

Ok. I can confirm that main worked.

kvj commented 2 years ago

is 0.3.10 the corrected version?

nope, I haven't pushed the updated release yet. That will be 0.3.11

Maximus48p commented 2 years ago

After a complete removal and reinstall of 'main' it worked for me as well. confirm.

LordShelmchen commented 2 years ago

I can't confirm. Problem still exist.

Removal and reinstall did not work. Is equal which version i'll use: main or 0.3.10.

If a status is requested the bridge become a ping timeout for round about 2-3 Pings. This can be reproduced. I opened a ticket at Nuki, too.

alexdelprete commented 2 years ago

If a status is requested the bridge become a ping timeout for round about 2-3 Pings. This can be reproduced. I opened a ticket at Nuki, too.

In case the bridge receives too many requests, it reboots, it's a known issue due to the hw limitations of the bridge. It can process only 1 request at a time. Probably you're sending it requests not only from this integration but from the mobile app, the web app, etc.

The bridge has a log, check it and report it here, you should see the reboots. You can dump it via curl and the /log endpoint.

curl -H "Content-Type: application/json" 'http://bridge-ip:8080/log?token=bridgetoken'

chu11u commented 2 years ago

I can't confirm. Problem still exist.

Removal and reinstall did not work. Is equal which version i'll use: main or 0.3.10.

If a status is requested the bridge become a ping timeout for round about 2-3 Pings. This can be reproduced. I opened a ticket at Nuki, too.

Remove and install "main" version

LordShelmchen commented 2 years ago

I had removed and install main, also tried to delete all files manually. Problem exists.

But a the nuki log, i can see the reboots. I have to wait for the answer from Nuki about this problem.

alexdelprete commented 2 years ago

But a the nuki log, i can see the reboots. I have to wait for the answer from Nuki about this problem.

I knew that was the case, and in order to limit the reboots, you need to lower the queries to the bridge: nuki_ng does only one every 30s (polling), the rest are callbacks (bridge to nuki_ng) so there are no problems there.

Make sure you uninstalled the old (official) nuki integration, make sure there are no other apps communicating with the bridge. If you can check the bridge log, check the frequency of the reboots to have an idea.

I'm pretty confident you are running nuki_ng in parallel to the official nuki integration, double-check that.

LordShelmchen commented 2 years ago

You were right, I had the official Nuki integration running. I have now disabled and uninstalled it.

I also closed all apps and tried it only via HA with Nuki Lock. The errors have become less, but are still there. As soon as I try to buzz/unlatch the "Opener" or "Lock", it often takes up to a minute until something happens.

This is what I find in the logs:

Dieser Fehler wurde von einer benutzerdefinierten Integration verursacht

Logger: custom_components.nuki_ng.nuki Source: custom_components/nuki_ng/nuki.py:155 Integration: Nuki Lock (documentation, issues) First occurred: 19:06:36 (1 occurrences) Last logged: 19:06:36

Failed to update callback http://homeassistant.pandora:8123/api/webhook/nuki_ng_bridge_hook_xxxxxxxxxxxxxxxxxxx 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 95, in create_connection raise err File "/usr/local/lib/python3.10/site-packages/urllib3/util/connection.py", line 85, in create_connection sock.connect(sa) ConnectionRefusedError: [Errno 111] Connection refused

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 0x7f66a2fe50>: Failed to establish a new connection: [Errno 111] Connection refused

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='192.168.42.101', port=8080): Max retries exceeded with url: /callback/list?token=xxxxxx (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f66a2fe50>: Failed to establish a new connection: [Errno 111] Connection refused'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/config/custom_components/nuki_ng/nuki.py", line 388, in _update callbacks_list = await self.api.bridge_check_callback( File "/config/custom_components/nuki_ng/nuki.py", line 154, in bridge_check_callback callbacks = await self.async_json( 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 response = await self.hass.async_add_executor_job(lambda: cb(requests)) File "/config/custom_components/nuki_ng/nuki.py", line 155, in lambda r: r.get(self.bridge_url("/callback/list"), 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='192.168.42.101', port=8080): Max retries exceeded with url: /callback/list?token=xxxxxx (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f66a2fe50>: Failed to establish a new connection: [Errno 111] Connection refused'))

Logger: homeassistant.components.websocket_api.http.connection Source: custom_components/nuki_ng/nuki.py:39 Integration: Home Assistant WebSocket API (documentation, issues) First occurred: 19:06:39 (2 occurrences) Last logged: 19:06:45

[546950995376] Http response for http://192.168.42.101:8080/lockAction?token=xxxxxx&action=3&nukiId=xxxxxxxxx&deviceType=2: 503 Service Unavailable Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 199, in handle_call_service await hass.services.async_call( File "/usr/src/homeassistant/homeassistant/core.py", line 1713, in async_call task.result() File "/usr/src/homeassistant/homeassistant/core.py", line 1750, in _execute_service await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)( File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 204, in handle_service await service.entity_service_call( File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 676, in entity_service_call future.result() # pop exception if have File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 930, in async_request_call await coro File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 713, in _handle_entity_call await result File "/config/custom_components/nuki_ng/lock.py", line 59, in async_open await self.coordinator.action(self.device_id, "open") File "/config/custom_components/nuki_ng/nuki.py", line 461, in action result = await self.api.bridge_lock_action(dev_id, action, device_type) File "/config/custom_components/nuki_ng/nuki.py", line 99, in bridge_lock_action return await self.async_json( File "/config/custom_components/nuki_ng/nuki.py", line 39, in async_json raise ConnectionError(f"Http response for {response.request.url}: {response.status_code} {response.reason}") ConnectionError: Http response for http://192.168.42.101:8080/lockAction?token=xxxxxx&action=3&nukiId=xxxxxxxxx&deviceType=2: 503 Service Unavailable

Any idea? Thanks in advance!

alexdelprete commented 2 years ago

Yes I have an idea: your setup is a total disaster. :)

Jokes apart: the errors are "connection refused", it means that HA/Nuki_NG can't communicate with the bridge. So please exclude any network issue, and if you're confident it's not the network (firewalls, vlans, etc.) then I would suggest to uninstall nuki_ng, read the instructions carefully again and reinstall it configuring everything accordingly. Take time to read every step.

Make sure you disabled all apps that could communicate with the bridge.