rroller / dahua

Dahua Camera and Doorbell Home Assistant Integration
MIT License
404 stars 82 forks source link

Failed to sync device state - 0.9.63 #410

Open ocean75 opened 3 weeks ago

ocean75 commented 3 weeks ago

Good morning,

I've experienced an issue with two out of ten cameras since upgrading from 0.9.62 to version 0.9.63. The cameras worked fine on version 0.9.62. Reverting back to 0.9.62 allowed the cameras to connect properly again. It appears something changed between the two versions?

HA - Version: 2024.10.4 - HASS Dahua Integration Version: 0.9.63 Dahua Camera Version: IPC-HDW4830EM-AS Dahua Camera FW version: DH_IPC-HX5X3X-Rhea_MultiLang_NP_Stream3_V2.800.0000029.0.R.221220

Any ideas or suggestions would be appreciated. Thanks

Screenshot 2024-11-02 080022

INFO (MainThread) [custom_components.dahua] Using max streams 3
INFO (MainThread) [custom_components.dahua] Using channel number 1
INFO (MainThread) [custom_components.dahua] Device supports Coaxial Control=True
INFO (MainThread) [custom_components.dahua] Device supports disarming linkage=False
INFO (MainThread) [custom_components.dahua] Device supports smart motion detection=False
INFO (MainThread) [custom_components.dahua] Device is a doorbell=False
INFO (MainThread) [custom_components.dahua] Device is a floodlight=False
INFO (MainThread) [custom_components.dahua] Device supports infrared lighting=True
INFO (Thread-49) [custom_components.dahua] Starting DahuaEventThread
INFO (MainThread) [custom_components.dahua] Device supports profile mode=False
WARNING (MainThread) [custom_components.dahua] Failed to sync device state for 192.168.4.23. See README to enable debug logs to get full exception

Debug

