kvj / hass_nuki_ng

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

ConnectionError: Http response: 503 in Automation #40

Open CAVACO-PT opened 2 years ago

CAVACO-PT commented 2 years ago

Hi There anyone know why my automation , that is really simple , just to close the lock , fails sometimes with 503 ??

Error executing script. Unexpected error for call_service at pos 8: Http response: 503 While executing automation automation.abrir_portas Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 372, in _async_step await getattr(self, handler)() File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 575, in _async_call_service_step await service_task File "/usr/src/homeassistant/homeassistant/core.py", line 1630, in async_call task.result() File "/usr/src/homeassistant/homeassistant/core.py", line 1667, 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 self.hass.helpers.service.entity_service_call( File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 668, in entity_service_call future.result() # pop exception if have File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 927, in async_request_call await coro File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 705, in _handle_entity_call await result File "/config/custom_components/nuki_ng/lock.py", line 57, in async_unlock await self.coordinator.action(self.device_id, "unlock") File "/config/custom_components/nuki_ng/nuki.py", line 326, in action result = await self.api.bridge_lock_action(dev_id, action, device_type) File "/config/custom_components/nuki_ng/nuki.py", line 87, in bridge_lock_action return await self.async_json( File "/config/custom_components/nuki_ng/nuki.py", line 41, in async_json raise ConnectionError(f"Http response: {response.status_code}") ConnectionError: Http response: 503

KitHubek commented 2 years ago

have the same or similar issue:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 372, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 588, in _async_device_step
    await platform.async_call_action_from_config(
  File "/usr/src/homeassistant/homeassistant/components/lock/device_action.py", line 76, in async_call_action_from_config
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1630, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1667, 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 self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 668, 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 705, in _handle_entity_call
    await result
  File "/config/custom_components/nuki_ng/lock.py", line 54, in async_lock
    await self.coordinator.action(self.device_id, "lock")
  File "/config/custom_components/nuki_ng/nuki.py", line 326, in action
    result = await self.api.bridge_lock_action(dev_id, action, device_type)
  File "/config/custom_components/nuki_ng/nuki.py", line 87, in bridge_lock_action
    return await self.async_json(
  File "/config/custom_components/nuki_ng/nuki.py", line 41, in async_json
    raise ConnectionError(f"Http response: {response.status_code}")
ConnectionError: Http response: 503
kvj commented 2 years ago

The Nuki Bridge hardware isn't great. 503s happen from time to time

alexdelprete commented 2 years ago

If you have a lot of 503 errors, it's because the bridge is limited to processing one request at a time. If it receives requests from the component AND from the mobile app or some other sw, it will process the first and send 503 to the other requests.

Make sure only the component communicates constantly with the bridge, uninstall other integrations (the official one, many leave it running). If you use the mobile app a lot, it can happen that it sends a command while the component does too...and that leads to 503. Unfortunately the bridge is a bad piece of hw and fw, no queue mechanism, very limited cpu, etc.

chiefdeputy commented 2 years ago

As a workaround, would it be feasable to retry a few times on 503?

Opening the door might take 2 secs longer, but it will not discard an "open door" command from home assistant.

leranp commented 2 years ago

As a workaround, would it be feasable to retry a few times on 503?

Opening the door might take 2 secs longer, but it will not discard an "open door" command from home assistant.

I have the same problem and looking for a solution