Amcrest IP Camera Component Enhancements - PTZ control and audio streaming

You just put yours straight into the scripts.yaml or services.yaml?

Yes, I manually edit my YAML files.

Sorry to keep bugging you.

Which YAML file do I edit? I’m a noob sorry. This works

image

1 Like

Yes, I would expect the state for the sensor to be unknown, and the values for the Total and Used attributes to be exactly what you’re seeing. I just don’t understand why you’re getting so many warnings and errors. How many cameras do you have configured, and have you changed the scan_interval for the sensors? Still, nearly 600 in 15 minutes is ridiculous.

If you haven’t already, you should go to the Documentation page and read the sections titled Configuration and Advanced Configuration.

4 amcrest cameras configured. just 1 with - sdcard and motion detection added

scan_interval not set.

amcrest:
  - host: 192.168.2.21
    name: "North Drive Camera"
    username: !secret cam_id
    password: !secret cam_pw
    resolution: high
    stream_source: rtsp
    port: 80
    sensors:
      - motion_detector
      - sdcard
    switches:
      - motion_detection
  - host: 192.168.2.22
    name: "Front Yard Camera"
    username: !secret cam_id
    password: !secret cam_pw
    resolution: high
    stream_source: rtsp
    port: 80

… +2 more as above

to clarify - version 1.2b is better than before since the SD entity is created properly and no python index errors occur.

This looping thing is really weird. Just tried again, adding -sdcard to 2 cameras with no card installed, same thing occurring for both.

I hope I didn’t set up the custom component improperly. I copied ALL the code from your repo, including sensor.py and switch.py which are just 2 lines each, importing some other code.

Here’s a more detailed output from the log, showing just a bit less than a minute’s worth…

