Amcrest IP Camera Component Enhancements - PTZ control and audio streaming

The only difference I see is that the media_content_id: is my external HA reference.

media_content_id: https://myhassio.duckdns.org:8123/api/hls/longtokenstring/playlist.m3u8

I’ve tried changing the base_url to my duckdns address, but still no dice, even if i have media_content_id: http://…duckdns.org…etc… it still doesn’t work

actually i got it going i had to use https to get it to work.

had some issues with preview image not showing on the home assistant states page.
this was fixed with firmware upgrade and hardware rest.
i also had to enable mjpeg in the extra stream. this option was not available in the android app under settings, i had to use the “amcrest ip config tool” for windows.

Have you all had success with the loopback in in camera.record on an Amcrest?

Hi All, I have recently installed two Amcrest IP camera’s and brought them into HA. I am using the Amcrest integration along with the standard stream component. I get many many errors in my developer tools info. I get Comm Errors and read timeouts from the IP4m-1026EB, sometimes they drop out of the LoveLace sometimes they work. The Binary Sensors often don’t respond. My goal when I set out on this was to use the binary sensors to fire image processing with TensorFlow and then take a snapshot and a loopback recording. I can get most of that to go, but the motion doesn’t get to HA until after the person has left the image or they are in the middle of it. (I expected it to change state as soon as someone enters the image). I have the camera.record service setup for a loopback but it never records the 15 seconds prior to the service being called. It seems like there are so many problems I don’t know where to begin. In this post there are mentions of a custom Amcrest component, have you all had better luck with it?

The enhancements that were made in the custom component, and more, have been folded into the standard component (which is now called an “integration.”)

What version of HA are you using? What does your amcrest configuration look like?

Are the Amcrest cameras being monitored/controlled by any other applications/systems at the same time as HA? If so, what and how?

If you check the support matrix, you’ll see that the IP4m-1026EB is not listed. That’s not to say that it can’t work, it’s just that (probably) nobody has tried the HA integration with it yet and there may be unaddressed issues.

Currently the motion_detected binary sensor is implement (like many HA integrations) as a polled sensor. That means it periodically (every 5 seconds) checks the status of the camera to see if motion has been seen. Consequently, a motion detection event can be delayed by up to 5 seconds before the HA binary sensor reacts. And that’s after the camera itself has decided there’s motion.

HA Version: .98.5

I have these in my main configuration:

ffmpeg:

stream:

Then I have an include for the Amcrest stuff which looks like this:

#Amcrest Cameras

  • host: 192.168.1.66
    username: !secret krusr
    password: !secret krpwd
    name: Redacted
    resolution: high
    #stream_source: rtsp
    binary_sensors:
    • motion_detected
    • online
  • host: 192.168.1.108
    username: !secret frusr
    password: !secret frpwd
    name: Front
    #stream_source: rtsp
    scan_interval: 1
    binary_sensors:
    • motion_detected

My wife is using the Amcrest app to access the one camera on a regular basis, but all I do with that camera is display it in HA LoveLace. The other camera “Front” is the one that is running through TS.

First, let me state right up front, I did not write this code in the first place. I recently fixed a lot of problems in the HA integration code, as well as the pypi.org library that it uses. However, I don’t claim to have fixed all the problems. I did enough to make it work with my three Amcrest cameras in the way I wanted to use them. Hopefully in the process I made it better for other users as well, which I think I’ve done. So…

Do you know how to write Python code? If so, this is an open source project and you’re more than welcome to contribute like I and others have done before me:

Home Assistant Amcrest integration

pypi.org amcrest package

And I’m not being defensive. That’s just the way it is. There are still issues in the code that I’m aware of that have been there since before my involvement, but I don’t have the time to address them. If you, or anyone else, can help, everyone would appreciate it.

Regarding your configuration, I don’t see anything obviously problematic. FWIW, I wouldn’t recommend changing stream_source. In fact, I don’t even think it makes sense for that to be an option anymore (seeing as when you use the stream component, it automatically uses RTSP. This option predates the addition of the stream component.) Also, scan_interval doesn’t work (it has no effect.) That was broken a long time ago. I tried to fix it, but I was shot down. If you want the binary sensors to update more frequently than 5 seconds, you’ll just have to modify the code.

