I had a Foscam camera setup but decided to buy 3 Amcrest cameras. Here is my configuration for the one Amcrest cameras I have set up. I am making this page look just like the Foscam page located here so that hopefully Home-Assistant adds it to their website. Which btw, the link to the PDF is broken (change it to this please!).
Since there is no component for Amcrest yet and the Foscam component doesn’t work with Amcrest, you have to use the mjpeg component like this:
camera:
platform: mjpeg
mjpeg_url: http://admin:password@ipaddress:80/cgi-bin/mjpg/video.cgi
name: My Camera Name
Hopefully they add an Amcrest camera module.
This requires an Amcrest IP Camera with PTZ (Pan, Tilt, Zoom) and CGI functionality (Source)
Amcrest Cameras can be controlled by Home Assistant through a number of CGI commands. The following outlines examples of the switch, services, and scripts required to move between 2 preset destinations while controlling motion detection, but many other options of movement are provided in the Amcrest CGI User Guide linked above.
The switch.amcrest_motion
will control whether the motion detection is on or off. This switch supports statecmd
, which checks the current state of motion detection.
switch:
platform: command_line
switches:
amcrest_motion:
oncmd: 'curl -k -u admin:password "http://ipaddress:80/cgi-bin/configManager.cgi?action=setConfig&MotionDetect\[0\].Enable=true"'
offcmd: 'curl -k -u admin:password "http://ipaddress:80/cgi-bin/configManager.cgi?action=setConfig&MotionDetect\[0\].Enable=false"'
statecmd: 'curl -k --silent -u admin:password "http://ipaddress:80/cgi-bin/configManager.cgi?action=getConfig&name=MotionDetect\[0\].Enable" | sed "s/^.*\(.\{5\}\)$/\1/"'
value_template: '{{ value == "true" }}'
The service shell_command.amcrest_turn_off sets the camera to point down and away to indicate it is not recording, and shell_command.amcrest_turn_on sets the camera to point where I’d like to record. h of these services require preset points to be added to your camera. See source above for additional information.
shell_command:
#Created a preset point in Amcrest Web Interface numbered '2' which essentially points the camera down and away
amcrest_turn_off: 'curl -k "http://ipaddress:80/cgi-bin/ptz.cgi?action=start&channel=0&code=GotoPreset&arg1=0&arg2=2&arg3=0"'
#Created a preset point in Amcrest Web Interface numbered '1' which points in the direction I would like to record
amcrest_turn_on: 'curl -k "http://ipaddress:80/cgi-bin/ptz.cgi?action=start&channel=0&code=GotoPreset&arg1=0&arg2=1&arg3=0"'
The script.amcrest_off
and script.amcrest_on
can be used to set the motion detection appropriately, and then move the camera. These scripts can be called as part of an automation with device_tracker
triggers to set home
and not_home
modes for your Amcrest and disable motion detection recording while home
.
script:
amcrest_off:
sequence:
- service: switch.turn_off
data:
entity_id: switch.amcrest_motion
- service: shell_command.amcrest_turn_off
amcrest_on:
sequence:
- service: switch.turn_off
data:
entity_id: switch.amcrest_motion
- service: shell_command.amcrest_turn_on
- service: switch.turn_on
data:
entity_id: switch.amcrest_motion
To automate Amcrest being set to “on” (facing the correct way with motion sensor on), I used the following simple automation:
automation:
- alias: Set Amcrest to Away Mode when I leave home
trigger:
platform: state
entity_id: group.family
from: 'home'
action:
service: script.amcrest_on
- alias: Set Amcrest to Home Mode when I arrive Home
trigger:
platform: state
entity_id: group.family
to: 'home'
action:
service: script.amcrest_off