rroller / dahua

Dahua Camera and Doorbell Home Assistant Integration
MIT License
382 stars 73 forks source link

Camera entity becomes unavailable. #285

Closed wgumaa closed 2 months ago

wgumaa commented 1 year ago

Up till the latest update my 2 cameras were working fine. After the latest update I have noticed that the cameras become unavailable. I have 2 automations related to the cameras. 1 arms the motion detection at a certain hour in the evening and 1 that disarms them at a certain hour in the morning. However looking at the logs the times the cameras become unavailable is not near the automation times. They are random.

Have to reload the integration to make them work again.

Anyone experiencing the same issue?

soulbrat commented 1 year ago

Same issues with the latest update of Dahua integration.

DarthElle13 commented 1 year ago

It seems highly random. My AD410 goes completely unavailable, including the button entity which means I have no doorbell (the physical chime does not work). Was working without issue for 6 months before the last update.

Debugging logs arent an option in the integrations page. Please let me know if there is something I can do to contribute to this issue.

shred86 commented 1 year ago

I’m noticing the same issue with an Amcrest AD410 doorbell. Within the past few weeks the Dahua integration will work after I reload it, but stops working after a few hours. I’m seeing thousands of “Exception fetching information from…” type error messages in the Home Assistant logs. If I reload the integration, it usually starts working again but the problem repeats. Prior to this, it was working great for 6+ months. My AD410 firmware is still on the original (did not update to the recently released version).

I’m going to try downgrading to 0.9.44 now to see if that resolves it.

wgumaa commented 1 year ago

I meant to say the latest HA update

thornygravy commented 1 year ago

+1

danieldotnl commented 1 year ago

Same here with the AD410. Downgrading does solve it! Also installed the new firmware but that didn't make a difference.

mcdhome commented 1 year ago

Same issue since last HA update. I think it is the HA update not the DI update here, but I could be wrong. Timing has been since the recent HA version upgrade. Cameras go inactive after some time. A full unplug and restart fixes for a little while.
NVR=N54B3P Cameras = N85DL6Z

Other addon had Python deprecated issues as they upgraded python in HA.

DarthElle13 commented 1 year ago

Happened for the first time for me before I updated to 2023.6 so definitely not just due to the HA update

shred86 commented 1 year ago

After downgrading the Dahua Integration to 0.9.44, it's been running for over 24 hours now without seeing the issue. Before, it would happen within a few hours.

shred86 commented 1 year ago

Just some more information on my issue. Ever since I started using this integration, I would get occasional timeout errors such as the following:

2023-06-12 15:44:05.440 WARNING (MainThread) [custom_components.dahua] TimeoutError fetching information from http://my-cam-ip:80/cgi-bin/configManager.cgi?action=getConfig&name=Lighting[0][0]

These would occur maybe a couple times a day but everything worked as expected. I think when I upgraded the Dahua Integration to the latest version, 0.9.46, is when I started noticing my Amcrest AD410 was becoming unavailable after a few hours and I would see thousands of the log entry above. I also use the Scrypted application to integrate my AD410 with HomeKit and while I could still access the video feed from the camera, I would no longer receive doorbell event presses. In other words, the AD410 became completely unavailable in Home Assistant, but was still partial available in Scrypted (video feed but no doorbell events). If I reloaded the integration in both Home Assistant and Scrypted, it would work as expected for a few hours before repeating this behavior.

As I mentioned above, after downgrading this integration to 0.9.44, everything has been working "normal" like before, both with this integration and Scrypted. I am still seeing a couple timeout errors in the logs but not the thousands of entries like before and everything is still functional.

DarthElle13 commented 1 year ago

Also downgraded to 0.9.44. Will update with results in the next couple of days.

mmib commented 1 year ago

Same here. If you turn cameras router off then it never comes back in 0.9.46. Downgraded to 0.9.44 - it works fine and cameras comes back after turning off and on.

intermittech commented 1 year ago

Just wanted to confirm, hit by it too after updating. Worked correctly for months before that, also reverted to the 0.9.44 version and hoping it doesn't return.