Regarding the use of the Amcrest app, I don’t think that should cause problems/errors (I use that myself from time to time.) But, these cameras (or, at least the models I’ve used) can’t support multiple, simultaneous invocations of certain operations (taking snapshots being the most problematic.) So it’s possible that you might see some errors. But they shouldn’t prevent proper operation in HA (since retries have been implemented.)

I’d suggest enabling debug for homeassistant.components.amcrest, and then checking home-assistant.log after some use. This should give you some insight into how well, or how poorly, communications between HA and the cameras is performing. It could just be the systems are having networking issues.

How is your camera connected? is it over wifi? If so how far away from the router is it? do you have a lot of network traffic? I always had issues with my amcrest cameras when I was first starting out with HA and soon after I updated my network to Ubiquiti from Netgear most of the issues went away around camera stability. Then after all of @pnbruckner changes this component has been a lot better. I hardly get errors but they do still show up.

have you tried to adjust the snapsnot settings to something lower so HA can receive the image faster? some of my cameras have a slight delay (takes 1-2 seconds for HA to get the snapshot sometimes longer) but remember it scans once every 5 seconds, so its possible teh subject was just moving too fast. I use tensorflow to turn on the lights when it detects peopel and its not 100% accurate but good enough in my setup.

In order for this feature to work properly did you make sure to check “preload stream” in the HA UI when you view the camera? without this the loopback won’t be accurate.

Phil, Please don’t misunderstand my comment about the problems. I meant that MY setup has a lot of problems, in regard to the motion sensor, the delay times, the camera and tensor flow. That wasn’t directed at you. In fact I really appreciate all of your hard work.

Absolutely no problem. Completely understood. I just wanted to make sure you fully understood the current situation.

I’d strongly recommend enabling the debug output. Hopefully that will help narrow down where the problems lie. In fact, you could even enable debug for amcrest (which is the library.) So, e.g.:

logger:
  default: info
  logs:
    amcrest: debug
    homeassistant.components.amcrest: debug

If you get some useful output, or would just like me to help you interpret it, feel free to share. In fact, feel free to PM me the details. I’m happy to help if I can (even if I sound grumpy sometimes. :wink:)

I have preload checked. I even tried manually firing the camera.record service with a duration of 0 and lookback of 15s. The video has 2 seconds of recording.

A duration of 0 means you don’t want any length in the recording time, the default is 30 seconds. Lookback probably needs to be adjusted too. If you look at the docs you can see that every camera is different and the settings need to be tweaked until they work as expected.

So if I set the duration to 30s with a 15s lookback, the first 15s are the lookback and the later 15s is after it was initiated? I expected to see a 45s clip.

the docs mention that the length may be different. You need to adjust your settings and keep adjusting until the video meets your requirements

Both duration and lookback options are suggestions, but should be consistent per camera. The actual length of the recording may vary. It is suggested that you tweak these settings to fit your needs.

I guess I’m just confused about what there is to tweak? Do you just keep changing the numbers until it works? Is it specific to the make and model of camera? Is the recording coming from the camera directly or is it based on what is being streamed on HA?

My issue with lookback was that I didn’t have my picture identities in lovelace set to camera_view: live. I didn’t realize that they were streaming actively unless I accessed the UI even with pre-load checked. This might actually help with my errors as HA won’t be trying to log in every time I access the UI with the picture entities. I just assumed they were streaming live.

Has anyone got any tips on how to speed up the lag between the camera and the home assistant webpage or android app? The lag is around 9-12 seconds.

amcrest:
  - host: 192.168.1.90
    name: "Babycam"
    username: xxxxx
    password: xxxxx
    port: 80
    binary_sensors:
      - motion_detected
      - online
    scan_interval: 10
    sensors:
      - ptz_preset

and camera settings are:

ONVIF is enabled.
All extra features are disabled ie. motion detection etc.

I run home assistant in docker on an i7-3770 and the server usually sits around 5% cpu so I don’t think my server is too slow.

are you talking about the lag for streaming? if so that is to be expected. Snapshots are different.