Command line - amcrest camera help

Hi,
I have two amcrest cameras I need help with. I am trying to control preset positions of the cameras. From another thread I found how to control them using command line but it doesn’t seem to be working. If I go to either url in my browser I get a pop up to authenticate, I enter my details and the camera moves. These are the commands I’ve tried.

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

    amcrest_test_turn_on: 'curl -k "http://192.168.1.169:80/cgi-bin/ptz.cgi?action=start&channel=0&code=GotoPreset&arg1=0&arg2=1&arg3=0&usr=user&pwd=password"'
    amcrest_test_turn_off: 'curl -k "http://192.168.1.169:80/cgi-bin/ptz.cgi?action=start&channel=0&code=GotoPreset&arg1=0&arg2=2&arg3=0&usr=user&pwd=password"'

If anyone has any ideas please let me know

Edit: the spacing on the commands is correct in the yaml file, it’s just a copy/paste error here

I have the same problem/question for my Dahua camera.
In my configuration there is a working still camera component:

camera:

When I change the url to
http://192.168.2.11:80/cgi-bin/ptz.cgi?action=start&channel=0&code=GotoPreset&arg1=0&arg2=5&arg3=0
It will change preset to nr. 5 when I reload HASS.
Off course with above url there is no image displayed, but it is a start.

Hope someone can make something from these puzzle parts :innocent:

@matust
When doing the command:

curl -v "http://user:[email protected]:80/cgi-bin/ptz.cgi?action=start&channel=0&code=GotoPreset&arg1=0&arg2=1&arg3=0"

It gives me this answer:

*   Trying 192.168.100.3...
* TCP_NODELAY set
* Connected to 192.168.100.3 (192.168.100.3) port 80 (#0)
* Server auth using Basic with user 'user'
> GET /cgi-bin/ptz.cgi?action=start&channel=0&code=GotoPreset&arg1=0&arg2=1&arg3=0 HTTP/1.1
> Host: 192.168.100.3
> Authorization: Basic aXBjYW0xOk1hdmVuMTJGbHkyMkhlagdsjdysnJ==
> User-Agent: curl/7.54.0
> Accept: */*
>
< HTTP/1.1 401 Unauthorized
< WWW-Authenticate: Digest realm="Login to AMC000932W9W5QPCFDD24",qop="auth",nonce="14106725823",opaque="9e685d97302d09448410a3fd7b69b41e4c855f52972"
< Connection: close
< CONTENT-LENGTH: 0
<
* Closing connection 0

By looking at the documentation (Found here: https://s3.amazonaws.com/amcrest-files/Amcrest+HTTP+API+3.2017.pdf) it says:

2. When digest authentication fails, response is:
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Digest realm="DH_00408CA5EA04", nonce="000562fdY631973ef04f77a3ede7c1832ff48720ef95ad",
stale=FALSE, qop="auth"

So as far I can tell, the IP camera is refusing my connection. Though the user is administrator and has every access level. Just tested loggin in with the user, and it works fine.

Yes, that has been frustrating me as well. I can put

http://user:[email protected]:80/cgi-bin/ptz.cgi?action=start&channel=0&code=GotoPreset&arg1=0&arg2=1&arg3=0

straight into my browser without having to authenticate further and have it move the camera. I just can’t get home assistant to do it. I’ve also tried the browser component in HA but that doesn’t work either.

Hm, this is driving me crazy. I don’t get how it can work in a normal browser, but not in HA.
I know there are a lot of differences between a normal browser, and a cURL call, but we are already getting refused when trying to authenticate.

1 Like

I think I have found the problem, you might have a bit more knowledge and be able to work out a solution. The newer firmware requires Digest Authentication where as the older firmware used Basic Authentication. I believe that is why your log is showing HTTP/1.1 401 Unauthorized.

Hopefully theres a way around it

Hello,

I had the same issue and it works with --digest
curl option

Thanks @HooverG, I had been struggling with this for a while and --digest fixed it for me as well. For anyone unfamiliar with the syntax, this is what I’m successfully using for preset positions:

curl --digest -u "[username]:[password]" "http://[ipaddress]/cgi-bin/ptz.cgi?action=start&channel=0&code=GotoPreset&arg1=0&arg2=1&arg3=0"

Just replace [username], [password], and [ipaddress] with your own information. The value in “arg2” is the preset number.

1 Like

Awesome! works for me as well

@HooverG or @raff have either of you been able to get this working for enable/disable motion?

http://admin:mypassword@[ipaddress]/cgi-bin/configManager.cgi?action=setConfig&MotionDetect[0].Enable=true

works in the chrome browser. Using the following doesn’t seem to work for enable/disable motion as a command line switch

curl --digest -u "[username]:[password]" "http://[ipaddress]/cgi-bin/configManager.cgi?action=setConfig&MotionDetect[0].Enable=true"

Yes it works for me.
I don’t have access to my config right now but I’ll update this post later today.

At first glance, escape the [ ]
curl --digest -u "[username]:[password]" "http://[ipaddress]/cgi-bin/configManager.cgi?action=setConfig&MotionDetect\[0\].Enable=true"

Edit : Also I think I don’t have " surrounding the user:password

Thanks for the response that fixed it. The command I was using was actually a little wrong. I had modified \[0\] to make it work in the browser but it failed in the command line. Working now, cheers

1 Like

Do you know how to read if motion has been detected this way as well? Could you share it?

I can only detect motion using the amcrest component

Is there a way to use the amcrest camera component and NOT get a video feed? I already have my feeds from zoneminder. I just need the sensor for motion.