Amcrest testers wanted: more responsive motion detection

The current implementation for motion detection uses polling. Every 5 seconds it checks to see if a motion detection event has happened. Obviously this can cause up to 5 seconds of delay between the event and the motion detection binary sensor changing to on.

The camera HTTP API does allow for subscribing to events, but that feature has yet to be used. Work is now being done to switch to this method. However, there are many camera models out there, with many different firmware versions in use. It would be helpful to gather some data about how these various cameras respond to the command.

To that end I’ve written a small Python script that will subscribe to the video motion detection event and output the received data when these events occur. If anyone would be willing to run it and share their results (especially if they are different from previously shared results), it would be much appreciated.

All you need is a command line that can run python3, and has the amcrest package installed. You can do this in a Python virtual environment like so:

python3 -m venv venv
source venv/bin/activate

Then run deactivate when you’re done.

Run the test like so:

python3 test_events.py host port user password

Where host is the camera’s IP address, port is the port number it listens on (80 is the default), user is the username of an account on the camera (admin is the default), and password is the account’s password.

When I run it on one of my cameras, I get output like this:

2020-01-22 22:42:02 'Code=VideoMotion;action=Start;index=0'
2020-01-22 22:42:05 'Code=VideoMotion;action=Stop;index=0'
2020-01-22 22:42:05 'Code=VideoMotion;action=Start;index=0'
2020-01-22 22:42:11 'Code=VideoMotion;action=Stop;index=0'

The pair of Start & Stop lines are printed for each motion detection event.

End the test by typing Ctrl-C.

Of course, motion detection needs to be enabled. You can do this via HA by using the camera.enable_motion_detection service. The test script can run at the same time HA is controlling the camera. There is no conflict between the two.

And now for the script. You can get it from here. (Be sure to use the Raw button when downloading.)

Thanks in advance!

2 Likes

Anyone willing to test and share their results???

I got a few different Amcrest cameras :slight_smile:

IP2M-841 - V2.420.AC00.18.R, Build Date: 2019-07-29

2020-01-23 15:29:39 '\r\nCode=VideoMotion;action=Start;index=0;data={\n   "RegionName" : [ "Region1" ]\n'
2020-01-23 15:29:46 '\r\nCode=VideoMotion;action=Stop;index=0;data={\n   "RegionName" : [ "Region1" ]\n'
2020-01-23 15:29:47 '\r\nCode=VideoMotion;action=Start;index=0;data={\n   "RegionName" : [ "Region1" ]\n'
2020-01-23 15:29:52 '\r\nCode=VideoMotion;action=Stop;index=0;data={\n   "RegionName" : [ "Region1" ]\n'

IP4M-1051 - V2.620.00AC000.3.R, Build Date: 2019-08-03

2020-01-23 15:30:49 '\r\nCode=VideoMotion;action=Start;index=0;data={\n   "RegionName" : [ "Region1" ]\n'
2020-01-23 15:30:57 '\r\nCode=VideoMotion;action=Stop;index=0;data={\n   "RegionName" : [ "Region1" ]\n'
2020-01-23 15:31:01 '\r\nCode=VideoMotion;action=Start;index=0;data={\n   "RegionName" : [ "Region1" ]\n'
2020-01-23 15:31:09 '\r\nCode=VideoMotion;action=Stop;index=0;data={\n   "RegionName" : [ "Region1" ]\n'

IP8M-2496 - V2.622.00AC000.0.R, Build Date: 2019-10-24

2020-01-23 15:32:38 '\r\nCode=VideoMotion;action=Start;index=0;data={\n   "RegionName" : [ "Region1" ]\n'
2020-01-23 15:32:47 '\r\nCode=VideoMotion;action=Stop;index=0;data={\n   "RegionName" : [ "Region1" ]\n'
2020-01-23 15:32:50 '\r\nCode=VideoMotion;action=Start;index=0;data={\n   "RegionName" : [ "Region1" ]\n'
2020-01-23 15:32:58 '\r\nCode=VideoMotion;action=Stop;index=0;data={\n   "RegionName" : [ "Region1" ]\n'

IP5M-1176 - 2.460.AC00.0.R, Build Date: 2017-10-23

2020-01-23 15:34:09 'Code=VideoMotion;action=Start;index=0'
2020-01-23 15:34:16 'Code=VideoMotion;action=Stop;index=0'
2020-01-23 15:34:20 'Code=VideoMotion;action=Start;index=0'
2020-01-23 15:34:27 'Code=VideoMotion;action=Stop;index=0'
1 Like

Out of curiosity, what do you get for the version_http_api property of each of these cameras?

How do I find that?

How did you get the firmware version & date? If you used the cli, then you can do the same but with:

--version-http-api

If you used the camera api in a Python shell or script, then:

camera.version_http_api

LOL I grabbed the firmware version by logging into the IP in a browser :stuck_out_tongue:

I updated my script to output the model, software version, and HTTP API version if you want to try it again with your cameras. I’m very interested in the HTTP API version numbers. Amcrest claims there isn’t a new version, yet there seems to be indications that there is.

FWIW, all three of my cameras show:

version=2.0.0

LOL 3 different versions here:

IP8M-2496E version=2.61

IP5M-1176E version=2.0.0

IP4M-1051 version=2.29

IP2M-841B version=2.29

Thanks!

I think I’ve heard of 2.29, but 2.61 seems to be yet another.

