xannor / ha_reolink_rest

ReoLink REST/Web Camera Integration for Home Assistant
24 stars 3 forks source link

Adding new device just goes in a loop #3

Closed warwickbuilds closed 1 year ago

warwickbuilds commented 2 years ago

Issue: I've install the integration from HACS, rebooted HA. Go to integrations and add new integration selecting "Reolink Device" Pop-up asking for Host+Port showing I enter IP address and Port of 80 (don't tick HTTPS) image

Hit submit, and inputs are just cleared image

I cannot progress past the initial configuration input

Thanks, I'm excited to see how this progresses, especially the movement status updates as the other integration out there does not support for these devices

vk2him commented 2 years ago

I had this issue as well. However if you install the Reolink Discovery integration https://github.com/xannor/ha_reolink_discovery it will detect any extisting cameras so you can create them.

warwickbuilds commented 2 years ago

I had this issue as well. However if you install the Reolink Discovery integration https://github.com/xannor/ha_reolink_discovery it will detect any extisting cameras so you can create them.

Ok thanks I did consider that being a requirement, I'll give it a try

warwickbuilds commented 2 years ago

Yes adding the discovery add-in, the only using that to discovery and add in the ones it finds works.

Looks like the above option to add in devices isn't supported to work and was a dev artifact.

vk2him commented 2 years ago

That's odd - if that's the case https://github.com/xannor/ha_reolink_discovery should be part of the main integration as it's not obvious you need to install it

xannor commented 2 years ago

it is not required. You also shouldn't need to enter port 80 as that is a default port. I am going to re-open this to remind myself to check the manual configuration and make sure it has no issues.

JPM-git commented 2 years ago

Well i know that this was the first reported bug and it's marked to be corrected, or implemented some kind or workaround, however i'm on one of the supported cameras RLC-820A, i have the reolink_discovery integration installed and i'm still on this loop without being able to add the cameras all i see is this on the log:

2022-08-30 15:30:49.635 DEBUG (MainThread) [custom_components.reolink_discovery] Setting up reolink discovery component
2022-08-30 15:30:49.636 DEBUG (MainThread) [custom_components.reolink_discovery] Listening on 0.0.0.0
2022-08-30 15:30:49.644 DEBUG (MainThread) [custom_components.reolink_discovery] Listener connected ('0.0.0.0', 3000)

PS: I have both components on debug log level and this are the only entries on the entire log:

    custom_components.reolink_discovery: debug
    custom_components.reolink_rest: debug

Adding a camera on the reolink_rest/ip component shows nothing on the log

xannor commented 2 years ago

Unfortunatle I don't have much logging in the dataflow portion so errors that occur there have to be hand diagnosed. I am in the middle of a code restructure (something I started right before these errors were posted) and I am hoping to get that finished this weekend, then I can test to see if it cleaned up some of these issues and get fixes for the others.

miff2000 commented 2 years ago

If you are using Homeassistant in Docker and it's not configured to use Host networking, that will likely be your issue.

For discovery to work, the Reolink Discovery integration needs to receive multicast announcements from the Reolink devices, which can only be achieved by Homeassistant being on the same subnet as your using Reolink devices (which Host networking achieves). Docker bridge networks don't receive copies of multicast announcements from the physical network.

To get around this, you can should your Homeassistant container to use Host networking (the --net=host flag if using a docker run command, or network_mode: host if using Docker Compose), just until the your Reolink devices are discovered. After that you can switch back to your original Docker network setup and it should just continue to work.

This worked for me at least. My two cameras magically appeared in Homeassistant a few minutes after I restarted it with the container set to use Host networking, and it's continued to work after setting it back.

Any time you want to add new devices or the network configuration of your Reolink devices change, you'll need to perform this same procedure so that Homeassistant can pick up the changes.

gumbyCAD commented 2 years ago

I have a similar issue, however no matter what I put it doesn't progress. image

I think I have the latest inside of HACS. image

2 x E1 Cameras. one wireless the other hardwire with ethernet cable

mikedrews commented 2 years ago