kafka0 commented 1 year ago

I am having the same issue with my doorbell AD410. In the meantime I just created an automation to reload the integration when the doorbell becomes unavailable.

pollinolas commented 1 year ago

same with a VTO 2202F device

p2baron commented 1 year ago

Same here. I have two IPC-HDW3849H-AS-PV camera's and two DHI-VTO2211G-P intercom devices. Reloading the configuration seems to fix it. Let me know if I can upload debug logging.

mcdhome commented 1 year ago

In Home assistant, you can script the quick HA reload that will fix the camera connection when the NVR or cameras are restarted. Basically I restart my NVR every day, wait 10 minutes then run a Home Assistant service call to "Home Assistant Supervisor: Reboot the host system." and this gets all the cameras reconnected just fine until this bug is resolved.

rroller commented 1 year ago

A few commits were released in the latest version (they were not written by my but by other community members who fixed a few bugs or added features).

I'm wondering if this one is at play here - https://github.com/rroller/dahua/commit/62c2def58596805c0e7f434b1d5f5421ba064f4b

Can anyone having this issue try without this commit?

rroller commented 1 year ago

I reverted that commit in https://github.com/rroller/dahua/releases/tag/0.9.47

Can someone please try it?

ptschi commented 1 year ago

same issue here with serie 3 and 5 since. I will dl the debug version

stefanoferrario commented 1 year ago

@rroller same error after update

This is the log:

2023-06-18 15:58:51.322 WARNING (MainThread) [custom_components.dahua] TimeoutError fetching information from https://192.168.188.53:443/cgi-bin/configManager.cgi?action=getConfig&name=Lighting[9][2] 2023-06-18 15:58:51.327 WARNING (MainThread) [custom_components.dahua] Failed to sync device state for 192.168.188.53. See README to enable debug logs to get full exception 2023-06-18 15:58:51.331 DEBUG (MainThread) [custom_components.dahua] Failed to sync device state for 192.168.188.53 Traceback (most recent call last): File "/config/custom_components/dahua/client.py", line 746, in get response = await auth.request("GET", url) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/dahua/digest.py", line 50, in request return await self._handle_401(response) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/dahua/digest.py", line 151, in _handle_401 return await self.request( ^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/dahua/digest.py", line 46, in request response = await self.session.request(method, url, headers=headers, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/client.py", line 560, in _request await resp.start(conn) File "/usr/local/lib/python3.11/site-packages/aiohttp/client_reqrep.py", line 899, in start message, payload = await protocol.read() # type: ignore[union-attr] ^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/streams.py", line 616, in read await self._waiter asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/config/custom_components/dahua/init.py", line 325, in _async_update_data results = await asyncio.gather(*coros) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/dahua/client.py", line 217, in async_get_config_lighting return await self.async_get_config("Lighting[{0}][{1}]".format(channel, profile_mode)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/dahua/client.py", line 200, in async_get_config return await self.get(url) ^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/dahua/client.py", line 758, in get raise exception File "/config/custom_components/dahua/client.py", line 742, in get async with async_timeout.timeout(TIMEOUT_SECONDS): File "/usr/local/lib/python3.11/site-packages/async_timeout/init.py", line 129, in aexit self._do_exit(exc_type) File "/usr/local/lib/python3.11/site-packages/async_timeout/init.py", line 212, in _do_exit raise asyncio.TimeoutError TimeoutError 2023-06-18 15:58:51.339 ERROR (MainThread) [custom_components.dahua] Error fetching dahua data: 2023-06-18 15:58:51.341 DEBUG (MainThread) [custom_components.dahua] Finished fetching dahua data in 24.175 seconds (success: False) 2023-06-18 15:58:51.349 WARNING (MainThread) [custom_components.dahua] TimeoutError fetching information from https://192.168.188.53:443/cgi-bin/configManager.cgi?action=getConfig&name=SmartMotionDetect

rroller commented 1 year ago

Can you all list your camera models? I'd like to see if there's a certain type of camera having issues. I'm having a hard time reproducing this.

