tchellomello / python-amcrest

A Python 2.7/3.x module for Amcrest and Dahua Cameras using the SDK HTTP API.
GNU General Public License v2.0
216 stars 76 forks source link

Enable/disable motion detection #129

Open zetix opened 5 years ago

zetix commented 5 years ago

The documentation states there is MotionDetection but does this allow the ability to enable/disable motion detection?

pnbruckner commented 4 years ago

Yes. See the motion_detection setter in motion_detection.py.

zetix commented 4 years ago

I can't seem to get the motion_detection to work.

Python version: 2.7.16 Raspberry Pi 3b running Raspbian Installed python-amcrest with: sudo pip install amcrest Installed argcomplete with: sudo pip install argcomplete Enabled amcrest-cli autocomplete with:

sudo su
echo 'eval "$(register-python-argcomplete amcrest-cli)"' >  /etc/profile.d/amcrest-cli-autocomplete.sh

Tried running via python:

>>> from amcrest import AmcrestCamera
>>> camera = AmcrestCamera('192.168.1.225', 80, 'USER', 'PASS').camera
>>> camera.motion_detection(False)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'unicode' object is not callable
>>> camera.motion_detection(True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'unicode' object is not callable

In Terminal:

pi@rpi3:~ $ amcrest-cli -H 192.168.1.225 -u USER -p PASSWORD --motion-detection False
No handlers could be found for logger "amcrest.http"
Traceback (most recent call last):
  File "/usr/local/bin/amcrest-cli", line 912, in <module>
    main()
  File "/usr/local/bin/amcrest-cli", line 887, in main
    camera.motion_detection = args.motion_detection
  File "/usr/local/lib/python2.7/dist-packages/amcrest/motion_detection.py", line 44, in motion_detection
    'setConfig&MotionDetect[0].Enable={0}'.format(opt.lower())
  File "/usr/local/lib/python2.7/dist-packages/amcrest/http.py", line 163, in command
    return self._command(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/amcrest/http.py", line 203, in _command
    raise CommError(error)
amcrest.exceptions.CommError: 400 Client Error: Bad Request for url: http://192.168.1.225:80/cgi-bin/configManager.cgi?action=setConfig&MotionDetect%5B0%5D.Enable=false

Added the camera to ~/.config/amcrest.conf so the full path is /home/pi/.config/amcrest.conf and running it in Terminal:

pi@rpi3:~ $ amcrest-cli --camera room --motion-detection False
No handlers could be found for logger "amcrest.http"
Traceback (most recent call last):
  File "/usr/local/bin/amcrest-cli", line 912, in <module>
    main()
  File "/usr/local/bin/amcrest-cli", line 887, in main
    camera.motion_detection = args.motion_detection
  File "/usr/local/lib/python2.7/dist-packages/amcrest/motion_detection.py", line 44, in motion_detection
    'setConfig&MotionDetect[0].Enable={0}'.format(opt.lower())
  File "/usr/local/lib/python2.7/dist-packages/amcrest/http.py", line 163, in command
    return self._command(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/amcrest/http.py", line 203, in _command
    raise CommError(error)
amcrest.exceptions.CommError: 400 Client Error: Bad Request for url: http://192.168.1.225:80/cgi-bin/configManager.cgi?action=setConfig&MotionDetect%5B0%5D.Enable=false
pnbruckner commented 4 years ago

camera.motion_detection(False) Traceback (most recent call last): File "", line 1, in TypeError: 'unicode' object is not callable

The motion_detection setter takes a string, not a bool. So try this instead:

camera.motion_detection("false")

I don't know why it didn't work when you used the cli w/ Python 2. I'm only concerned with how this works with Home Assistant (which, BTW, uses only Python 3.) Maybe @tchellomello could look into those problems.

zetix commented 4 years ago

I tried it with a string but I get the same error as without.

>>> camera.motion_detection("false")
Traceback (most recent call last)
File "<stdin>", line 1, in <module>
TypeError: 'Unicode' object is not callable

HTTP-API Version is 2.29 Firmware build is 2019-07-29

pnbruckner commented 4 years ago

Oh, wait, that's not how a setter is used. I should have said try this:

camera.motion_detection = "false"
zetix commented 4 years ago

It's showing the same error as when I type the amcrest-cli command from terminal.

>>> camera.motion_detection = "false"
No handlers could be found for logger "amcrest.http"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/amcrest/motion_detection.py", line 44, in motion_detection
    'setConfig&MotionDetect[0].Enable={0}'.format(opt.lower())
  File "/usr/local/lib/python2.7/dist-packages/amcrest/http.py", line 163, in command
    return self._command(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/amcrest/http.py", line 203, in _command
    raise CommError(error)
amcrest.exceptions.CommError: 400 Client Error: Bad Request for url: http://192.168.1.225:80/cgi-bin/configManager.cgi?action=setConfig&MotionDetect%5B0%5D.Enable=false

Also copying and pasting the url directly into my browser gives a bad request error. There's post on the Amcrest forum saying that the previous and current firmware released doesn't support setConfig for the API.

pnbruckner commented 4 years ago

Well, not much that can be done about that at this time. I've tried several times, through several different channels, to get Amcrest to admit that the HTTP API has changed and to provide a new spec that documents the new API. But they've consistently denied that the API has changed and have stated that there is no newer revision of the spec available. I've personally not updated the firmware in my cameras and have refrained from buying any new ones from Amcrest until they cease their denial and provide a new spec.

zetix commented 4 years ago

It's pretty sad cause the hardware and specs are great, but the software and support is really lackluster.

Mark612 commented 4 years ago

I also opened a support ticket on this issue. They concluded by closing the ticket as: "_Good afternoon,

The R&D team is currently looking into this issue and update the firmware accordingly. Unfortunately at the moment we do not have an ETA on any release dates for further updates. I apologize for the inconvenience._"

nfour14 commented 4 years ago

Has this been resolved? I am looking to do the same (enable/disable motion detection).

nfour14 commented 4 years ago

On an IPM-721B when I try to set motion detection, I actually get a return of "OK"

http://X.X.X.X:8080/cgi-bin/configManager.cgi?action=setConfig&MotionDetect[0].Enable=true

But when I view it either via API or UI, it says its not enabled:

http://X.X.X.X:8080/cgi-bin/configManager.cgi?action=getConfig&name=MotionDetect

I guess its still not working on Amcrest's end, but its certainly not giving me an error. Its just not working.

nfour14 commented 4 years ago

FYI - Looks like this is still broken according to Amcrest. Set commands do not work for motion detection. Unfortunately that will be the end of the road for me and Amcrest cameras.

luisbattle commented 3 years ago

I am having the same problem........... Always received OK but the Motion Detection not enable/disable..... I can enable/disable from Android app only. I leave one thing that listen events and take photography from api and then send the photography to telegram, may be you want improve and add new features for telegram ;) https://github.com/luisbattle/amcrest-read-events-and-send-photo

nfour14 commented 3 years ago

Same, it works fine from their applications, but not from the API. Its on the Amcrest end. They are still not going to address it. Its a bummer since I was going to script up some on/off times and movement.

I am having the same problem........... Always received OK but the Motion Detection not enable/disable..... I can enable/disable from Android app only. I leave one thing that listen events and take photography from api and then send the photography to telegram, may be you want improve and add new features for telegram ;) https://github.com/luisbattle/amcrest-read-events-and-send-photo

luisbattle commented 3 years ago

My idea was to program the motion detection on and off by sending commands from telegram but we will have to wait for them to solve it, I hope it will be soon...

nfour14 commented 3 years ago

FYI - I have a new 841B v3 camera and the motion detection on/off seems to work now.

luisbattle commented 3 years ago

Hi @rtmgllc, I hope you are well. Could you share the software camera version ? I have this version: Software VersionV2.420.AC00.18.R, Build Date: 2020-02-17

nfour14 commented 3 years ago

V2.800.0000000.6.R, Build Date: 2020-03-1

luisbattle commented 3 years ago

I am tryng access to amcrest website to check if new releases exists but the web doesnt work........... image

nfour14 commented 3 years ago

The website is up, thats Cloudflare blocking you. Not sure why, sorry.

luisbattle commented 3 years ago

:(

nfour14 commented 3 years ago

Sadly, while motion detection on/off works on the 841, ptz control does not. On the 741 ptz control works, but motion on/off does not. :(

nfour14 commented 3 years ago

Luckily, you can use the ptz preset list to move the camera.