home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.19k stars 30.57k forks source link

0.112.2 Amcrest - enable/disable motion_recording #37726

Closed redwngsrul closed 4 years ago

redwngsrul commented 4 years ago

The problem

2020-07-10 09:54:32 ERROR (SyncWorker_6) [homeassistant.components.amcrest.camera] Could not set Den 2 camera 
motion recording to True due to error: AmcrestCommandFailed

Problem with only 1 model (IP3M-HX2) Amcrest camera, using the command to enable/disable motion_recording. I have two of these IP3M-HX2's that are both currently broken with this issue. All other functionality with both cameras, including motion detection sensors, etc, seems to function normally. Prior in-use version 0.111.0 the enable/disable of the motion recording functioned correctly too. I have other model Amcrest cameras that are still fully functional, including the enable/disable motion_recording. Other fully functioning models include: IP4M-1026, IP3M-943, IPM-HX1.

The IP3M-HX2's are running the newest version Amcrest firmware available 2.620.000 (2019-08-19), and is likely different firmware than the other models. The Amcrest API for the IP cameras has not changed in some time to my knowledge with this still being the most recent https://s3.amazonaws.com/amcrest-files/Amcrest+HTTP+API+3.2017.pdf.

I looked at the source code here https://github.com/home-assistant/core/tree/dev/homeassistant/components/amcrest within camera.py and found the code has been altered recently (18d), although I'm not great with python and have reached my troubleshooting limits.

Environment

arch x86_64
dev false
docker true
hassio false
installation_type Home Assistant Container
os_name Linux
os_version 4.14.24-qnap
python_version 3.7.7
timezone America/Detroit
version 0.112.2
virtualenv false

Problem-relevant configuration.yaml

- host: 192.168.1.84
  name: "Den 2"
  username: !secret amcrest_un
  password: !secret amcrest_pw
  stream_source: snapshot
  binary_sensors:
    - motion_detected

Traceback/Error logs

Log Details (ERROR)

Logger: homeassistant.components.amcrest.camera
Source: components/amcrest/helpers.py:20
Integration: Amcrest (documentation, issues)
First occurred: 1:15:49 PM (2 occurrences)
Last logged: 1:15:49 PM 

Additional information

probot-home-assistant[bot] commented 4 years ago

Hey there @pnbruckner, mind taking a look at this issue as its been labeled with an integration (amcrest) you are listed as a codeowner for? Thanks! (message by CodeOwnersMention)

pnbruckner commented 4 years ago

Prior in-use version 0.111.0 the enable/disable of the motion recording functioned correctly too.

That may or may not be true. Before 0.112, as far back as I know, this integration operated in an "optimistic" mode. That means when a command was sent to the camera to change a setting like this, it just assumed it worked and set the attribute accordingly. Unfortunately I discovered that often the new setting did not take effect, even if the command was successfully transmitted to the camera. I mostly noticed this with turning video streaming & recording on & off, but after further testing I discovered it also happened with other settings such as audio on & off, etc.

So, starting in 0.112, the integration no longer operates in optimistic mode. After sending a command it retrieves the setting and checks that it actually changed to the desired value. If not it will retry the command, up to three times before giving up. Also, the attribute will be set according to what the setting in the camera actually is.

So, it's very possible it never worked on these cameras, even if the HA entity attribute implied it did.

Also, regarding the API, it has changed, but Amcrest will not provide an updated spec, or even admit it has changed. So there's nothing I can do about that.

redwngsrul commented 4 years ago

Ok that may be 100% possible. I do have 0 recorded motion incidents on both cameras. I could might try to figure out the API call manually outside of HASS see what I can do from there. The python-amcrest github project says it supports the IP3M-HX2 but perhaps not fully.

Thanks for the speedy reply.

pnbruckner commented 4 years ago

The python-amcrest github project says it supports the IP3M-HX2 but perhaps not fully.

Yeah, unfortunately that does not track firmware versions. We've been discovering that some newer firmware versions for some models of camera no longer properly support the only published HTTP API spec.

redwngsrul commented 4 years ago

@pnbruckner I installed the python-amcrest project in a sandbox environment and did some toying with it. Since you're codeowner for the Amcrest integration and you've contributed to the python-amcrest project, I wonder if I can ask you to explain to me how to use the amcrest-cli tool to SET motion-recording true/false? I'm not sure what the modifier syntax is to SET motion-recording.

For my IP3M-HX2 cameras running firmware 2.620.00, they return a value of version=2.29 to the amcrest-cli command for --version-http-api, while all my other cameras running firmware 2.420 return version=2.0.0.

When I use amcrest-cli and with modifier --motion-detection, all the cameras have very similar outputs, but the newer firmware has an extra line regarding DetectVersion=V3.0. What's surprising to me is if I can use the cli tool and get a valid response from the camera, why isn't the Home Assistant integration able to GET/SET the motion-recording status? If I log into the browser UI for one of my cameras and manually toggle the motion-recording to ON, my Home Assistant will still not change the state of motion recording.

At this point, without understanding how to use amcrest-cli to SET motion-recording, I can't really troubleshoot any further. If you could provide any help to me, I'd appreciate it. I'd also be willing to use my sandbox to test different scenarios if you'd like.

pnbruckner commented 4 years ago

@redwngsrul I really haven't used amcrest-cli much, and right now I can't seem to get it working. So I can't help much with it. Try opening an issue on the python-amcrest repo.

Regarding the API version, as I said, it has changed, but Amcrest won't acknowledge that (I've tried multiple times, and so have others) and they won't provide any details on what has changed. Since the camera you're having issues with implies it's using a new version of the API, there isn't much I can do to make HA work with it. If it works, it works. If it doesn't, well...

Not sure why you're comparing getting the motion detection setting via the cli to getting the motion recording setting via HA. Those are two different settings.

I'd like to help, but if Amcrest won't support this effort, then my hands are tied.

In theory Amcrest cameras also support the ONVIF standard. You might want to try the corresponding HA integration with your newer camera.

redwngsrul commented 4 years ago

Just wanted to update FYI @pnbruckner . I was able to get the motion_recording enable/disable and status working by downgrading the firmware of my IP3M-HX2 cameras. My firmware is version V2.520.AC00.18.R.20170629 now. Per Amcrest support, they told me that the firmware V2.620 I was running previously had an updated API version that had removed the functionality for the motion recording. Now with the downgraded firmware, I tested and all functions of the HASS Amcrest service and it seems to work properly.