stefanoferrario commented 1 year ago

@rroller It is an NVR. The model is DHI-NVR5216-16P-I. I noticed that sometimes are correctly load and motion detected is ok, other times are "not available".

rroller commented 1 year ago

I'm wondering if this PR was at play then - https://github.com/rroller/dahua/pull/242

stefanoferrario commented 1 year ago

Before 0.9.45 version I need to modify plugin code because was detected as doorbell and I receive no alarms. Not sometimes I receive alarms so I think #242 issue is solved.

shred86 commented 1 year ago

I've been running 0.9.47 for several hours now and haven't experienced the issue I mentioned before. I'll keep on eye on it but so far, so good. This is with an Amcrest AD410 doorbell.

stefanoferrario commented 1 year ago

I noticed in the log also this error image

I don't understand if could be related

intermittech commented 1 year ago

For anyone else currently having this issue (reverting to the older version did not fix it for me, still goes unavailable sometimes) I've created a little automation for myself which will trigger a reload of the integration, so far this seems to be working fine for me doing this manually so this automated way should hopefully hold us over until the bug is squashed. Having a non-working doorbell is annoying. ;) automation

stefanoferrario commented 1 year ago

Me too still having problem with cameras. After home assistant start all cameras are ok and motion detection too is ok. After hours some cameras become unavailable and trying to reloading I have timeout error Please, any solution?

stefanoferrario commented 1 year ago

I also noticed that only some motion alarms are not available others still working. I also try removing all my cameras and add them again

stefanoferrario commented 1 year ago

@intermittech have you the same issue also after the last update as me? I received all motion detection alert since the two last updates. Now sometimes I revived them, sometimes not, sometimes motion detection alarm remain in detected state. I can't understand which is the problem

stefanoferrario commented 1 year ago

@rroller issue persist. Sometimes all cameras are and then become not available and no motion are detected. I can see in log several time timeout errors. I have never had problems with the cameras connected to the NVR before the last update

I tried to delete and re-add the device, Reboot NVR, change user of NVR. Nothing resolve the issue

Suxsem commented 1 year ago

@rroller I get the same error with doorbell VTO2211G. Reverting that commit didn't fix the issue.

All entities goes offline after some days (in my case about 3 days) with

2023-07-03 07:39:03.985 WARNING (MainThread) [custom_components.dahua] Failed to sync device state for citofono.lan. See README to enable debug logs to get full exception
2023-07-03 07:39:03.986 ERROR (MainThread) [custom_components.dahua] Error fetching dahua data:
....
2023-07-03 07:49:30.564 ERROR (Thread-3) [custom_components.dahua] server closed the connection
Suxsem commented 1 year ago

ok I think it has to do with recent HA update.

The error basically tells that the http request https://github.com/rroller/dahua/blob/321a576e5fee81de122c440ad28d806b519e35cc/custom_components/dahua/digest.py#L46 sometimes get canceled (asyncio.exceptions.CancelledError).

I found another reference to this exception after recent HA update: https://community.home-assistant.io/t/zha-asyncio-exceptions-cancellederror/562112

Maybe it could be related to https://www.home-assistant.io/blog/2023/04/18/home-assistant-os-release-10/, specifically

Advanced memory management With Home Assistant OS 10 low memory, devices will generally perform better. Firstly, we moved from zram to zswap, which allows us to use the storage as an actual swap space. We’ve tuned the memory management to minimize the number of writes to storage (to prevent unnecessary wear on SD-cards and other flash memory-based storage).

We’ve also improved reliability and responsiveness in low-memory situations: Home Assistant OS uses a new memory management mechanism named Multi-Gen LRU along with thrashing prevention. This makes Home Assistant OS recover quickly from a low-memory situation and remain responsive.

Digging further I see other references to the problem in the HA core repository issues: https://github.com/home-assistant/core/issues/95377 and https://github.com/home-assistant/core/issues/94559.

This last one says that it has been fixed in 2023.6.2, but I'm running this exact version and I'm still facing the issue.