2024-11-02 08:22:53.854 WARNING (MainThread) [custom_components.dahua] Failed to sync device state for 192.168.4.23. See README to enable debug logs to get full exception
2024-11-02 08:22:53.854 DEBUG (MainThread) [custom_components.dahua] Failed to sync device state for 192.168.4.23
Traceback (most recent call last):
File "/config/custom_components/dahua/__init__.py", line 339, in _async_update_data
light_v2 = await self.client.async_get_lighting_v2()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/dahua/client.py", line 178, in async_get_lighting_v2
return await self.get(url)
^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/dahua/client.py", line 789, in get
raise exception
File "/config/custom_components/dahua/client.py", line 772, in get
response.raise_for_status()
File "/usr/local/lib/python3.12/site-packages/aiohttp/client_reqrep.py", line 1121, in raise_for_status
raise ClientResponseError(
aiohttp.client_exceptions.ClientResponseError: 400, message='Bad Request', url='http://192.168.4.23/cgi-bin/configManager.cgi?action=getConfig&name=Lighting_V2'
2024-11-02 08:22:53.856 DEBUG (MainThread) [custom_components.dahua] Finished fetching dahua data in 6.906 seconds (success: False)
2024-11-02 08:22:53.963 DEBUG (MainThread) [custom_components.dahua] Finished fetching dahua data in 0.232 seconds (success: True)
2024-11-02 08:22:54.081 DEBUG (MainThread) [custom_components.dahua] Finished fetching dahua data in 0.163 seconds (success: True)
2024-11-02 08:22:54.107 DEBUG (MainThread) [custom_components.dahua] Finished fetching dahua data in 0.361 seconds (success: True)
2024-11-02 08:22:54.135 DEBUG (MainThread) [custom_components.dahua] Finished fetching dahua data in 0.197 seconds (success: True)
2024-11-02 08:22:54.159 DEBUG (MainThread) [custom_components.dahua] Finished fetching dahua data in 0.169 seconds (success: True)
2024-11-02 08:22:54.397 DEBUG (MainThread) [custom_components.dahua] Finished fetching dahua data in 0.267 seconds (success: True)
2024-11-02 08:22:59.672 INFO (MainThread) [custom_components.dahua] Using max streams 3
2024-11-02 08:23:01.869 INFO (MainThread) [custom_components.dahua] Using channel number 1
2024-11-02 08:23:02.048 INFO (MainThread) [custom_components.dahua] Device supports Coaxial Control=True
2024-11-02 08:23:02.221 DEBUG (MainThread) [custom_components.dahua] ClientError fetching information from http://192.168.4.23:80/cgi-bin/configManager.cgi?action=getConfig&name=DisableLinkage
2024-11-02 08:23:02.221 INFO (MainThread) [custom_components.dahua] Device supports disarming linkage=False
2024-11-02 08:23:02.848 DEBUG (MainThread) [custom_components.dahua] ClientError fetching information from http://192.168.4.23:80/cgi-bin/configManager.cgi?action=getConfig&name=SmartMotionDetect
2024-11-02 08:23:02.848 INFO (MainThread) [custom_components.dahua] Device supports smart motion detection=False
2024-11-02 08:23:02.848 INFO (MainThread) [custom_components.dahua] Device is a doorbell=False
2024-11-02 08:23:02.849 INFO (MainThread) [custom_components.dahua] Device is a floodlight=False
ChristBKK commented 3 weeks ago

I am having the same issue and rolled back to 0.9.60 which works fine

rroller commented 3 weeks ago

Thanks, checking it out.

rroller commented 3 weeks ago

.93 only included this fix https://github.com/rroller/dahua/pull/408

Are you sure you are on the latest eversion of HA? I'm using 2024.10.4 and .93 of the Dahua integration and don't have an issue. I'm trying to think of why you'd be getting a Bad Request but it's hard without being able to reproduce it

ocean75 commented 3 weeks ago

Hi, Yes, I am using the latest version of HA (2024.10.4) along with the Dahua integration (0.9.64). I tried adding one of these cameras in my lab environment, and this is what I received in the log when adding the camera with version 0.9.62 (working) and version 0.9.64 (not working). As I mentioned previously, the error only occurs when adding the IPC-HDW4830EM-AS cameras.

Version 0.9.62

2024-11-02 13:47:37.513 INFO (MainThread) [custom_components.dahua] Using max streams 3
2024-11-02 13:47:39.744 INFO (MainThread) [custom_components.dahua] Using channel number 1
2024-11-02 13:47:39.873 INFO (MainThread) [custom_components.dahua] Device supports Coaxial Control=True
2024-11-02 13:47:40.029 DEBUG (MainThread) [custom_components.dahua] ClientError fetching information from http://192.168.4.23:80/cgi-bin/configManager.cgi?action=getConfig&name=DisableLinkage
2024-11-02 13:47:40.029 INFO (MainThread) [custom_components.dahua] Device supports disarming linkage=False
2024-11-02 13:47:40.810 DEBUG (MainThread) [custom_components.dahua] ClientError fetching information from http://192.168.4.23:80/cgi-bin/configManager.cgi?action=getConfig&name=SmartMotionDetect
2024-11-02 13:47:40.810 INFO (MainThread) [custom_components.dahua] Device supports smart motion detection=False
2024-11-02 13:47:40.810 INFO (MainThread) [custom_components.dahua] Device is a doorbell=False
2024-11-02 13:47:40.810 INFO (MainThread) [custom_components.dahua] Device is a floodlight=False
2024-11-02 13:47:41.456 INFO (MainThread) [custom_components.dahua] Device supports infrared lighting=True
2024-11-02 13:47:41.456 INFO (Thread-5) [custom_components.dahua] Starting DahuaEventThread
2024-11-02 13:47:42.176 INFO (MainThread) [custom_components.dahua] Device supports profile mode=False
2024-11-02 13:47:43.037 DEBUG (MainThread) [custom_components.dahua] Finished fetching dahua data in 5.941 seconds (success: True)
2024-11-02 13:47:43.037 INFO (MainThread) [homeassistant.components.binary_sensor] Setting up dahua.binary_sensor
2024-11-02 13:47:43.038 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new binary_sensor.dahua entity: binary_sensor.walkway_motion_alarm
2024-11-02 13:47:43.040 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new binary_sensor.dahua entity: binary_sensor.walkway_cross_line_alarm
2024-11-02 13:47:43.041 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new binary_sensor.dahua entity: binary_sensor.walkway_alarm_local
2024-11-02 13:47:43.044 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new binary_sensor.dahua entity: binary_sensor.walkway_video_loss
2024-11-02 13:47:43.046 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new binary_sensor.dahua entity: binary_sensor.walkway_video_blind
2024-11-02 13:47:43.047 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new binary_sensor.dahua entity: binary_sensor.walkway_audio_mutation
2024-11-02 13:47:43.049 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new binary_sensor.dahua entity: binary_sensor.walkway_cross_region_detection
2024-11-02 13:47:43.051 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new binary_sensor.dahua entity: binary_sensor.walkway_smart_motion_human
2024-11-02 13:47:43.053 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new binary_sensor.dahua entity: binary_sensor.walkway_smart_motion_vehicle
2024-11-02 13:47:43.058 INFO (MainThread) [homeassistant.components.switch] Setting up dahua.switch
2024-11-02 13:47:44.857 DEBUG (MainThread) [custom_components.dahua] ClientError fetching information from http://192.168.4.23:80/cgi-bin/configManager.cgi?action=getConfig&name=DisableLinkage
2024-11-02 13:47:44.857 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new switch.dahua entity: switch.walkway_motion_detection
2024-11-02 13:47:44.861 INFO (MainThread) [homeassistant.components.light] Setting up dahua.light
2024-11-02 13:47:44.862 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new light.dahua entity: light.walkway_infrared
2024-11-02 13:47:44.865 INFO (MainThread) [homeassistant.components.camera] Setting up dahua.camera
2024-11-02 13:47:44.865 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new camera.dahua entity: camera.walkway_main
2024-11-02 13:47:44.868 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new camera.dahua entity: camera.walkway_sub
2024-11-02 13:47:44.872 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new camera.dahua entity: camera.walkway_sub_2
2024-11-02 13:47:44.875 INFO (MainThread) [homeassistant.components.select] Setting up dahua.select

Version 0.9.64

2024-11-02 13:35:57.460 INFO (MainThread) [custom_components.dahua] Using max streams 3
2024-11-02 13:35:59.501 INFO (MainThread) [custom_components.dahua] Using channel number 1
2024-11-02 13:35:59.781 INFO (MainThread) [custom_components.dahua] Device supports Coaxial Control=True
2024-11-02 13:35:59.950 DEBUG (MainThread) [custom_components.dahua] ClientError fetching information from http://192.168.4.23:80/cgi-bin/configManager.cgi?action=getConfig&name=DisableLinkage
2024-11-02 13:35:59.950 INFO (MainThread) [custom_components.dahua] Device supports disarming linkage=False
2024-11-02 13:36:00.556 DEBUG (MainThread) [custom_components.dahua] ClientError fetching information from http://192.168.4.23:80/cgi-bin/configManager.cgi?action=getConfig&name=SmartMotionDetect
2024-11-02 13:36:00.556 INFO (MainThread) [custom_components.dahua] Device supports smart motion detection=False
2024-11-02 13:36:00.557 INFO (MainThread) [custom_components.dahua] Device is a doorbell=False
2024-11-02 13:36:00.557 INFO (MainThread) [custom_components.dahua] Device is a floodlight=False
2024-11-02 13:36:01.209 INFO (MainThread) [custom_components.dahua] Device supports infrared lighting=True
2024-11-02 13:36:01.209 INFO (Thread-3) [custom_components.dahua] Starting DahuaEventThread
2024-11-02 13:36:01.917 INFO (MainThread) [custom_components.dahua] Device supports profile mode=False
2024-11-02 13:36:03.466 DEBUG (MainThread) [custom_components.dahua] ClientError fetching information from http://192.168.4.23:80/cgi-bin/configManager.cgi?action=getConfig&name=Lighting_V2
2024-11-02 13:36:03.466 WARNING (MainThread) [custom_components.dahua] Failed to sync device state for 192.168.4.23. See README to enable debug logs to get full exception
2024-11-02 13:36:03.466 DEBUG (MainThread) [custom_components.dahua] Failed to sync device state for 192.168.4.23
Traceback (most recent call last):
File "/config/custom_components/dahua/__init__.py", line 340, in _async_update_data
light_v2 = await self.client.async_get_lighting_v2()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/dahua/client.py", line 178, in async_get_lighting_v2
return await self.get(url)
^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/dahua/client.py", line 812, in get
raise exception
File "/config/custom_components/dahua/client.py", line 795, in get
response.raise_for_status()
File "/usr/local/lib/python3.12/site-packages/aiohttp/client_reqrep.py", line 1121, in raise_for_status
raise ClientResponseError(
aiohttp.client_exceptions.ClientResponseError: 400, message='Bad Request', url='http://192.168.4.23/cgi-bin/configManager.cgi?action=getConfig&name=Lighting_V2'
2024-11-02 13:36:03.469 DEBUG (MainThread) [custom_components.dahua] Finished fetching dahua data in 6.214 seconds (success: False)
2024-11-02 13:36:08.753 INFO (MainThread) [custom_components.dahua] Using max streams 3
2024-11-02 13:36:11.124 INFO (MainThread) [custom_components.dahua] Using channel number 1
2024-11-02 13:36:11.254 INFO (MainThread) [custom_components.dahua] Device supports Coaxial Control=True
2024-11-02 13:36:11.418 DEBUG (MainThread) [custom_components.dahua] ClientError fetching information from http://192.168.4.23:80/cgi-bin/configManager.cgi?action=getConfig&name=DisableLinkage
2024-11-02 13:36:11.419 INFO (MainThread) [custom_components.dahua] Device supports disarming linkage=False
2024-11-02 13:36:12.062 DEBUG (MainThread) [custom_components.dahua] ClientError fetching information from http://192.168.4.23:80/cgi-bin/configManager.cgi?action=getConfig&name=SmartMotionDetect
2024-11-02 13:36:12.062 INFO (MainThread) [custom_components.dahua] Device supports smart motion detection=False
2024-11-02 13:36:12.062 INFO (MainThread) [custom_components.dahua] Device is a doorbell=False
2024-11-02 13:36:12.062 INFO (MainThread) [custom_components.dahua] Device is a floodlight=False
2024-11-02 13:36:12.872 INFO (MainThread) [custom_components.dahua] Device supports infrared lighting=True
2024-11-02 13:36:12.872 INFO (Thread-5) [custom_components.dahua] Starting DahuaEventThread
2024-11-02 13:36:13.735 INFO (MainThread) [custom_components.dahua] Device supports profile mode=False
2024-11-02 13:36:15.460 DEBUG (MainThread) [custom_components.dahua] ClientError fetching information from http://192.168.4.23:80/cgi-bin/configManager.cgi?action=getConfig&name=Lighting_V2
coolhand72 commented 3 weeks ago

Similar issue for me, unsure if it started with .63 or .64: This one camera no longer connects, but the other two have no problems.

2024-11-02 13:47:11.720 DEBUG (MainThread) [custom_components.dahua] ClientError fetching information from http://192.168.50.137:16160/cgi-bin/configManager.cgi?action=getConfig&name=Lighting_V2
2024-11-02 13:47:11.720 WARNING (MainThread) [custom_components.dahua] Failed to sync device state for 192.168.50.137. See README to enable debug logs to get full exception
2024-11-02 13:47:11.721 DEBUG (MainThread) [custom_components.dahua] Failed to sync device state for 192.168.50.137
Traceback (most recent call last):
  File "/config/custom_components/dahua/__init__.py", line 340, in _async_update_data
    light_v2 = await self.client.async_get_lighting_v2()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/dahua/client.py", line 178, in async_get_lighting_v2
    return await self.get(url)
           ^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/dahua/client.py", line 812, in get
    raise exception
  File "/config/custom_components/dahua/client.py", line 795, in get
    response.raise_for_status()
  File "/usr/local/lib/python3.12/site-packages/aiohttp/client_reqrep.py", line 1121, in raise_for_status
    raise ClientResponseError(
aiohttp.client_exceptions.ClientResponseError: 400, message='Bad Request', url='http://192.168.50.137:16160/cgi-bin/configManager.cgi?action=getConfig&name=Lighting_V2'
2024-11-02 13:47:11.723 DEBUG (MainThread) [custom_components.dahua] Finished fetching dahua data in 0.737 seconds (success: False)
2024-11-02 13:46:26.650 DEBUG (MainThread) [custom_components.dahua] Finished fetching dahua data in 1.841 seconds (success: True)
2024-11-02 13:46:30.146 INFO (MainThread) [custom_components.dahua] Using max streams 3
2024-11-02 13:46:30.345 INFO (MainThread) [custom_components.dahua] Using channel number 1
2024-11-02 13:46:30.390 INFO (MainThread) [custom_components.dahua] Device supports Coaxial Control=True
2024-11-02 13:46:30.448 DEBUG (MainThread) [custom_components.dahua] ClientError fetching information from http://192.168.50.137:16160/cgi-bin/configManager.cgi?action=getConfig&name=DisableLinkage
2024-11-02 13:46:30.448 INFO (MainThread) [custom_components.dahua] Device supports disarming linkage=False
2024-11-02 13:46:30.504 DEBUG (MainThread) [custom_components.dahua] ClientError fetching information from http://192.168.50.137:16160/cgi-bin/configManager.cgi?action=getConfig&name=SmartMotionDetect
2024-11-02 13:46:30.504 INFO (MainThread) [custom_components.dahua] Device supports smart motion detection=False
2024-11-02 13:46:30.505 INFO (MainThread) [custom_components.dahua] Device is a doorbell=False
2024-11-02 13:46:30.505 INFO (MainThread) [custom_components.dahua] Device is a floodlight=False
2024-11-02 13:46:30.560 INFO (MainThread) [custom_components.dahua] Device supports infrared lighting=True
2024-11-02 13:46:30.561 INFO (Thread-52) [custom_components.dahua] Starting DahuaEventThread
2024-11-02 13:46:30.646 INFO (MainThread) [custom_components.dahua] Device supports profile mode=False
2024-11-02 13:46:30.847 DEBUG (MainThread) [custom_components.dahua] ClientError fetching information from http://192.168.50.137:16160/cgi-bin/configManager.cgi?action=getConfig&name=Lighting_V2
2024-11-02 13:46:30.848 WARNING (MainThread) [custom_components.dahua] Failed to sync device state for 192.168.50.137. See README to enable debug logs to get full exception
2024-11-02 13:46:30.848 DEBUG (MainThread) [custom_components.dahua] Failed to sync device state for 192.168.50.137
Traceback (most recent call last):
  File "/config/custom_components/dahua/__init__.py", line 340, in _async_update_data
    light_v2 = await self.client.async_get_lighting_v2()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/dahua/client.py", line 178, in async_get_lighting_v2
    return await self.get(url)
           ^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/dahua/client.py", line 812, in get
    raise exception
  File "/config/custom_components/dahua/client.py", line 795, in get
    response.raise_for_status()
  File "/usr/local/lib/python3.12/site-packages/aiohttp/client_reqrep.py", line 1121, in raise_for_status
    raise ClientResponseError(
aiohttp.client_exceptions.ClientResponseError: 400, message='Bad Request', url='http://192.168.50.137:16160/cgi-bin/configManager.cgi?action=getConfig&name=Lighting_V2'
2024-11-02 13:46:30.849 DEBUG (MainThread) [custom_components.dahua] Finished fetching dahua data in 0.750 seconds (success: False)
rroller commented 3 weeks ago

Can you both revert down to find the specific version things break on?

rroller commented 3 weeks ago

To me it seems like 0.9.63, but I don't understand how that would only impact some cameras and not all

ocean75 commented 3 weeks ago

When updating from 0.9.62 to 0.9.63.

coolhand72 commented 3 weeks ago

Works on .62 but not .63

rroller commented 3 weeks ago

Here are the relevant changes going from .62 to .63

Do you see how either of these could impact your specific cameras?

coolhand72 commented 3 weeks ago

My camera model is IP8M-2496E ...

rroller commented 3 weeks ago

likely related. I'll revert that change

coolhand72 commented 3 weeks ago

... but I have two others that work fine. They are models IP8M-T2669E-AI and IP8M-2779E-AI

ocean75 commented 3 weeks ago

The following change is causing the problem:

52adba8

The two cameras experiencing issues are Amcrest models IP8M-T2499E, flashed with Dahua firmware version DH_IPC-HX5X3X-Rhea_MultiLang_NP_Stream3_V2.800.0000029.0.R.221220 for camera model IPC-HDW4830EM-AS. This may be why the cameras aren’t connecting properly. When I remove or self.model.startswith("IP8M"), everything works fine on version .64.

rroller commented 3 weeks ago

Reverted in https://github.com/rroller/dahua/releases/tag/0.9.65

coolhand72 commented 3 weeks ago

Thanks @rroller

ocean75 commented 3 weeks ago

I also have one IP8M-T2599E which is connecting without issues on .64.

coolhand72 commented 3 weeks ago

.65 fixed it. Thank you sir.

ocean75 commented 3 weeks ago

Confirm .65 fixed it for me as well. Thank you.

wgumaa commented 3 weeks ago

.65 is not working for me. Same issue as https://github.com/rroller/dahua/issues/411.
I have 4 cameras on an nvr and they fail the initialisation. Goes into an initialisation loop and keep failing.

MNOiSY commented 3 weeks ago

The identical has happened here with multiple cameras since 0.9.63. 0.9.62 is the last version where they all worked.

Since 0.9.63 version and up, had one or more Amcrest cameras keep failing sync. In 0.9.66, it has finally reduced to only 1 camera which fails; An Amcrest IP8M-DT3949EW-3AI with Firmware: 2.840.00AC001.0.R, build:2022-10-19.

Restoring to 0.9.62 fixes it and restores all functionality.

Issue is identical, so I didn't want to file a new issue.

yurisvsavov commented 3 weeks ago

I have the same problem with cameras from my XVR, even with version 0.9.66. It all works fine with version 0.9.62. I have two IP cameras one is IPC-HDW4231EM-ASE, the other is IPC-HFW1320S-W and they work fine with all versions, but the 3 cameras from my XVR don't. The model of the XVR is XVR5108C-X

AubreyKloppers commented 3 weeks ago

Exact same problem with my DVR. Rolled back to 0.9.62 and it is working... using: XVR5108HS-4KL-X (Dahua)