rroller / dahua

Dahua Camera and Doorbell Home Assistant Integration
MIT License
383 stars 74 forks source link

NVR support #9

Open kukulich opened 3 years ago

kukulich commented 3 years ago

Is it possible to support NVR? It would be nice to add one device (NVR) and all info about cameras would be detected automatically.

It should also solve a problem when cameras cannot be added because they are connected via NVR and NVR use specific custom IP addresses for them - and the IP addresses are not usable directly.

rroller commented 3 years ago

I think that's doable. But I don't have an nvr and I'd need one to build out the functionality.

kukulich commented 3 years ago

I can help with debugging and testing. Is there a list of API somewhere?

rroller commented 3 years ago

The problem is that I need an actual NVR so I can do edit-test cycles locally to get all the APIs correct. Without that I have no idea if my code would work or even where to start. I have to play around with the APIs to understand them and for that I need an NVR unit.

kukulich commented 3 years ago

I have already tested some API:

/cgi-bin/magicBox.cgi?action=getSystemInfo

deviceType=31
processor=ST7108
serialNumber=4F07335PAZEEA9B
updateSerial=NVR2X-4KS3

/cgi-bin/magicBox.cgi?action=getSoftwareVersion

version=4.001.0000005.0,build:2020-11-17

/cgi-bin/magicBox.cgi?action=getMachineName

name=NVR

/cgi-bin/magicBox.cgi?action=getVendor

vendor=Dahua

But I don't know what I should test next... If you can guide me, I may be able to send a PR...

kukulich commented 3 years ago

/cgi-bin/magicBox.cgi?action=getDeviceType

type=DHI-NVR2108-8P-4KS2

/cgi-bin/magicBox.cgi?action=getDeviceClass

class=NVR
kukulich commented 3 years ago

This looks like a way to detect number of channels/cameras:

/cgi-bin/configManager.cgi?action=getConfig&name=VideoColor

table.VideoColor[0][0].Brightness=50
table.VideoColor[0][0].ChromaSuppress=50
table.VideoColor[0][0].Contrast=50
table.VideoColor[0][0].Gamma=50
table.VideoColor[0][0].Hue=50
table.VideoColor[0][0].Saturation=50
table.VideoColor[0][0].Style=Standard
table.VideoColor[0][0].TimeSection=1 00:00:00-24:00:00
table.VideoColor[0][1].Brightness=50
table.VideoColor[0][1].ChromaSuppress=50
table.VideoColor[0][1].Contrast=50
table.VideoColor[0][1].Gamma=50
table.VideoColor[0][1].Hue=50
table.VideoColor[0][1].Saturation=50
table.VideoColor[0][1].Style=Standard
table.VideoColor[0][1].TimeSection=0 00:00:00-24:00:00
table.VideoColor[0][2].Brightness=50
table.VideoColor[0][2].ChromaSuppress=50
table.VideoColor[0][2].Contrast=50
table.VideoColor[0][2].Gamma=50
table.VideoColor[0][2].Hue=50
table.VideoColor[0][2].Saturation=50
table.VideoColor[0][2].Style=Standard
table.VideoColor[0][2].TimeSection=0 00:00:00-24:00:00
table.VideoColor[1][0].Brightness=50
table.VideoColor[1][0].ChromaSuppress=50
table.VideoColor[1][0].Contrast=50
table.VideoColor[1][0].Gamma=50
table.VideoColor[1][0].Hue=50
table.VideoColor[1][0].Saturation=50
table.VideoColor[1][0].Style=Standard
table.VideoColor[1][0].TimeSection=1 00:00:00-24:00:00
table.VideoColor[1][1].Brightness=50
table.VideoColor[1][1].ChromaSuppress=50
table.VideoColor[1][1].Contrast=50
table.VideoColor[1][1].Gamma=50
table.VideoColor[1][1].Hue=50
table.VideoColor[1][1].Saturation=50
table.VideoColor[1][1].Style=Standard
table.VideoColor[1][1].TimeSection=0 00:00:00-24:00:00
table.VideoColor[1][2].Brightness=50
table.VideoColor[1][2].ChromaSuppress=50
table.VideoColor[1][2].Contrast=50
table.VideoColor[1][2].Gamma=50
table.VideoColor[1][2].Hue=50
table.VideoColor[1][2].Saturation=50
table.VideoColor[1][2].Style=Standard
table.VideoColor[1][2].TimeSection=0 00:00:00-24:00:00
table.VideoColor[2][0].Brightness=50
table.VideoColor[2][0].ChromaSuppress=50
table.VideoColor[2][0].Contrast=50
table.VideoColor[2][0].Gamma=50
table.VideoColor[2][0].Hue=50
table.VideoColor[2][0].Saturation=50
table.VideoColor[2][0].Style=Standard
table.VideoColor[2][0].TimeSection=1 00:00:00-24:00:00
table.VideoColor[2][1].Brightness=50
table.VideoColor[2][1].ChromaSuppress=50
table.VideoColor[2][1].Contrast=50
table.VideoColor[2][1].Gamma=50
table.VideoColor[2][1].Hue=50
table.VideoColor[2][1].Saturation=50
table.VideoColor[2][1].Style=Standard
table.VideoColor[2][1].TimeSection=0 00:00:00-24:00:00
table.VideoColor[2][2].Brightness=50
table.VideoColor[2][2].ChromaSuppress=50
table.VideoColor[2][2].Contrast=50
table.VideoColor[2][2].Gamma=50
table.VideoColor[2][2].Hue=50
table.VideoColor[2][2].Saturation=50
table.VideoColor[2][2].Style=Standard
table.VideoColor[2][2].TimeSection=0 00:00:00-24:00:00
table.VideoColor[3][0].Brightness=50
table.VideoColor[3][0].ChromaSuppress=50
table.VideoColor[3][0].Contrast=50
table.VideoColor[3][0].Gamma=50
table.VideoColor[3][0].Hue=50
table.VideoColor[3][0].Saturation=50
table.VideoColor[3][0].Style=Standard
table.VideoColor[3][0].TimeSection=1 00:00:00-24:00:00
table.VideoColor[3][1].Brightness=50
table.VideoColor[3][1].ChromaSuppress=50
table.VideoColor[3][1].Contrast=50
table.VideoColor[3][1].Gamma=50
table.VideoColor[3][1].Hue=50
table.VideoColor[3][1].Saturation=50
table.VideoColor[3][1].Style=Standard
table.VideoColor[3][1].TimeSection=0 00:00:00-24:00:00
table.VideoColor[3][2].Brightness=50
table.VideoColor[3][2].ChromaSuppress=50
table.VideoColor[3][2].Contrast=50
table.VideoColor[3][2].Gamma=50
table.VideoColor[3][2].Hue=50
table.VideoColor[3][2].Saturation=50
table.VideoColor[3][2].Style=Standard
table.VideoColor[3][2].TimeSection=0 00:00:00-24:00:00
table.VideoColor[4][0].Brightness=50
table.VideoColor[4][0].ChromaSuppress=50
table.VideoColor[4][0].Contrast=50
table.VideoColor[4][0].Gamma=50
table.VideoColor[4][0].Hue=50
table.VideoColor[4][0].Saturation=50
table.VideoColor[4][0].Style=Standard
table.VideoColor[4][0].TimeSection=1 00:00:00-24:00:00
table.VideoColor[4][1].Brightness=50
table.VideoColor[4][1].ChromaSuppress=50
table.VideoColor[4][1].Contrast=50
table.VideoColor[4][1].Gamma=50
table.VideoColor[4][1].Hue=50
table.VideoColor[4][1].Saturation=50
table.VideoColor[4][1].Style=Standard
table.VideoColor[4][1].TimeSection=0 00:00:00-24:00:00
table.VideoColor[4][2].Brightness=50
table.VideoColor[4][2].ChromaSuppress=50
table.VideoColor[4][2].Contrast=50
table.VideoColor[4][2].Gamma=50
table.VideoColor[4][2].Hue=50
table.VideoColor[4][2].Saturation=50
table.VideoColor[4][2].Style=Standard
table.VideoColor[4][2].TimeSection=0 00:00:00-24:00:00
table.VideoColor[5][0].Brightness=50
table.VideoColor[5][0].ChromaSuppress=50
table.VideoColor[5][0].Contrast=50
table.VideoColor[5][0].Gamma=50
table.VideoColor[5][0].Hue=50
table.VideoColor[5][0].Saturation=50
table.VideoColor[5][0].Style=Standard
table.VideoColor[5][0].TimeSection=1 00:00:00-24:00:00
table.VideoColor[5][1].Brightness=50
table.VideoColor[5][1].ChromaSuppress=50
table.VideoColor[5][1].Contrast=50
table.VideoColor[5][1].Gamma=50
table.VideoColor[5][1].Hue=50
table.VideoColor[5][1].Saturation=50
table.VideoColor[5][1].Style=Standard
table.VideoColor[5][1].TimeSection=0 00:00:00-24:00:00
table.VideoColor[5][2].Brightness=50
table.VideoColor[5][2].ChromaSuppress=50
table.VideoColor[5][2].Contrast=50
table.VideoColor[5][2].Gamma=50
table.VideoColor[5][2].Hue=50
table.VideoColor[5][2].Saturation=50
table.VideoColor[5][2].Style=Standard
table.VideoColor[5][2].TimeSection=0 00:00:00-24:00:00
table.VideoColor[6][0].Brightness=50
table.VideoColor[6][0].ChromaSuppress=50
table.VideoColor[6][0].Contrast=50
table.VideoColor[6][0].Gamma=50
table.VideoColor[6][0].Hue=50
table.VideoColor[6][0].Saturation=50
table.VideoColor[6][0].Style=Standard
table.VideoColor[6][0].TimeSection=1 00:00:00-24:00:00
table.VideoColor[6][1].Brightness=50
table.VideoColor[6][1].ChromaSuppress=50
table.VideoColor[6][1].Contrast=50
table.VideoColor[6][1].Gamma=50
table.VideoColor[6][1].Hue=50
table.VideoColor[6][1].Saturation=50
table.VideoColor[6][1].Style=Standard
table.VideoColor[6][1].TimeSection=0 00:00:00-24:00:00
table.VideoColor[6][2].Brightness=50
table.VideoColor[6][2].ChromaSuppress=50
table.VideoColor[6][2].Contrast=50
table.VideoColor[6][2].Gamma=50
table.VideoColor[6][2].Hue=50
table.VideoColor[6][2].Saturation=50
table.VideoColor[6][2].Style=Standard
table.VideoColor[6][2].TimeSection=0 00:00:00-24:00:00
table.VideoColor[7][0].Brightness=50
table.VideoColor[7][0].Contrast=50
table.VideoColor[7][0].Hue=50
table.VideoColor[7][0].Saturation=50
table.VideoColor[7][0].TimeSection=1 00:00:00-24:00:00
table.VideoColor[7][1].Brightness=50
table.VideoColor[7][1].Contrast=50
table.VideoColor[7][1].Hue=50
table.VideoColor[7][1].Saturation=50
table.VideoColor[7][1].TimeSection=0 00:00:00-24:00:00
alanpilz commented 3 years ago

I’m also interested in the NVR integration. I have a Dahua 4108 NVR, installed this great integration and I see “main” camera added and I have a preview of one of the cameras. But only one camera is visible. I simply added the IP of the dahua NVR and it detected 1 Device with 5 entities.

kukulich commented 3 years ago

I'll try to prepare PR.

frapersan commented 3 years ago

I have a nvr (dahua hcvr5108hs-s3) when I configure the integration it works, but on the integrations page it appears as:

Captura

no warning appears in the logs.

I can help, I am fully available

chali272 commented 3 years ago

im also using dahua nvr and like to see it supported, when adding the nvr today im getting one camera.

kukulich commented 3 years ago

I did not find any API to detect number of cameras... However it may be possible to detect if the device is NVR (via getDeviceClass) so the best option would be to add second config_flow step - user can specify the number of cameras/channels by itself.

Mikefila commented 3 years ago

Okay So I was going through the code and in camera.py I saw this

For now we'll only support 1 channel. I don't have any cams where I can test a second channel. I'm not really sure what channel 2 means anyways, it doesn't seem to be the substream. CHANNEL = 1

Channel refers to dvr/xvr/nvr channels. subtype denotes main(0)/sub stream(1) Rtsp streams are in the form of rtsp://<username>:<password>@<ip>:<port>/cam/realmonitor?channel=1&subtype=0

Channels are offset by one. Channel 0 = Camera 1; 1=2; 2=3 etc.

I use this right now and I am able to get all events from an xvr running 11 analog cameras.

https://github.com/algirdasc/appdaemon-apps/blob/master/dahua_mqtt.py

Mikefila commented 3 years ago

Probably the most important part, the only thing I had to modify was a setting. Instead of defining a camera in the form of camera/1 I removed the number and just used camera

chali272 commented 3 years ago

Okay So I was going through the code and in camera.py I saw this

For now we'll only support 1 channel. I don't have any cams where I can test a second channel. I'm not really sure what channel 2 means anyways, it doesn't seem to be the substream. CHANNEL = 1

Channel refers to dvr/xvr/nvr channels. subtype denotes main(0)/sub stream(1) Rtsp streams are in the form of rtsp://<username>:<password>@<ip>:<port>/cam/realmonitor?channel=1&subtype=0

Channels are offset by one. Channel 0 = Camera 1; 1=2; 2=3 etc.

I use this right now and I am able to get all events from an xvr running 11 analog cameras.

https://github.com/algirdasc/appdaemon-apps/blob/master/dahua_mqtt.py

noob questone, what file is this replacing in the Dahua folder/whats should your file be named as? (i cant see any file named dahua_mqtt.py)

Mikefila commented 3 years ago

I'm sorry if I was unclear, I did not change anything on this integration nor do I have it working.

The link I posted is a different integration all together. It works through appdaemon. I only referenced so the maintainer of this integration has a working example of a script that will log on to a nvr/dvr/xvr. Perhaps it maybe helpful.

Follow this post for details of the other integration, if you have further questions please post them to that thread. I'm subscribed and will answer there as not to derail this thread.

https://community.home-assistant.io/t/dahua-ipc-to-mqtt-app/93327/174?u=mikefila

fokcuk commented 3 years ago

what is this section undr init.py? def init(self, hass: HomeAssistant, events: list, address: str, port: int, rtsp_port: int, username: str, password: str) -> None: """Initialize.""" self.client: DahuaClient = DahuaClient(username, password, address, port, rtsp_port, async_get_clientsession(hass)) self.dahua_event: DahuaEventThread self.platforms = [] self.initialized = False self.model = "" self.machine_name = "" self.connected = None self.channels = {"1": "1"} self.events: list = events

If we use NVR address, it works and events are registered, but only for channel 1. Also there is no way to modify entity name, so even if we modify the channel in the code, it will link it to the same one.

rroller commented 3 years ago

Yeah I have a hard coded channel coded through the code. I can make that an option when configuring the integration to allow you to pick the channel. I think that will work.

fokcuk commented 3 years ago

Yeah I have a hard coded channel coded through the code. I can make that an option when configuring the integration to allow you to pick the channel. I think that will work.

And make am option for entity name pick, otherwise it assigns the same name to the same NVR when adding and no option to change it. Which file picks the channel for events? I saw in one there is 1:1 for a channel, but don't know it its a start:end (like 1:5) or if you want a particular channel you have to select 2:2, 3:3 etc

rroller commented 3 years ago

I'm close to completing a change that allows one to set the name during configuration time. This will be the building blocks needed to support channels.

It's basically the same configuration form now, but after you click submit, it'll open a new form with the name of the camera and lets you edit it.

fokcuk commented 3 years ago

great! thank you. How does it get the motion events? I thought I changed the channel info in the code but I think it reads any motion event and NVR will have different events for different channels/cameras

fokcuk commented 3 years ago

Platform dahua does not generate unique IDs. ID 3CPAZ5EF403317U_motion_detection already exists - ignoring switch.nvr_motion_detection Platform dahua does not generate unique IDs. ID 3CPAZ5EF403317U_disarming already exists - ignoring switch.nvr_disarming

Can you please add the sensor unique IDs as well?

haid45 commented 3 years ago

I'm close to completing a change that allows one to set the name during configuration time. This will be the building blocks needed to support channels.

It's basically the same configuration form now, but after you click submit, it'll open a new form with the name of the camera and lets you edit it.

@rroller Ill be eager to test this when you have finished.

rroller commented 3 years ago

Thanks. I'll make this the next thing I work on. I need to un-hard-code all the channels I currently have hard coded

haid45 commented 3 years ago

Amazing, I'm readily available to test this out for you. I currently have an NVR installed with 4 cameras (channels). The integration is able to pick up just the main channel at the moment.

rroller commented 3 years ago

@haid45 when you added your camera, for the IP address, do you use your NVR IP Address? I assume you don't use the IP of the camera? So you'd be adding 4 camera's all with the IP of your NVR?

haid45 commented 3 years ago

@rroller, yes I used the IP address of the NVR as I wasn't able to get the individual ip's of the cameras. Well actually, I was but they seemed to be on a local network within the NVR because the ip's where along the lines of 10.0.0.1. Adding the 4 cameras with IP of the NVR is definitely the end game here.

rroller commented 3 years ago

Awesome, this is totally doable. I'm working on the changes now.

haid45 commented 3 years ago

How exciting! looking forward to trying it out 🥳

rroller commented 3 years ago

I just released 0.9.0 with early support for NVR's. I don't have an NVR so I can't test it... so this will most definitely have bugs :)

If you all could please test it and let me know if you run into any issues and I'll try to fix them ASAP.

https://github.com/rroller/dahua/releases/tag/0.9.0

rroller commented 3 years ago

And now 0.9.1 is released for a small bug fix https://github.com/rroller/dahua/releases/tag/0.9.1

rroller commented 3 years ago

One area that I know needs work is the event stream. I'll try to work on that soon. It's probably only handling events from camera 0

rroller commented 3 years ago

And I just realized another change I need to make for this to work. The unique id used for the entities is the serial number. All cams added will get the nvr serial, so they’ll collide. I’ll need to add in the channel to the unique id.

haid45 commented 3 years ago

@rroller, thank you for that. It's great! I have just tested it on my setup and the first hurdle is that by adding the NVR it does not add all the cameras that are associated with the NVR. I tried adding multiple integrations, one for each channel but received this error in the process Only a single instance of a device is allowed.

rroller commented 3 years ago

@haid45 thsts the issue I mentioned above. I'll try to fix that today.

rroller commented 3 years ago

OK 0.9.2 is out. Try that one. This will hopefully let you add the additional cameras and from there we can debug any issues. Known issues that I know about are events. Once we get the additional cams added I'll ask if one of you can provide me event logs so I can then fix that. Sorry for so many iterations here, hard without having an NVR :D https://github.com/rroller/dahua/releases/tag/0.9.2

@haid45

mrbarbz commented 3 years ago

I updated to version 0.9.2, I still have the same issue in #50 with your latest update.

I also can't connect a single camera, I think its because the NVR has an internal PoE switch and assigns different Ip addresses from the NVR Example NVR IP address 10.0.0.5, Camera on the NVR IP 10.2.2.9

mrbarbz commented 3 years ago

I updated to version 0.9.2, I still have the same issue in #50 with your latest update.

I also can't connect a single camera, I think its because the NVR has an internal PoE switch and assigns different Ip addresses from the NVR Example NVR IP address 10.0.0.5, Camera on the NVR IP 10.2.2.9

It's working now. Thanks heaps When I was trying to sort out the issue I found that there was new Dahua NVR system Firmware. I upgraded to version 4 and like magic no more error. I will play around and see if there are any issues I come across. Thanks again

rroller commented 3 years ago

Great! Ill note the firmware update in the readme. Also please let me know if you can grab some of the even json. You'll need to enable debug logging, there's an example in the readme.

mrbarbz commented 3 years ago

I have debugged logging already enabled but where do I get it from?

mrbarbz commented 3 years ago

After some testing, this is what I have experienced

When I updated the NVR firmware and tested it, I had it on my desk. I tested with 1 camera, which has its own POE injector and is connected to my network router. With only 1 camera connected and I could add the NVR using its Ip address. I put back the NVR in the carboard and connected the rest of the cameras. I removed the integration, restarted HA and re-added it to that it can pick up all the cameras, every time I put in my details and select submit it would clear my inputs giving me the "username/password/Ip address" wrong error. These are the following IPs NVR 10.0.0.100 cam1 10.0.0.101 cam2 10.0.0102 cam3 10.0.0.103 cam4 10.0.0.104

cam4 is the only camera not connected to the NVR's internal PoE switch, it is connected to my network with PoE injector

Every time I try to add cam1, cam2, cam3, and NVR with the relevant IP it would get the username/password/IP address error cam4 is the only camera I could connect to.

All cameras have also been updated to Version 2.8

I don't know if the issue is within your integration or my internal switch settings.

haid45 commented 3 years ago

In my case, I used the ip address of the nvr and just added multiple integrations, one for each channel. So far it works great but I have not utilised any of the sensors or switches, just the cameras.

fokcuk commented 3 years ago

camera integration you can do with a simple rtsp stream. Events per channel are what I need from the integration. At the moment I am still running the older version of the integration that I modified py code to point to a particular camera for video. Channel events were not available then (don't know about now). Any event from NVR (events from any channel) would trigger the entity change for things like cross line etc. I went around it by having a particular alarm that is only specific to the channel I want

fokcuk commented 3 years ago

@rroller - check your code in camera.py (and maybe others). You have channel + 1 in a number of places in the code. It may work if channel is 0 (zero), but for multi channel NVR it breaks things. I only have 5 channels, but it tries to get stream from channel 6

mrbarbz commented 3 years ago

An update to my issue looks like my issue is not related to your integration.

This is what I have found The NVR will have DHCP and will give a different subnet to its cameras .. this is where the problem is ... So the issue is with the inbuilt Poe Switch on the NVR having its own DHCP.

I couldn't find a way to disable it and I don't think there is an option. I am going to purchase a separate PoE switch, connect cameras and NVR to it and test it again.

mrbarbz commented 3 years ago

ok purchased PoE Switch

Integration wouldn't connect to NVR, I kept getting either username/password/IP address incorrect

Integration worked with the cameras via their IP address connected to the same network as HA via PoE switch but video stream only worked when I left the channel at 0 at setup.

I've found that I could only connect to the cameras when not using internal/inbuilt switch

Below is the log when I try to connect to the NVR if that is any help to you.

This error originated from a custom integration.

Logger: custom_components.dahua Source: custom_components/dahua/digest.py:46 Integration: Dahua (documentation, issues) First occurred: 8:32:24 PM (1 occurrences) Last logged: 8:32:24 PM

Could not connect to Dahua device Traceback (most recent call last): File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 969, in _wrap_create_connection return await self._loop.create_connection(*args, **kwargs) # type: ignore # noqa File "/usr/local/lib/python3.8/asyncio/base_events.py", line 1050, in create_connection transport, protocol = await self._create_connection_transport( File "/usr/local/lib/python3.8/asyncio/base_events.py", line 1080, in _create_connection_transport await waiter File "/usr/local/lib/python3.8/asyncio/sslproto.py", line 529, in data_received ssldata, appdata = self._sslpipe.feed_ssldata(data) File "/usr/local/lib/python3.8/asyncio/sslproto.py", line 189, in feed_ssldata self._sslobj.do_handshake() File "/usr/local/lib/python3.8/ssl.py", line 944, in do_handshake self._sslobj.do_handshake() ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1125)

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/config/custom_components/dahua/config_flow.py", line 201, in _test_credentials data = await client2.get_machine_name() File "/config/custom_components/dahua/client.py", line 95, in get_machine_name return await self.get(url) File "/config/custom_components/dahua/client.py", line 565, in get raise exception File "/config/custom_components/dahua/client.py", line 550, in get response = await auth.request("GET", url) File "/config/custom_components/dahua/digest.py", line 46, in request response = await self.session.request(method, url, headers=headers, **kwargs) File "/usr/local/lib/python3.8/site-packages/aiohttp/client.py", line 520, in _request conn = await self._connector.connect( File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 535, in connect proto = await self._create_connection(req, traces, timeout) File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 892, in _createconnection , proto = await self._create_direct_connection(req, traces, timeout) File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 1051, in _create_direct_connection raise last_exc File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 1020, in _create_direct_connection transp, proto = await self._wrap_create_connection( File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 971, in _wrap_create_connection raise ClientConnectorCertificateError(req.connection_key, exc) from exc aiohttp.client_exceptions.ClientConnectorCertificateError: Cannot connect to host 10.0.0.100:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1125)')]

mrbarbz commented 3 years ago

ok purchased PoE Switch

Integration wouldn't connect to NVR, I kept getting either username/password/IP address incorrect

Integration worked with the cameras via their IP address connected to the same network as HA via PoE switch but video stream only worked when I left the channel at 0 at setup.

I've found that I could only connect to the cameras when not using internal/inbuilt switch

Below is the log when I try to connect to the NVR if that is any help to you.

This error originated from a custom integration.

Logger: custom_components.dahua Source: custom_components/dahua/digest.py:46 Integration: Dahua (documentation, issues) First occurred: 8:32:24 PM (1 occurrences) Last logged: 8:32:24 PM

Could not connect to Dahua device Traceback (most recent call last): File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 969, in _wrap_create_connection return await self._loop.create_connection(*args, **kwargs) # type: ignore # noqa File "/usr/local/lib/python3.8/asyncio/base_events.py", line 1050, in create_connection transport, protocol = await self._create_connection_transport( File "/usr/local/lib/python3.8/asyncio/base_events.py", line 1080, in _create_connection_transport await waiter File "/usr/local/lib/python3.8/asyncio/sslproto.py", line 529, in data_received ssldata, appdata = self._sslpipe.feed_ssldata(data) File "/usr/local/lib/python3.8/asyncio/sslproto.py", line 189, in feed_ssldata self._sslobj.do_handshake() File "/usr/local/lib/python3.8/ssl.py", line 944, in do_handshake self._sslobj.do_handshake() ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1125)

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/config/custom_components/dahua/config_flow.py", line 201, in _test_credentials data = await client2.get_machine_name() File "/config/custom_components/dahua/client.py", line 95, in get_machine_name return await self.get(url) File "/config/custom_components/dahua/client.py", line 565, in get raise exception File "/config/custom_components/dahua/client.py", line 550, in get response = await auth.request("GET", url) File "/config/custom_components/dahua/digest.py", line 46, in request response = await self.session.request(method, url, headers=headers, **kwargs) File "/usr/local/lib/python3.8/site-packages/aiohttp/client.py", line 520, in _request conn = await self._connector.connect( File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 535, in connect proto = await self._create_connection(req, traces, timeout) File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 892, in _createconnection , proto = await self._create_direct_connection(req, traces, timeout) File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 1051, in _create_direct_connection raise last_exc File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 1020, in _create_direct_connection transp, proto = await self._wrap_create_connection( File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 971, in _wrap_create_connection raise ClientConnectorCertificateError(req.connection_key, exc) from exc aiohttp.client_exceptions.ClientConnectorCertificateError: Cannot connect to host 10.0.0.100:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1125)')]

Also, got this error when trying to connect NVR

This error originated from a custom integration.

Logger: custom_components.dahua Source: custom_components/dahua/config_flow.py:197 Integration: Dahua (documentation, issues) First occurred: 8:32:24 PM (1 occurrences) Last logged: 8:32:24 PM

Could not connect to Dahua device via the RPC2 API, falling back to cgi

fokcuk commented 3 years ago

try to disable SSL and try again. ONVIF on my Dahua NVR has some sort of issue with SSL

mrbarbz commented 3 years ago

try to disable SSL and try again. ONVIF on my Dahua NVR has some sort of issue with SSL

You mean disable on the NVR? If so how? I couldn't find it on the NVR

fokcuk commented 3 years ago

on mine its under Settings>Security>CA Certificates

rroller commented 3 years ago

I've added SSL support in the latest version on this integration. Do you mind trying again? It requires that your port is 443.