Amcrest IP Camera Component Enhancements - PTZ control and audio streaming

Hi all,
I added some enhancements to the camera component for controlling the cameras PTZ functions from HA. Now working on playing audio files on the cameras speaker but I’m having some issues with the ‘play_wav’ function in python-amcrest.

See the GitHub issue I raised for it.
If you have any experience using this library let me know. Will PR to HA once it’s complete and tested :slight_smile:

I added quite a few enhancements to the amcrest component a while ago, but I haven’t gotten around to pushing any of it back via PRs. At the time I did them I was still pretty new to HA and git. And since then I’ve had other priorities. But, if you’re interested, take a look at https://github.com/pnbruckner/homeassistant-config#amcrest-camera.

One of the changes I made that might relate to your issues was adding a lock to serialize camera API usage. There are some cases where having two commands pending simultaneously causes the camera to respond incorrectly. One such case had to do with grabbing snapshots. When you click on the camera image in HA’s frontend it opens a new window in which to display the images and it updates more frequently. But it also keeps updating the image in the “background” at the same time. This caused many, many comm errors. By adding the lock I no longer get any errors. You may have to do something similar with audio.

2 Likes

Hi, thanks for sharing that.
I replaced my amcrest.py with yours and got the goto_preset service and play_wav service working, stuck at the same problem though.

I can try taking a look at it next week. In the meantime, have you seen:

It’s not really an “SDK”, per se. Really it just has a link to the HTTP API pdf.

Yeah i was going to use this originally to make HTTP requests to amcrest camera directly from HA. This was before I found out they supply python-amcrest.

Created PR for @pnbruckner’s enhancements

1 Like

Nice to see these changes coming in! Glad to see theres a binary sensor for the motion detection :slight_smile: will need to check that out too.

Sorry to hijack the thread and for general noob-ness…but how do we load the changes? I’d like to be able to control PTZ from within home assistant so I can disable P2P on the cameras themselves

1 Like

I am pretty much ready to give up on this PR. taking too much time and im struggling with the workflow. Git is being annoying with merge conflicts.
its a shame because phils code has really nice performance improvements.
I cleaned up the code according to linting rules. It’s in https://github.com/danobot/home-assistant

My enhancements here (PTZ controls, audio playback target, reboot):

1 Like

Thanks for giving it a go. I can tell you spent quite a bit of time on this. And, yes, I find git hard to grasp. I’ve used many other version control systems in my life, and git is so different. It’s starting to sink in, but I still find I have to use git help and google way too often to figure out how to do things.

Anyway, I may be able to find some time to try myself. I’m still on 0.84.6 and it’s about time I deal with all the recent changes so I can have a hope of upgrading some day! I’ll certain leverage the work you’ve done!!

We use gitflow at work, but for some reason I keep getting merge conflicts when rebasing new HA dev work onto my branch. Very annoying.
I triedmerging my stuffdirectly into the current amcrest/camera.py file, however the services do not show up in HA. Tried registering the services sync and asynchronously.
It works perfectly when my file runs as camera/amcrest.py. since recently, they created a new amcrest domain.

Thanks for your work on this gentlemen. I have a question though…the SD card on my Pi died a couple of days ago, but I was able to backup my config folder. After reloading Hass.io on a new SD card and restoring my config folder, for some reason the custom components aren’t being loaded. The log shows says that I’m missing some dependencies. Any ideas what it could be?

Blockquote
Log Details (ERROR)
Sat Feb 23 2019 01:08:24 GMT-0500 (Eastern Standard Time)
Error loading custom_components.amcrest.sensor. Make sure all dependencies are installed
Traceback (most recent call last): File “/usr/local/lib/python3.7/site-packages/homeassistant/loader.py”, line 147, in _load_file module = importlib.import_module(path) File “/usr/local/lib/python3.7/importlib/init.py”, line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File “<frozen importlib._bootstrap>”, line 1006, in _gcd_import File “<frozen importlib._bootstrap>”, line 983, in _find_and_load File “<frozen importlib._bootstrap>”, line 962, in _find_and_load_unlocked ModuleNotFoundError: No module named ‘custom_components.amcrest.sensor’; ‘custom_components.amcrest’ is not a package

Does the custom_componrnts folder exist and contain the expected files?
Are you running the same HA version now as you were before?
Only thing I can think of is restart a few times. If that doesn’t help, remove all custom components and add them in one at a time.

It’s because you updated to a newer version of HA which has changed the folder layout of custom components. This custom component is not compatible with this new layout. It’s on my list of things to do, but not sure when I’ll get to it. I’m pretty much stuck on 0.84.6.

In the meantime, you can try doing this:

cd custom_components
sudo -u homeassistant mkdir amcrest
sudo -u homeassistant mv amcrest.py amcrest/__init__.py
sudo -u homeassistant mv camera/amcrest.py amcrest/camera.py
sudo -u homeassistant mv binary_sensor/amcrest.py amcrest/binary_sensor.py

If you try it let me know how it works for you.

Thank you both, and yes I used version 88.0 when I rebuilt the pi since it was the latest version at the moment.

@pnbruckner, moved the components as you instructed, the error in the log disappeared and it looks like the services work now. However, now my input select entity and rtsp streams of the cameras don’t work but think they might be separate issues.

Glad it’s (basically) working for you!

Yes, I’m sure the input_select is another issue. As far as rtsp goes, I never got that working. But I think that had more to do with me not getting ffmpeg working well on my pi when I first tried to get it working a long time ago (even with the standard component), and gave up. I only use snapshot mode, although I might give streaming a go again before too long.

For those of you trying to figure out how to get the amcrest custom component working with home assistant 0.88, here’s what you need to do:

  1. Create a folder in custom_components called amcrest
  2. Copy the amcrest.py (amcrest component) into the custom_components/amcrest folder and rename it to __init__.py
  3. Copy the amcrest.py (camera component) into custom_components/amcrest and rename it camera.py
  4. If you use the binary_sensor, copy that component into the same amcrest folder and rename it binary_sensor.py

That’s it, it should be working

Isn’t that what I said a few posts up? :slight_smile:

Dang, can’t believe I missed that… :flushed: Thanks for the component btw!

1 Like