Is there some file we can manually add the cameras info? Discovery will not work on my home network as the cameras and HA are on different subnets and I do not want to have broadcast packets traverse the subnets. I would love to get this to work but I am also stuck in this same loop when trying to add the cameras via the interface. If there is any data you need from me please let me know. I am using RLC-511W and RLC-811A cams. My HA is the latest with respect to updates.

xannor commented 2 years ago

Normally yes, but there is a bug I am working out in the manual addition. I am also working out a bug with PTZ cameras, which breaks on setup, and causes NVRs with a PTZ on them to not work at all.

xannor commented 2 years ago

I finally got a new version up, though this is "very" alpha, please give it a go and see if manually adding the cameras works now, and let me know.

mikedrews commented 2 years ago

Get the following when trying to add the integration. This integration does not support configuration via the UI. If you followed this link from the Home Assistant website, make sure you run the latest version of Home Assistant. The log shows this ... Logger: homeassistant.config_entries Source: config_entries.py:796 First occurred: 6:21:39 PM (2 occurrences) Last logged: 6:25:31 PM

Error occurred loading configuration flow for integration reolink_rest: No module named 'backports.strenum'

xannor commented 2 years ago

I must have missed a backports entry, I decided to remove strenum since it is not in 3.10. I will double check and push a new version once I have verified and tried to correct a couple of the other issues that cropped up.

mikedrews commented 2 years ago

I was able to add all my cameras successfully. I did however notice the following in the logs.

Logger: homeassistant.components.websocket_api.http.connection Source: custom_components/reolink_rest/camera.py:402 Integration: Home Assistant WebSocket API (documentation, issues) First occurred: 6:01:07 PM (1 occurrences) Last logged: 6:01:07 PM