2019-03-26 12:07:28 WARNING (MainThread) [homeassistant.loader] You are using a custom component for custom_updater which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
2019-03-26 12:07:28 WARNING (MainThread) [homeassistant.loader] You are using a custom component for amcrest which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
2019-03-26 12:07:31 WARNING (MainThread) [homeassistant.loader] You are using a custom component for life360.device_tracker which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
2019-03-26 12:07:32 WARNING (MainThread) [homeassistant.loader] You are using a custom component for composite.device_tracker which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
2019-03-26 12:07:35 WARNING (MainThread) [homeassistant.loader] You are using a custom component for amcrest.switch which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
2019-03-26 12:07:35 WARNING (MainThread) [homeassistant.loader] You are using a custom component for amcrest.sensor which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
2019-03-26 12:07:36 WARNING (SyncWorker_16) [amcrest.http] Trying again due to error 400 Client Error: Bad Request for url: http://192.168.2.22:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:36 WARNING (SyncWorker_9) [amcrest.http] Trying again due to error 400 Client Error: Bad Request for url: http://192.168.2.21:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:36 ERROR (SyncWorker_16) [amcrest.http] Query failed due to error 400 Client Error: Bad Request for url: http://192.168.2.22:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:36 WARNING (SyncWorker_16) [amcrest.http] Trying again due to error 400 Client Error: Bad Request for url: http://192.168.2.22:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:36 ERROR (SyncWorker_9) [amcrest.http] Query failed due to error 400 Client Error: Bad Request for url: http://192.168.2.21:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:36 WARNING (SyncWorker_9) [amcrest.http] Trying again due to error 400 Client Error: Bad Request for url: http://192.168.2.21:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:36 ERROR (SyncWorker_16) [amcrest.http] Query failed due to error 400 Client Error: Bad Request for url: http://192.168.2.22:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:36 WARNING (MainThread) [homeassistant.loader] You are using a custom component for amcrest.camera which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
2019-03-26 12:07:36 ERROR (SyncWorker_9) [amcrest.http] Query failed due to error 400 Client Error: Bad Request for url: http://192.168.2.21:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:37 WARNING (SyncWorker_16) [amcrest.http] Trying again due to error 400 Client Error: Bad Request for url: http://192.168.2.22:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:37 ERROR (SyncWorker_16) [amcrest.http] Query failed due to error 400 Client Error: Bad Request for url: http://192.168.2.22:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:37 WARNING (SyncWorker_9) [amcrest.http] Trying again due to error 400 Client Error: Bad Request for url: http://192.168.2.21:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:37 ERROR (SyncWorker_9) [amcrest.http] Query failed due to error 400 Client Error: Bad Request for url: http://192.168.2.21:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:37 WARNING (SyncWorker_9) [amcrest.http] Trying again due to error 400 Client Error: Bad Request for url: http://192.168.2.21:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:37 ERROR (SyncWorker_9) [amcrest.http] Query failed due to error 400 Client Error: Bad Request for url: http://192.168.2.21:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:37 WARNING (SyncWorker_16) [amcrest.http] Trying again due to error 400 Client Error: Bad Request for url: http://192.168.2.22:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:37 ERROR (SyncWorker_16) [amcrest.http] Query failed due to error 400 Client Error: Bad Request for url: http://192.168.2.22:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:48 WARNING (SyncWorker_16) [amcrest.http] Trying again due to error 400 Client Error: Bad Request for url: http://192.168.2.22:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:48 ERROR (SyncWorker_16) [amcrest.http] Query failed due to error 400 Client Error: Bad Request for url: http://192.168.2.22:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:48 WARNING (SyncWorker_15) [amcrest.http] Trying again due to error 400 Client Error: Bad Request for url: http://192.168.2.21:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:48 WARNING (SyncWorker_16) [amcrest.http] Trying again due to error 400 Client Error: Bad Request for url: http://192.168.2.22:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:48 ERROR (SyncWorker_15) [amcrest.http] Query failed due to error 400 Client Error: Bad Request for url: http://192.168.2.21:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:48 ERROR (SyncWorker_16) [amcrest.http] Query failed due to error 400 Client Error: Bad Request for url: http://192.168.2.22:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:48 WARNING (SyncWorker_16) [amcrest.http] Trying again due to error 400 Client Error: Bad Request for url: http://192.168.2.22:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:48 WARNING (SyncWorker_15) [amcrest.http] Trying again due to error 400 Client Error: Bad Request for url: http://192.168.2.21:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:48 ERROR (SyncWorker_16) [amcrest.http] Query failed due to error 400 Client Error: Bad Request for url: http://192.168.2.22:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:48 ERROR (SyncWorker_15) [amcrest.http] Query failed due to error 400 Client Error: Bad Request for url: http://192.168.2.21:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:48 WARNING (SyncWorker_16) [amcrest.http] Trying again due to error 400 Client Error: Bad Request for url: http://192.168.2.22:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:48 WARNING (SyncWorker_15) [amcrest.http] Trying again due to error 400 Client Error: Bad Request for url: http://192.168.2.21:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:48 ERROR (SyncWorker_16) [amcrest.http] Query failed due to error 400 Client Error: Bad Request for url: http://192.168.2.22:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:48 ERROR (SyncWorker_15) [amcrest.http] Query failed due to error 400 Client Error: Bad Request for url: http://192.168.2.21:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:49 WARNING (SyncWorker_15) [amcrest.http] Trying again due to error 400 Client Error: Bad Request for url: http://192.168.2.21:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:49 ERROR (SyncWorker_15) [amcrest.http] Query failed due to error 400 Client Error: Bad Request for url: http://192.168.2.21:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:59 WARNING (SyncWorker_16) [amcrest.http] Trying again due to error 400 Client Error: Bad Request for url: http://192.168.2.22:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:59 ERROR (SyncWorker_16) [amcrest.http] Query failed due to error 400 Client Error: Bad Request for url: http://192.168.2.22:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:59 WARNING (SyncWorker_19) [amcrest.http] Trying again due to error 400 Client Error: Bad Request for url: http://192.168.2.21:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:59 ERROR (SyncWorker_19) [amcrest.http] Query failed due to error 400 Client Error: Bad Request for url: http://192.168.2.21:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:59 WARNING (SyncWorker_16) [amcrest.http] Trying again due to error 400 Client Error: Bad Request for url: http://192.168.2.22:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:59 WARNING (SyncWorker_19) [amcrest.http] Trying again due to error 400 Client Error: Bad Request for url: http://192.168.2.21:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:59 ERROR (SyncWorker_16) [amcrest.http] Query failed due to error 400 Client Error: Bad Request for url: http://192.168.2.22:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:59 ERROR (SyncWorker_19) [amcrest.http] Query failed due to error 400 Client Error: Bad Request for url: http://192.168.2.21:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:59 WARNING (SyncWorker_16) [amcrest.http] Trying again due to error 400 Client Error: Bad Request for url: http://192.168.2.22:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:59 WARNING (SyncWorker_19) [amcrest.http] Trying again due to error 400 Client Error: Bad Request for url: http://192.168.2.21:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:59 ERROR (SyncWorker_19) [amcrest.http] Query failed due to error 400 Client Error: Bad Request for url: http://192.168.2.21:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:59 ERROR (SyncWorker_16) [amcrest.http] Query failed due to error 400 Client Error: Bad Request for url: http://192.168.2.22:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:59 WARNING (SyncWorker_19) [amcrest.http] Trying again due to error 400 Client Error: Bad Request for url: http://192.168.2.21:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:59 WARNING (SyncWorker_16) [amcrest.http] Trying again due to error 400 Client Error: Bad Request for url: http://192.168.2.22:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:07:59 ERROR (SyncWorker_16) [amcrest.http] Query failed due to error 400 Client Error: Bad Request for url: http://192.168.2.22:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo
2019-03-26 12:08:00 ERROR (SyncWorker_19) [amcrest.http] Query failed due to error 400 Client Error: Bad Request for url: http://192.168.2.21:80/cgi-bin/storageDevice.cgi?action=getDeviceAllInfo

