HOW TO: Amcrest Camera Home/Away Mode like Foscam

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
4 Likes

Thanks for posting this!!

A few updates as I think the components have changed since you wrote it.

The switch component was updated to the command_on vs oncmd, etc.

switch:    
  - platform: command_line
    switches:
      amcrest_motion:
        command_on: 'curl -k -u admin:password "http://192.168.1.XX:80/cgi-bin/configManager.cgi?action=setConfig&MotionDetect\[0\].Enable=true"'
        command_off: 'curl -k -u admin:password "http://192.168.1.XX:80/cgi-bin/configManager.cgi?action=setConfig&MotionDetect\[0\].Enable=false"'
        command_state: 'curl -k --silent -u admin:password "http://192.168.1.XX:80/cgi-bin/configManager.cgi?action=getConfig&name=MotionDetect\[0\].Enable" | sed "s/^.*\(.\{5\}\)$/\1/"'
        value_template: '{{ value == "true" }}'

The shell commands needed the username and password added to work.

shell_command:
  amcrest_turn_off: 'curl -k -u admin:password "http://192.168.1.XX:80/cgi-bin/ptz.cgi?action=start&channel=0&code=GotoPreset&arg1=0&arg2=2&arg3=0"'
  amcrest_turn_on: 'curl -k -u admin:password "http://192.168.1.XX:80/cgi-bin/ptz.cgi?action=start&channel=0&code=GotoPreset&arg1=0&arg2=1&arg3=0"'

Thanks for updating it. I would edit the post, but I can’t seem to find any way to do that.

Is the motion on/off action still working? I have it configured but can’t get it to fire from the home assistant services interface. I get the toast message to say its been called but nothing happens.

If I put go to the address into my browser I get asked to input my username and password and get the following response

Error
ErrorID=0, Detail=Invalid Authority!

Cheers!

Was it working before?
Did you install a recent firmware update?

I’ve only just got the cameras and they are on the latest firmware, so I’m not sure if it’s me or something changed. Pasting the shell commands for preset positions into the browser is working though.

According to their SDK, this means “The user fails in authentication or doesn’t include the right accessing the resource.”

Maybe you mistyped the username or password?

Hmmm I do think that’s it. When I paste the address into the browser I get the authentication pop up which I am filling in with my password manager. I used the same method for the shell command present position and it worked fine.

The full command with the username and password has to be run. You can try it without home assistant if you have any Mac/Linux machine. You can’t leave out the username and password though.

Ok I’ve given up on the enable/disable motion for now since there seems to be something else wrong.

I think the command is right for setting the position (when I put the address in the browser I get the login pop up, I enter my details and then see a page saying ok and the camera moves). These are the commands I’m calling from home assistant to move to the preset position but I can’t get the shell to work from the services panel.

amcrest_turn_off: 'curl -k -u admin:mypassword "http://192.168.1.XXX:80/cgi-bin/ptz.cgi?action=start&channel=0&code=GotoPreset&arg1=0&arg2=2&arg3=0"'
amcrest_turn_on: 'curl -k -u admin:mypassword "http://192.168.1.XXX:80/cgi-bin/ptz.cgi?action=start&channel=0&code=GotoPreset&arg1=0&arg2=1&arg3=0"'

In services I’m selecting > shell_command then service > amcrest_turn_off I get the toast saying it’s be called but no response from the camera

When I send cURL commands to my Foscams, I use basic authentication in the url like this:

curl -k "http://192.168.1.13/decoder_control.cgi?command=37&user=USER&pwd=PASSWORD"

Maybe try that? It’s working for me.

Thanks, I’ll give it a try

Another thing you can try is adding it in like this:

http://hass:[email protected]/video/mjpg.cgi

which works for my other two cams.

@rpitera / @matust Did you ever get the PTZ working with the Amcrest Cameras?

No, I’ve tried quite a few things but just can’t get it to work

I have been trying to get pzt to work in reference to this post. I’m using a more recent set up of the AIO on a RP3 so the path is different but I still can’t get it to work

I have spent some more time trying to get the cameras working but I haven’t had any luck. I did find on the Amcrest forum that a firmware update they disabled Basic Authentication in favour of Digest Authentication. This doesn’t mean to much to me as I have little technical knowledge but I guess it explains why the current commands work for some and not for others.

For what it’s worth, I too found that digest authentication was required. Therefore, the command should be updated to:

amcrest_turn_off: ‘curl -k --digest -u admin:mypassword “http://192.168.1.XXX:80/cgi-bin/ptz.cgi?action=start&channel=0&code=GotoPreset&arg1=0&arg2=2&arg3=0”’