Amcrest IP Camera Motion Detection Setup Guide

Hi everyone! I wanted to share my experience setting up motion detection on my Amcrest IP4M-956E camera. While the camera itself doesn’t have built-in HTTP notifications for motion, I found a workaround using the http binding in openHAB. Here’s how I did it:

Item Setup

I created a string item to monitor motion status:
plaintext
String Amcrest_Motion “Motion detected [%S]” (Group) { http=“<
[http://user:pass@x.x.x.x/cgi-bin/eventManager.cgi?action=getEventIndexes&code=VideoMotion:2000:JS(motiondetect.js)]” }

This item queries the camera’s event manager and uses a JavaScript file to interpret the response.

JavaScript Parsing

I wrote a small script to convert the camera’s response into a readable format:
javascript
// Wrap everything in a function
(function(i) {
var response = i.replace(/(
|
|
)/gm, “”);
if(response == ‘channels[0]=0’){
return “TRUE”
}else{
return “FALSE”
};
})(input)

This script checks if motion is detected and returns “TRUE” or “FALSE” accordingly.

Rule Implementation

To automate the lights based on motion, I set up the following rule:
plaintext
var Timer tOutdoorMotionLightsOff = null
var DateTime dtOutdoorMotionTriggerTime = new DateTime(now)
var DateTime motionSunset = null

rule “Driveway Motion”
when Item Amcrest_Motion changed
then
logInfo(“Timer”, “Motion Detected!”)
motionSunset = new DateTime(parse(now.getYear()+“-”+now.getMonthOfYear()+“-”+now.getDayOfMonth()+“T”+strSunset.state))
if ((Amcrest_Motion.state == “TRUE”) && ((motionSunset.isBeforeNow()) || (now.getHourOfDay() < 7)) && (Light_Outdoor_Front.state == OFF) && (dtOutdoorMotionTriggerTime.plusMinutes(6).isBeforeNow())) {
logInfo(“Timer”,“Driveway motion detected. Turning on light and creating off timer”)
sendCommand(Light_Outdoor_Front, ON)
if(tOutdoorMotionLightsOff!=null) {
logInfo(“Timer”,“Timer tOutdoorMotionLightsOff cancelled”)
tOutdoorMotionLightsOff.cancel()
}
tOutdoorMotionLightsOff = createTimer(now.plusMinutes(5)) [|
logInfo(“Timer”,“Timer tOutdoorMotionLightsOff executed”)
dtOutdoorMotionTriggerTime = new DateTime(now)
sendCommand(Light_Outdoor_Front, OFF)
]
}
end

This rule turns on the front light for 5 minutes when motion is detected, but only after sunset or before 7 AM to avoid false triggers from sunrise or daylight.

Tips and Considerations

  • False Triggers: The act of turning off the light can sometimes trigger motion detection again. The 6-minute delay between trigger events helps prevent this.
  • Camera Placement: Ensure the camera is positioned to cover the desired area without unnecessary blind spots.
  • Firmware Updates: Regularly check for firmware updates on your camera to ensure optimal performance.

I hope this guide helps others set up motion detection on their Amcrest cameras! Let me know if you have any questions or suggestions. :slight_smile: