Successfully Configuring Motion Detection with Amcrest IP Camera

Hi everyone, I wanted to share my experience in setting up motion detection with my Amcrest IP4M-956E camera. I’ve been trying to get this working for a while and finally managed to crack it! Here’s how I did it:

First, I configured the camera using the HTTP binding in openHAB. The camera doesn’t have a built-in feature for HTTP calls when motion is detected, but I found a workaround using the Amcrest API to query the event info. Here’s the item setup I used:

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)]” }

Next, I created a JavaScript file to translate the camera’s responses into TRUE or FALSE. This was essential for the rule engine to understand when motion was detected:

// Wrap everything in a function
(function(i) {
var response = i.replace(/(\r\n|\n|\r)/gm, “”);
if(response == ‘channels[0]=0’){
return “TRUE”
}else{
return “FALSE”
};
})(input)

Finally, I set up a rule to trigger the front light for 5 minutes when motion is detected. I added checks to ensure the light doesn’t flicker unnecessarily and only activates during specific times:

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 setup has been working perfectly for me. The only challenge was figuring out how to interpret the camera’s response codes correctly. I hope this helps someone else who’s struggling with similar issues!

If anyone has tips or alternative methods, I’d love to hear them. Let’s keep the knowledge flowing! :blush: