tchellomello / python-amcrest

A Python 2.7/3.x module for Amcrest and Dahua Cameras using the SDK HTTP API.
GNU General Public License v2.0
213 stars 76 forks source link

Is it possible to choose an NVR channel #89

Open gihad opened 6 years ago

gihad commented 6 years ago

I'm using this library through the latest Home Assistant, I successfully added my Amcrest NVR with this:

# Amcrest NVR
amcrest:
  - host: NVR_IP
    username: <login>
    password: <password>
    sensors:
      - motion_detector
      - sdcard
      - ptz_preset

My Overview page in HA started showing images from the camera set to the first channel in the NVR. Is it currently possible to specify the channel so that I can get the feed from other cameras in the NVR? Are there other implications of doing this?

In general I'm trying to avoid connecting directly to the Camera's IP, I'm thinking it's more efficient to connect to the NVR.

dougsland commented 6 years ago

@gihad most of our API calls have channels params. Not sure how we will integrate with HA. Marcelo, probably is aware of it. @tchellomello

tchellomello commented 6 years ago

Not sure about that too @gihad and @dougsland.

@gihad do you know if the NVR has a bindable API?

Klathmon commented 6 years ago

As a workaround, you can access each camera directly on an NVR by going to the "remote" tab in the NVR settings, then clicking on the "browser" button for that camera.

It will open in a new tab a full UI for that specific camera, routed THROUGH the NVR on a custom port. So you can then put that port in home assistant as a unique camera, and it will be treated as if it were a standalone camera.

The username/password will be the default admin/admin

thefarelkid commented 6 years ago

Hi @Klathmon. I too have an Amcrest NVR. I was able to log in directly to the port 10080 through the NVR, but only if I'm logged into the NVR. Otherwise, the page can't be reached. I think that's the reason why when I load my config in Home Assistant, I get the error below. Any help would be appreciated.

Unable to connect to Amcrest camera: HTTPConnectionPool(host='192.168.29.209', port=10080): Max retries exceeded with url: /cgi-bin/magicBox.cgi?action=getMachineName (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x73e36f10>: Failed to establish a new connection: [Errno 111] Connection refused',))

My configuration.yaml

camera:
  - platform: amcrest
amcrest:
  - host: 192.168.29.209
    port: 10080
    username: admin
    password: admin #I also tried my normal password and it didn't work either.
    name: NVR
Klathmon commented 6 years ago

@thefarelkid Well another workaround is to not run the cameras "through" your NVR, but to instead run them through your normal router, but the "add" them to the NVR manually through it's UI.

This is what I ended up doing, so each of my cameras has an IP on my "normal" network, and then the NVR logs into them through the normal network and saves all their recordings, and I have full access to all of them from my "normal" network.

The only downside is that if you are using PoE, then you need to power them with another PoE adapter.

mohesles commented 6 years ago

Wouldn't it be just a matter of exposing the channel as a config parameter in home-assistant? for example... I can see the different streams by using the urls as in: http://user:pass@NVRs_IP/cgi-bin/snapshot.cgi?channel=0&subtype=1 http://user:pass@NVRs_IP/cgi-bin/snapshot.cgi?channel=1&subtype=1 http://user:pass@NVRs_IP/cgi-bin/snapshot.cgi?channel=2&subtype=1 http://user:pass@NVRs_IP/cgi-bin/snapshot.cgi?channel=3&subtype=1

setting them as individual IP cameras is kinda weird and sometimes some work and others dont, plus I have no advanced controls

thefarelkid commented 6 years ago

@Klathmon The 2 camera's I'm not able to see are both POE and I bought the NVR specifically to be the power for them. I'm not going to be able to rout them to the network directly.

@mohesles can you be more specific about what you mean by "exposing the channel as a config parameter? Thanks.

mohesles commented 6 years ago

@mohesles can you be more specific about what you mean by "exposing the channel as a config parameter?

In the rest api for snapshots, you can use the channel attribute to see different feeds in an NVR. http://user:pass@NVRs_IP/cgi-bin/snapshot.cgi?channel=0&subtype=1 would get a snapshot of the 1st camera in the NVR while http://user:pass@NVRs_IP/cgi-bin/snapshot.cgi?channel=1&subtype=1 would show the second camera, and so on.

So I was wondering if there might be a way to let this attribute to be specified. Or something like that?

amcrest:

BenNeumeister commented 6 years ago

Not sure it's that simple. Btw, I'm in the same boat.

From snahshot.py

channel:
                Values according with Amcrest API:
                0 - regular snapshot
                1 - motion detection snapshot
                2 - alarm snapshot

Edit, nope, it works.

http://user:pass@NVRs_IP/cgi-bin/snapshot.cgi?channel=0 http://user:pass@NVRs_IP/cgi-bin/snapshot.cgi?channel=1 http://user:pass@NVRs_IP/cgi-bin/snapshot.cgi?channel=2 http://user:pass@NVRs_IP/cgi-bin/snapshot.cgi?channel=3

@tchellomello, easy enough to add??

Also possible to add a delay in polling the NVR. Getting timeouts coming in like crazy. Box only seem to respond after 10s wait or so when polling for snapshots.

2018-07-17 22:18:11 WARNING (SyncWorker_19) [urllib3.connectionpool] Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPConnectionPool(host='192.168.1.222', port=80): Read timed out. (read timeout=3.0)",)': /cgi-bin/snapshot.cgi?channel=0
2018-07-17 22:18:21 WARNING (SyncWorker_3) [urllib3.connectionpool] Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPConnectionPool(host='192.168.1.222', port=80): Read timed out. (read timeout=3.0)",)': /cgi-bin/snapshot.cgi?channel=0
2018-07-17 22:18:24 WARNING (SyncWorker_3) [urllib3.connectionpool] Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPConnectionPool(host='192.168.1.222', port=80): Read timed out. (read timeout=3.0)",)': /cgi-bin/snapshot.cgi?channel=0
2018-07-17 22:19:21 WARNING (SyncWorker_6) [urllib3.connectionpool] Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPConnectionPool(host='192.168.1.222', port=80): Read timed out. (read timeout=3.0)",)': /cgi-bin/snapshot.cgi?channel=0
2018-07-17 22:19:31 WARNING (SyncWorker_4) [urllib3.connectionpool] Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPConnectionPool(host='192.168.1.222', port=80): Read timed out. (read timeout=3.0)",)': /cgi-bin/snapshot.cgi?channel=0
2018-07-17 22:19:34 WARNING (SyncWorker_4) [urllib3.connectionpool] Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPConnectionPool(host='192.168.1.222', port=80): Read timed out. (read timeout=3.0)",)': /cgi-bin/snapshot.cgi?channel=0
thefarelkid commented 5 years ago

I'm still hoping to get this working. Has anyone played around with it? We definitely can get snapshots of each channel, but I don't know if that translates to full functionality of the cameras can be utilized by home assistant. ie: motion sensor triggering an automation.

theclevercrib commented 5 years ago

I noticed this hasn't been updated recently, but I also would like to use various channels of the NVR ... and in addition, I would like to be able to activate/deactivate motion recording per channel so I can use the switch in conjunction with automations in Home Assistant.

I've tried to control motion detection recording from the cameras individually, but because I am using the NVR and not the SD CARD on the camera, it doesn't appear to work in making the NVR start recording.

mohesles commented 5 years ago

Any updates anyone?

thefarelkid commented 5 years ago

This did work for me pretty well until I realized that the Pi I was running my home assistant on was idling around 80% load. Note that this isn't the Amcrest component, so nothing specific to that component works, but I was able to get each camera connected to the NVR to come through by making each channel specific to that camera.

camera:
  - platform: ffmpeg
    name: Camera 1
    input: -rtsp_transport tcp -i rtsp://admin:[passowd]@[nvrIPaddress]:554/cam/realmonitor?channel=1&subtype=1
  - platform: ffmpeg
    name: Camera 2
    input: -rtsp_transport tcp -i rtsp://admin:[passowd]@[nvrIPaddress]:554/cam/realmonitor?channel=2&subtype=1
  - platform: ffmpeg
    name: Camera 3
    input: -rtsp_transport tcp -i rtsp://admin:[passowd]@[nvrIPaddress]:554/cam/realmonitor?channel=3&subtype=1`
bryeartem commented 5 years ago

Try lowering the frame rate for your extra streams in your Amcrest config (you can change right in the mobile app) lowering the frame rate even slightly greatly reduced my usage, I have 4 ffmpeg cameras, and use ffmpeg motion and sit around 15% on a very old NUC. The only camera I keep at a high frame rate is my front porch which is my main entrance. I am also still trying to get multiple cameras to work through the NVR... would love if I could get the motion sensors. Anyone get anywhere or have an ideas where we can start?

GaryOkie commented 5 years ago

+1 to the OP for selecting the NVR channel as an option in Home Assistant.

I will also submit a feature request to the Home Assistant Amcrest github asking for this.

blademckain commented 4 years ago

+1

DeathCamel58 commented 1 month ago

Just thought that I'd chime in here with an additional note about the channel.

Per AMCREST_CGI_SDK_API.pdf

Per HTTP_API_V3.26.pdf

Which API spec a device follows can be queried at http://user:pass@nvrs_ip/cgi-bin/IntervideoManager.cgi?action=getVersion&Name=CGI, and it looks like version 2.0 or greater follows HTTP_API_V3.26, with AMCREST_CGI_SDK_API only applying to a version below 2.0.