[548229773104] Error handling message: Unknown error (unknown_error) Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 27, in _handle_async_response await func(hass, connection, msg) File "/usr/src/homeassistant/homeassistant/components/camera/init.py", line 805, in ws_camera_stream url = await _async_stream_endpoint_url(hass, camera, fmt=msg["format"]) File "/usr/src/homeassistant/homeassistant/components/camera/init.py", line 953, in _async_stream_endpoint_url stream = await camera.async_create_stream() File "/usr/src/homeassistant/homeassistant/components/camera/init.py", line 524, in async_create_stream source = await self.stream_source() File "/config/custom_components/reolink_rest/camera.py", line 402, in stream_source url = await client.get_rtmp_url( File "/usr/local/lib/python3.10/site-packages/async_reolink/api/network/init.py", line 172, in get_rtmp_url await self._ensure_ports_and_link() File "/usr/local/lib/python3.10/site-packages/async_reolink/api/network/init.py", line 124, in _ensure_ports_and_link self.__link = response.local_link AttributeError: 'GetNetworkPortsResponse' object has no attribute 'local_link'

gumbyCAD commented 2 years ago

@mikedrews what was the port number you used? Assume the Host is the IP Address of the camera?

mikedrews commented 2 years ago

I didn't specify any port and yes the IP is of the camera.

xannor commented 2 years ago

I added a new version v0.6.3 which may fix this issue. Please update and let me know.

mikedrews commented 2 years ago

Added additional cameras (E1 Zoom, RLC-811a, RLC-511W) with no issues however seeing this now in the logs.

Logger: custom_components.reolink_rest Source: custom_components/reolink_rest/entity.py:289 Integration: Reolink IP Device (documentation, issues) First occurred: 12:38:46 PM (29 occurrences) Last logged: 1:06:46 PM

Unexpected error fetching reolink_rest-95270003ZP9N1QBU data: invalid response Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 205, in _async_refresh self.data = await self._async_update_data() File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 164, in _async_update_data return await self.update_method() File "/config/custom_components/reolink_rest/init.py", line 77, in _update_data return await entity_data.async_update() File "/config/custom_components/reolink_rest/entity.py", line 454, in async_update result = await self._execute_commands(commands, command_channel=command_channel) File "/config/custom_components/reolink_rest/entity.py", line 341, in _execute_commands raise reoresp File "/config/custom_components/reolink_rest/entity.py", line 289, in _execute_commands async for response in self.client.batch(commands): File "/usr/local/lib/python3.10/site-packages/async_reolink/rest/connection.py", line 350, in __execute raise errors.ReolinkResponseError( async_reolink.api.errors.ReolinkResponseError: invalid response

Logger: async_reolink.rest.connection Source: custom_components/reolink_rest/entity.py:289 Integration: Reolink IP Device (documentation, issues) First occurred: 12:38:46 PM (29 occurrences) Last logged: 1:06:46 PM

did not get json as response: ([{"cmd": "GetAbility", "action": 0, "param": {"User": {"userName": "HomeAssist"}}}, {"cmd": "GetTime", "action": 0}, {"cmd": "GetNetPort", "action": 0}, {"cmd": "GetDevInfo", "action": 0}, {"cmd": "GetMdState", "action": 0, "param": {"channel": 0}}, {"cmd": "GetZoomFocus", "action": 0, "param": {"channel": 0}}])

xannor commented 2 years ago

I have seen stuff like this when testing/developing. Too many connection attempts seem to confuse the cameras and they either ignore requests or leak the browser session encryption into other requests, providing invalid data. The best thing to do is reboot the camera and see if it happens again.

xannor commented 2 years ago

I actually do have a working version of their encrypted connection the browser client uses, but since it is entirely undocumented I am leary of using it, as if they make changes things would just start breaking.

gumbyCAD commented 2 years ago

I just did the update to your latest build and my "E1 Pro" is not allowing me to config. I tried no port number and port 80. What am I doing wrong? image

image

xannor commented 2 years ago

Can you check the system log for errors, and post them?

gumbyCAD commented 2 years ago

ReolinkLOgs.txt

I hope this what you want, sorry newbie at HA.

gumbyCAD commented 2 years ago

I also cleared the logs after a restart and just did one test. image

gumbyCAD commented 2 years ago

Let me know how I might be able to help. Thanks for writing it. :)

xannor commented 2 years ago

Everything there points to port 80 not being available, either your system supports SSL only, is configured to use a port other than 80, or there is a firewall between the two blocking port 80. The first thing I would try, is from a terminal session in your home assistant computer, try to ping the device by ip, and if that succeeds, try to curl or wget and see if you get a response from it.

gumbyCAD commented 2 years ago

I can ping the IP Address from both my PC and SSH on the Raspberri Pi from inside my home.

Not sure how to check the Port stuff or firewall? Any suggestions?

As far as I know, my internal network is very simple.

xannor commented 2 years ago

on the pi, via ssh, can you run the curl or wget command? if so run it with http://[ip of camera] and see if it gets an html page back.

The other possibility is I have seen the cameras "lock" out computers (it happens to me when I heavily test new features on a single device) and just refuse to talk for a few minutes, usualy this clears up after 10-15 minutes, so I feel like it is a some sort of brute force protection built into the firmware.

Also see if v0.6.6 works better, as I am having more success with that one, and that includes E1's.

gumbyCAD commented 2 years ago

not sure how to use CURL or WGET .... however I tried this.

Is this a problem? It was test run from inside my local network

image

xannor commented 2 years ago

Only if you are port forwarding port 80 to your camera, or your camera has a public IP address, both which I hope you are not doing.

curl and wget are pretty strait forward, from a SSH terminal type either command name by its self and see if it says command not found or give other output, like help instructions, etc... which ever works, and it doesnt matter which, type the command again followed by http://[ip.address.of.camera] and see if it says something like timeout or connection refused, or dumps html or saves an .html file. The latter two means it could talk to the camera over port 80 anything else means it cannot.

gumbyCAD commented 2 years ago

Interesting, I can ping it but not the other image

xannor commented 2 years ago

This means that either the camera you are using does not support the REST API or that port 80 and port 443 are disabled in the network ports configuration. I am leaning towards it not supporting the API, as on most of the cameras, if port 80 was disabled the camera automatically would redirect to port 4413

I never asked what type of camera you have. I see in your screenshots it has E1 in its name, but I think only the E1 Zoom, and possibly some versions of the E1 Pro support what ReoLink call the CGI interface (REST API).

https://support.reolink.com/hc/en-us/articles/900000625763-What-is-CGI-API https://support.reolink.com/hc/en-us/articles/900000617826-Which-Reolink-Products-Support-CGI-RTSP-ONVIF

If this is the case your camera only supports the proprietary protocol, of which, there is little documentations available about it.