Ok, well, now I think I understand why so many warnings and errors. So every time the sensor updates it calls three different camera methods, one of which calls the other two itself. So basically four camera commands per update. And if it fails, then each command will cause two warnings and two errors. Now the update happens every ten seconds, so six times a minute. Putting that all together, in fifteen minutes there would be 720 warnings and 720 errors!

I think the moral of the story is, if it hurts, don’t do it! :wink: (I.e., don’t use the sdcard sensor for a camera it doesn’t make sense for.)

But seriously, yes, I agree, it should be smarter about this. But then again, as I’ve said, it needs to be smarter about some other stuff, too. I’ll add this to the list.

1 Like

Hey - I’m not intentionally trying to inflict pain! Just testing the edge cases for you. I’m headed back to the lake house now and will continue some more testing there. One of those cameras has an sdcard installed with nothing on it yet. This caused an index error in the old code, but I’m pretty sure it’s fixed with your update. I’ll confirm later today.

Oh - sure glad you understand the repeated errors now and have added it to the “be smarter” list. :slight_smile:

No problem, and I definitely appreciate the feedback. As I’ve said, it’s kind of hard for me to test all the scenarios with only a couple of cameras. Obviously there is a lot of history in this code that I’m unfamiliar with. Just hoping I’m helping and not causing too many problems in the process. :wink:

I temporarily changed my recent PR to a “WIP”, but I think I can remove that now. I.e., I don’t think anything I did caused the problem; it just changed how it shows up. (I.e., before the change there would still have been many, many unhandled exceptions, as opposed to warnings/errors, albeit more, because it’s now not aborting the entire sensor update cycle on the first exception.)

Honestly, I would rather see the sdcard sensor code crap out with a single python error than 69,120 repeated errors each day in the log. But that’s just me. :wink:

EDIT - just kidding though… removing the -sdcard immediately after discovering this, is the proper solution for now.

I’m with ya! But error handling hasn’t traditionally been HA’s strong point. At least not in the code I’ve dealt with. Why do you think they recently changed the way errors show up on the Info page (i.e., grouping them)? From what I’ve seen HA seems to be pretty much a “fire and forget” type of system. You can see it in this aspect, the fact that service calls have no infrastructure for returning completion status, etc., etc. But, it hasn’t reached release 1.0 yet, so…

(BTW, if it’s not obvious, I’m mostly just kidding, too!)

1 Like

Yea I think its up to each component based on how they fire errors too. For example if a sensor continues to fail, setting the sensor to unavailable and only printing an error when the device was available will help prevent the errors from flooding (saying that outloud makes me realize I need to update Neato :slight_smile: ). But every integration is setup differently, just need to think about the different ways things work together. I have several components that just send out errors that to me are meaningless because it still functions. Just need to try and find a happy middle ground.

@pnbruckner thank you for all the error logging enhancements recently as well, the recent changes in 0.90 now help me better understand which camera is having an issue :slight_smile:

1 Like

I tried this and still no go.

image

don’t forget to include the entity ID in your service call or script

I got it working. Thank you

@pnbruckner If I’m not mistaken, the goto preset function broke with a recent update of home assistant. When I call the service amcrest_goto_preset with data {“preset”: 1, “entity_id”: “camera.mycamera”}
I get an error message saying: failed to call service camera/amcrest_goto_preset. Cannot be called from within the event loop.

Hmm, sure enough. Looks like a change in 0.90.0 caused this. I’ll figure out how to fix it…

If you’d like to try the fix I came up with, grab an updated copy of <config>/custom_components/amcrest/camera.py from here. I’ve tried it with a few different versions (0.84.6 that I’m still using, 0.90.2, as well as a recent dev checkout) and it seems to work. Assuming I don’t hear any negative feedback I’ll release an update soon.

Anyone have any luck getting multiple cameras to work through an NVR and more specifically the motion sensors? I use FFMPEG for the cams, but would love to make use of all the motion sensors.

EDIT: I was wondering if I could make Scrape Sensors to pull the data from the motion sensors but it seems like it will only look for HTML tags. This is the response from the API

channels[0]=1
channels[1]=0
channels[2]=1
channels[3]=1

Any suggestions or ideas would be appreciated