core: Amcrest Camera error: Bad request for VideoMotion

The problem

After I upgraded from Home Assistant Core 0.107.7 to 0.108.1, I see the following warnings and errors from my Amcrest Camera:

It retries 30 times:

WARNING (Amcrest Amcrest Camera) [amcrest.http] <Camera Name> Trying again due to error: HTTPError('400 Client Error: Bad Request for url: http://camera-ip:80/cgi-bin/eventManager.cgi?action=attach&codes=%5BVideoMotion%5D')

Followed by:

ERROR (Amcrest Amcrest Camera) [homeassistant.components.amcrest] Amcrest Camera camera offline: Too many errors

This repeats every couple of seconds.

The camera model is IP2M-841-V3

Removing the motion_detected binary sensor from the config fixes the issue.

Environment

  • Home Assistant Core release with the issue: 0.108.1
  • Last working Home Assistant Core release (if known): 0.107.7
  • Operating environment (Home Assistant/Supervised/Docker/venv): Docker
  • Integration causing this issue: Amcrest
  • Link to integration documentation on our website: https://www.home-assistant.io/integrations/amcrest/

Problem-relevant configuration.yaml

amcrest:
  - host: !secret amcrest_ip
    username: !secret amcrest_username
    password: !secret amcrest_password
    resolution: low
    binary_sensors:
      - motion_detected
      - online

Traceback/Error logs

WARNING (Amcrest Amcrest Camera) [amcrest.http] <Camera Name> Trying again due to error: HTTPError('400 Client Error: Bad Request for url: http://camera-ip:80/cgi-bin/eventManager.cgi?action=attach&codes=%5BVideoMotion%5D')

ERROR (Amcrest Amcrest Camera) [homeassistant.components.amcrest] Amcrest Camera camera offline: Too many errors

Additional information

I think this may have been caused by #32818, but I don’t have a good understanding of the Amcrest API, so I may be wrong.

Motion detection used to work in 0.107.7.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 32 (14 by maintainers)

Most upvoted comments

Hi @GeorgeSG, the problem I have and I am sure many others, is that Dahua only support firmwares for a short while. For example this is the last firmware for mine… as far as i know Device Type IPC-HDW4300S Software Version 2.420.0009.0.R, build : 2015-11-06 WEB Version 3.2.1.305503 ONVIF Version 2.4.1

So given that the cameras clearly have a bug for not being able to accept a proper encoded URL, ill flag a bug on Python Amcrest and see if any miles are achieved.

I have the same issue upgrading from 0.107.7 to 0.108.6, with the 400 Client Errors on generic Dahau cameras. They don’t like the command URLencoding the []. I did a quick and dirty patch to event.py, and got it working…


--- event.py.orig       2020-04-17 22:16:11.488167900 -0400
+++ event.py    2020-04-17 23:21:46.830314848 -0400
@@ -203,7 +203,8 @@
                 timeout_cmd = (self._timeout_default, None)

         ret = self.command(
-            "eventManager.cgi?action=attach&codes=[{0}]".format(eventcodes),
+            'eventManager.cgi?action=attach&codes=',
+            param='[All]',
             retries=retries,
             timeout_cmd=timeout_cmd,
             stream=True,

The param appends without URLencoding. Hope that helps!

/Mike