But, really, we must be mistaken. Amcrest says there isn’t a new version since March, 2017.

1 Like

Sorry I missed this post i will give it a try later… do you think it will interfere with this https://github.com/psyciknz/CameraEvents
Which is what I currently use for motion ?

Well, that code is a bit hard to follow, but it looks like it will be doing the same thing as what I’m planning to do, at least as far as communicating with the camera to get events. Honestly I don’t know, but I would assume there could be multiple “event attach” sessions going on simultaneously, but I haven’t tried it.

I’ll try and let you know…

So I ran two “attach” commands simultaneously, watching with WireShark. Seems to work fine. Each sesstion is on a separate port, and all events were sent to both sessions. So you should be able to run my script without affecting HA or the CameraEvents script in any way.

I have a 4 channel NVR, and it seems to be working… it seems Channel 1 would be index=0, Channel 2 index=1, etc…

2020-01-27 21:28:11 'Code=VideoMotion;action=Start;index=2'
2020-01-27 21:28:15 'Code=VideoMotion;action=Start;index=3'
2020-01-27 21:28:24 'Code=VideoMotion;action=Stop;index=3'
2020-01-27 21:28:25 'Code=VideoMotion;action=Stop;index=2'
2020-01-27 21:30:15 'Code=VideoMotion;action=Start;index=2'
2020-01-27 21:30:20 'Code=VideoMotion;action=Stop;index=2'
2020-01-27 21:30:28 'Code=VideoMotion;action=Start;index=2'
2020-01-27 21:30:33 'Code=VideoMotion;action=Stop;index=2'

type=NV2104E
version=3.200.AC00.0
BuildDate=05-16-2017
WebVersion=3.1.0.68011

Thanks, but just to be clear, the amcrest integration currently really doesn’t support NVRs. Desire for that has certainly been expressed by several, and I believe someone is even starting to work on it.

Yes I’m aware it doesn’t work for nvr s but was hoping it would eventually work… everything is pretty much exactly the same with the api except the index=0,1,2,3

I just now stumbled on this old post and would like to contribute if it is still a “WIP”. I sure hope so - enabling subscription vs polling for instantaneous motion detection would be very welcome!

I’m running Home Assistant 106.5/HassOS 3.11 on RasPi4. Via docker exec -t -i homeassistant /bin/bash I am able to access the container that the latest Amcrest package is installed. The venv commands didn’t work for me but I was able to run python3 test_events.py in this “protected” container directly.

I’m watching cars drive by and get test_events motion alerts instantly from my Dahua StarLights…

2020-03-04 16:11:40 '\r\nCode=VideoMotion;action=Stop;index=0;data={\n   "RegionName" : [ "Region1" ]\n'
2020-03-04 16:19:42 '\r\nCode=VideoMotion;action=Start;index=0;data={\n   "RegionName" : [ "Region1" ]\n'
2020-03-04 16:19:47 '\r\nCode=VideoMotion;action=Stop;index=0;data={\n   "RegionName" : [ "Region1" ]\n'
2020-03-04 16:21:04 '\r\nCode=VideoMotion;action=Start;index=0;data={\n   "RegionName" : [ "Region1" ]\n'
2020-03-04 16:21:09 '\r\nCode=VideoMotion;action=Stop;index=0;data={\n   "RegionName" : [ "Region1" ]\n'

2x Dahua IPC HDW5231R-Z
2x Dahua IPC HDW4231EM-AS
1x Dahua NVR5208-4KS2 (not tested)

From the camera settings/system/information/version tab:

System Version V2.800.0000013.0.R, Build Date: 2019-12-02
WEB Version V3.2.1.825578
ONVIF Version 16.12(V2.4.3.822559)

All 4 cameras running the latest version of firmware (as identified by ipcamtalk.com). The camera self-check for updates is not reliable.

I also have a couple of Amcrest cameras at our vacation house which have not been updated since purchase. I’ll run the test and obtain the versions when I can, and also will update them with the latest version I can find.

EDIT: The test_events code is not outputting an HTTP API version. Is that actually different from the firmware version?

EDIT2: Updated test_events to print cam.version_http_api (Note: cam not camera) and get:

HTTP API version=2.61

EDIT3: Thought I would try VPN to remote location and run tests. While I could login directly to camera via http in a few sec, the test failed with connection timeout, even after updating the code from 3.05 sec timeout to 15.05 in 2 places in code.

:laughing: A little over one month and it’s considered “old.” Shows how fast stuff changes in HA!

It’s not technically a WIP because I’m mostly done with implementing it. I just haven’t gotten to the point of submitting it yet. I’ve been using it myself for a while now and it seems to work very well. The reasons it hasn’t been submitted yet are first I wanted to let the previous PRs (which made the 0.106 release) get some real world usage before submitting another change, and I’ve been busy with something else. Hopefully I’ll submit a PR with the changes before too long.

Thanks for output from your cameras. Looks like it should work with these changes.

Hmm, not sure why that would be. Can you use HA to interact with those same cameras over the same VPN using the amcrest integration? If that’s not something you’d normally do, then I guess it doesn’t matter.

Yeah, it’s an “old” post when the green great contributor Thunderbird rocket doesn’t appear in a reply for weeks! :laughing:

Oh, that’s great news you’re already close to submitting a PR for this significant improvement.

Nah, I don’t connect to the remote system via VPN for HA connectivity. That was just to see if I could obtain the API version remotely via test_events, which oddly, would not connect.