@rroller maybe you should report the issue on the HA core repo?

djfjeff commented 1 year ago

It seems I have the same issue now. I still don't know if this is my doorbell unit itself but it started to misbehave in the last week after I did a bunch of upgrade (the dahua addon to 0.9.47 and HA to 2023.8.1)

My doorbell is at the latest version for the last 2 months and was working well before that.

Masterz69 commented 5 months ago

Integration lost contact with camera and probably same time Video feed stopped. On Camera web UI also have no video when checked. But Setting etc. working fine. Camera reboot with NO changes in Camera/HA fixed so far.

It worked fine for a week, but last night starts to become Unavailable: image Then disconnects finally till Camera reboot.

Camera Info:

Device TypeIPC-HFW2441S-S-0280B
System VersionV2.840.0000000.14.R, Build Date: 2023-11-24
WEB VersionV3.2.1.1676618
ONVIF Version22.06(V2.0.1.80886)
S/N9A04577PAG46C32
Algorithm Version3.9.4
Security Baseline VersionV2.3

HA info:

Core 2024.3.1
Supervisor 2024.03.1
Operating System 11.4
Frontend 20240307.0

HA System->Logs:

This error originated from a custom integration.

Logger: custom_components.dahua
Source: helpers/update_coordinator.py:350
integration: Dahua (documentation, issues)
First occurred: 00:31:47 (309 occurrences)
Last logged: 11:22:05

Error fetching dahua data:
Logger: aiohttp.server
Source: /usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py:421
First occurred: 11:16:42 (6 occurrences)
Last logged: 11:22:05

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 452, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_app.py", line 543, in _handle
    resp = await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_middlewares.py", line 114, in impl
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 91, in security_filter_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 25, in request_context_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 79, in ban_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 235, in auth_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 31, in headers_middleware
    response = await handler(request)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/http.py", line 68, in handle
    result = await handler(request, **request.match_info)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/camera/__init__.py", line 818, in get
    return await self.handle(request, camera)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/camera/__init__.py", line 836, in handle
    image = await _async_get_image(
            ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/camera/__init__.py", line 191, in _async_get_image
    else await camera.async_camera_image(width=width, height=height)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/dahua/camera.py", line 253, in async_camera_image
    return await self._coordinator.client.async_get_snapshot(self._channel_number)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/dahua/client.py", line 74, in async_get_snapshot
    return await self.get_bytes(url)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/dahua/client.py", line 759, in get_bytes
    response.raise_for_status()
  File "/usr/local/lib/python3.12/site-packages/aiohttp/client_reqrep.py", line 1060, in raise_for_status
    raise ClientResponseError(
aiohttp.client_exceptions.ClientResponseError: 401, message='Unauthorized', url=URL('http://192.168.1.91:80/cgi-bin/snapshot.cgi?channel=1')
This error originated from a custom integration.

Logger: custom_components.dahua
Source: custom_components/dahua/__init__.py:339
integration: Dahua (documentation, issues)
First occurred: 00:31:47 (566 occurrences)
Last logged: 11:22:35

Failed to sync device state for 192.168.1.91. See README to enable debug logs to get full exception
Logger: homeassistant.components.stream.stream.camera.ipc_gate_sub
Source: components/stream/__init__.py:431
integration: Stream (documentation, issues)
First occurred: 11:23:12 (6 occurrences)
Last logged: 11:23:49

Error from stream worker: Stream ended; no additional packets
Error from stream worker: Error opening stream (ERRORTYPE_110, Operation timed out) rtsp://****:****@192.168.1.91:554/cam/realmonitor?channel=1&subtype=1
Error from stream worker: Error opening stream (ERRORTYPE_111, Connection refused) rtsp://****:****@192.168.1.91:554/cam/realmonitor?channel=1&subtype=1
jaaneo commented 4 months ago

Any solution? I have the same problem.

Masterz69 commented 4 months ago

Any solution? I have the same problem.

Switched off 'Preload camera stream', so far 3 weeks no issues. Not sure is it permanent solution or not.