Amcrest camera component

Is anyone using the Amcrest camera successfully? I have mine setup, it shows the image in the dashboard and updates periodically, but if I click the image to open the popup window I get an empty window that says ‘idle’ but no image. In the log there are a bunch of Python errors (sorry, at work and I forgot to save them), which of course would be helpful. Just wondering if it’s working for anyone else, or are they seeing the same problem? I will post the log tonight.

edit: This is the camera I have, it is not a PTZ.

Trying right now (just came in) and not having any luck. I’m getting this:

6-12-13 15:24:38 homeassistant.bootstrap: Invalid config for [camera.amcrest]: required key not provided @ data['host']. Got None. (See ?:?). Please check the docs at https://home-assistant.io/components/camera.amcrest/

my setup is:

camera 6:
 platform: amcrest
 ip: !secret camera_ip6
 username: !secret camera_username
 password: !secret camera_password
 name: Back Yard
 port: 18816

Does the ip need to have “http://”? my foscams did not need that.

The error message is telling you the problem, it’s host not IP. Try this:

camera 6:
 platform: amcrest
 host: !secret camera_ip6
 username: !secret camera_username
 password: !secret camera_password
 name: Back Yard
 port: 18816

Crap… thank you! I’ve been so frustrated fighting with my foscams that I didn’t even see that. (obviously) Thanks again!

What about:

16-12-13 15:50:06 homeassistant.components.camera.amcrest: Unable to connect to Amcrest camera: HTTPConnectionPool(host='http', port=80): Max retries exceeded with url: //192.168.1.206:18816/cgi-bin/global.cgi?action=getCurrentTime (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x6f260230>: Failed to establish a new connection: [Errno -2] Name or service not known',))

I didn’t want to seem foolish so I tried the url and was able to connect directly to it. The port is correct (18816) but it looks as though it is trying to connect to 80?

Googling HTTPConnectionPool now…

Ok so I was foolish… while troubleshooting I had added an “http”. removed that and now getting:

16-12-13 16:21:27 homeassistant.components.camera.amcrest: Unable to connect to Amcrest camera: HTTPConnectionPool(host='192.168.1.206', port=18816): Read timed out. (read timeout=3)

No idea. 18816 seems like an odd port choice. Mine is on the default of 80 and it just works. Does connecting to

http://@192.168.1.206:18816/cgi-bin/global.cgi?action=getCurrentTime

work?

I ended up connecting to it as an mjpeg camera. Then this morning I removed it because it wouldn’t keep a wifi signal. I’m sure I will circle back to it at some point.

I may do the same, as at least as mjpeg it worked in the popup. Mine is a POE camera, so no issues with WiFi.

Hello @Corey_Johnson

Is your web interface running on port 18816? Did you change the configuration on Amcrest web interface?

If you try: http://<192.168.1.206:18816, are you able to see username/password form to log into Acmrest software?

Please let me know if you need any help setting up the amcrest component, I’d be mora than happy assisting you to troubleshoot it. I’m working to extend it by adding some sensors and control to PTZ presets via HA, which will require the component.

Another good advice is to increase to 20 the max number of connections on the admin interface on Amcrest software.

mmello

I was able to log into it properly and use it via Zoneminder as rstp using the same settings, port, user/pass but was not able to use the Amcrest component in HASS. I have it running now using the generic component. I can try to increase the max connections later and reconfigure as Amcrest to test.

@Corey_Johnson would you mind sharing the configuration?

Note that you have to use the HTTP port and not the RSTP port to be able to use Amcrest component.

Please let me know if you need any help.

I’ll have to recheck at a later time… I came home to the wife having AT&T install a new modem/router (unexpected) and have been trying to everything reconnected/reconfigured… ugh.

I’m getting connection timeouts when trying to view the streaming video. Using the mjpeg platform does work for me, but ideally the Amcrest platform should “just work”.

I dug through the codebase and found that the platform is currently trying to construct an mjpeg screen based on still snapshots. However, Amcrest cameras do provide a native mjepg stream - what if we just used that instead?

The underlying Python library does have a method for obtaining that stream: https://github.com/tchellomello/python-amcrest/blob/master/src/amcrest/special.py#L60 I tried implementing handle_async_mjpeg_stream myself using this method, but I’m not a Python developer, so I’m not making any progress. (Specifically, I don’t know how to pass that library’s response stream along in a way that makes HA happy).

IMO there are three ways this could be implemented:

  1. Call self._data.camera.mjpg_stream() and somehow return that raw response data out
  2. Skip the convenience function and call self._data.camera.command('mjpg/video.cgi?channel=0&subtype=1') to get the response object, and somehow return that out
  3. Build and call the URL ourselves using aiohttp

While a native stream would be nice, there is one potential downside - as noted in this comment, newer firmware does not support mjpeg streaming off the high-resolution video - it’s only doable with the sub-stream. Personally, I’m okay with that, as my Amcrest camera does offer both streams. But to accomadate other users, we could:

  • Ignore the resolution option for the live stream, forcing everyone to use the low resolution mjpeg stream (as it should “just work” for everyone)
  • Add a new configuration option like stream_type with values snapshot (current functionality) or mjpeg (use the native stream
  • Somehow intelligently choose one methodology over the other

I’d prefer the first option as its the easiest and has the widest compatibility, but I’m open to either of the others.

@tchellomello Seeing as you’re leading the effort to implement Amcrest cameras, do you have any thoughts or pointers? I’d be happy to implement this myself - I just need a nudge in the right direction :slight_smile:

1 Like

Hello @colinodell,

Great comment. Yes, I think you are right and we can definitely modify the component for a better performance and user experience.

If we decide for mjpg_stream() I think we can remove the resolution option or make it available only if the user prefer the snapshot method.

I’m going to test it and I’ll post here a test code.

@colinodell since you provided a great input, I’m working to extend a few sensors to the Amcrest cameras and I would like to hear your opinion about it. Could you check the post at Amcrest Camera Sensor - What would be nice to have in your opinion? and give your input about it?

Thank you!
Marcelo

Hi Marcelo,

I took a stab at implementing direct MJPEG streaming: https://github.com/home-assistant/home-assistant/pull/5217 My implementation uses aiohttp to retrieve the /mjpg/video.cgi stream from the camera.

I had originally tried to use the mjpg_stream() method from the amcrest library, but I couldn’t figure out how to properly take that raw response from mjpg_stream() and create an aiohttp response stream while considering:

  • How to easily obtain the Content-Type header and pass that along
  • Reading and writing the two streams asynchronously
  • Ensuring the response stream from the camera is properly closed at the right time

If you can figure that out, you’re welcome to submit a better PR in place of mine :slight_smile:

So while I do consider myself a capable developer, I’ve never written in Python before, so I’d definitely appreciate a second look at this PR.

I’ll take a look at your other post and comment in a minute :slight_smile:

Cheers,

Colin

1 Like

Hello @colinodell,

Thank you for your contribution!! I’ll take a look on the PR and test here too. With the new PR, were you able to fix the timeout issues that you were experiencing before?

Thank you again! :thumbsup:

mmello