home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.73k stars 30.85k forks source link

UPnP/IGD and AsusWRT Error with Pi-hole in System #26869

Closed barqers closed 4 years ago

barqers commented 5 years ago

Home Assistant release with the issue:

0.99.2

Last working Home Assistant release (if known): Not sure

Operating environment (Hass.io/Docker/Windows/etc.):

Component/platform:

AsusWRT and/or UPnp/IGD Integration

Description of problem: Fails to connect to the router when Pi-hole is installed on the system. Does not create any blocked entries within pi-hole so do not believe the traffic is being blocked.

Problem-relevant configuration.yaml entries and (fill out even if it seems unimportant):

None - UPnP/IGD integration in Hassio with Asus WRT router

Traceback (if applicable):

Additional information: Log file gets spammed with entries every minute for:

2019-09-23 21:01:09 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.rt_ac1750_packets_sec_sent fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 924, in _wrap_create_connection
    await self._loop.create_connection(*args, **kwargs))
  File "/usr/local/lib/python3.7/asyncio/base_events.py", line 954, in create_connection
    raise exceptions[0]
  File "/usr/local/lib/python3.7/asyncio/base_events.py", line 941, in create_connection
    await self.sock_connect(sock, address)
  File "/usr/local/lib/python3.7/asyncio/selector_events.py", line 464, in sock_connect
    return await fut
  File "/usr/local/lib/python3.7/asyncio/selector_events.py", line 494, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
ConnectionRefusedError: [Errno 111] Connect call failed ('192.168.x.x', 34575)

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

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 261, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 439, in async_device_update
    await self.async_update()
  File "/usr/src/homeassistant/homeassistant/components/upnp/sensor.py", line 198, in async_update
    new_value = await self._async_fetch_value()
  File "/usr/src/homeassistant/homeassistant/components/upnp/sensor.py", line 254, in _async_fetch_value
    return await self._device.async_get_total_packets_sent()
  File "/usr/src/homeassistant/homeassistant/components/upnp/device.py", line 165, in async_get_total_packets_sent
    return await self._igd_device.async_get_total_packets_sent()
  File "/usr/local/lib/python3.7/site-packages/async_upnp_client/profiles/igd.py", line 120, in async_get_total_packets_sent
    result = await action.async_call()
  File "/usr/local/lib/python3.7/site-packages/async_upnp_client/client.py", line 509, in async_call
    await self.service.requester.async_http_request('POST', url, headers, body)
  File "/usr/local/lib/python3.7/site-packages/async_upnp_client/client.py", line 70, in async_http_request
    body_type=body_type)
  File "/usr/local/lib/python3.7/site-packages/async_upnp_client/aiohttp.py", line 103, in async_do_http_request
    async with self._session.request(method, url, headers=headers, data=body) as response:
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client.py", line 1005, in __aenter__
    self._resp = await self._coro
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client.py", line 476, in _request
    timeout=real_timeout
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 522, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 854, in _create_connection
    req, traces, timeout)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 992, in _create_direct_connection
    raise last_exc
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 974, in _create_direct_connection
    req=req, client_error=client_error)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 931, in _wrap_create_connection
    raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host 192.168.x.x:34575 ssl:None [Connect call failed ('192.168.x.x', 34575)]
probot-home-assistant[bot] commented 5 years ago

Hey there @kennedyshead, mind taking a look at this issue as its been labeled with a integration (asuswrt) you are listed as a codeowner for? Thanks!

probot-home-assistant[bot] commented 5 years ago

Hey there @robbiet480, mind taking a look at this issue as its been labeled with a integration (upnp) you are listed as a codeowner for? Thanks!

dgomes commented 5 years ago

CC @StevenLooman

StevenLooman commented 5 years ago

A few checks, can you, from your own computer, connect to http://192.168.x.x:34575 ?

Also, was the integration itself set up and 'initialized'? I.e., do you see the UPnP sensors (traffic counters etc) in your home assistant?

barqers commented 5 years ago

A few checks, can you, from your own computer, connect to http://192.168.x.x:34575 ?

Also, was the integration itself set up and 'initialized'? I.e., do you see the UPnP sensors (traffic counters etc) in your home assistant?

Hey Steven, sorry for the slow reply. I cannot access that URL in my web browser - the router doesn't seem to be responding to http requests on that port (with or without pihole running btw).

However, previously they were working and pulling the upnp sensors in HA. They no longer pull the data and instead flood the log files with the above error.

I noticed my router is not running merlin (if that matters) and so only has telnet, not SSH enabled.

StevenLooman commented 5 years ago

Did you change the IP to you routers IP?

Also, have you tried removing and adding the integration?

Is there anything else that has changed?

Not sure what merlin is, the point is that it should be running a UPnP/IGD server. If you haveshell- access to the home-assistant environment you can run this to discover/search for the UPnP devices on your network:

$ upnp-client search

This will output something like:

{"Cache-Control": "max-age=1900", "Location": "http://192.168.178.1:80/RootDevice.xml", "Server": "UPnP/1.0 UPnP/1.0 UPnP-Device-Host/1.0", "ST": "upnp:rootdevice", "USN": "uuid:upnp-InternetGatewayDevice-1_0-889ffacb9043::upnp:rootdevice", "EXT": "", "_timestamp": "2019-10-12 12:34:50.839151", "_address": "192.168.178.1:1900", "_udn": "uuid:upnp-InternetGatewayDevice-1_0-889ffacb9043", "_source": "search"}
{"Cache-Control": "max-age=1900", "Location": "http://192.168.178.1:80/RootDevice.xml", "Server": "UPnP/1.0 UPnP/1.0 UPnP-Device-Host/1.0", "ST": "uuid:upnp-InternetGatewayDevice-1_0-889ffacb9043", "USN": "uuid:upnp-InternetGatewayDevice-1_0-889ffacb9043", "EXT": "", "_timestamp": "2019-10-12 12:34:50.839446", "_address": "192.168.178.1:1900", "_udn": "uuid:upnp-InternetGatewayDevice-1_0-889ffacb9043", "_source": "search"}
...
thundergreen commented 5 years ago

I got also this error. I added this upnp by integration and after a while it throws this error:

Tue Nov 05 2019 19:04:56 GMT+0100 (Mitteleuropäische Normalzeit)
Update for sensor.rt_ac68u_bytes_sent fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 936, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore  # noqa
  File "/usr/local/lib/python3.7/asyncio/base_events.py", line 954, in create_connection
    raise exceptions[0]
  File "/usr/local/lib/python3.7/asyncio/base_events.py", line 941, in create_connection
    await self.sock_connect(sock, address)
  File "/usr/local/lib/python3.7/asyncio/selector_events.py", line 464, in sock_connect
    return await fut
  File "/usr/local/lib/python3.7/asyncio/selector_events.py", line 494, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
ConnectionRefusedError: [Errno 111] Connect call failed ('192.168.1.1', 47779)

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

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 270, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 448, in async_device_update
    await self.async_update()
  File "/usr/src/homeassistant/homeassistant/components/upnp/sensor.py", line 143, in async_update
    self._state = await self._device.async_get_total_bytes_sent()
  File "/usr/src/homeassistant/homeassistant/components/upnp/device.py", line 151, in async_get_total_bytes_sent
    return await self._igd_device.async_get_total_bytes_sent()
  File "/usr/local/lib/python3.7/site-packages/async_upnp_client/profiles/igd.py", line 99, in async_get_total_bytes_sent
    result = await action.async_call()
  File "/usr/local/lib/python3.7/site-packages/async_upnp_client/client.py", line 509, in async_call
    await self.service.requester.async_http_request('POST', url, headers, body)
  File "/usr/local/lib/python3.7/site-packages/async_upnp_client/client.py", line 70, in async_http_request
    body_type=body_type)
  File "/usr/local/lib/python3.7/site-packages/async_upnp_client/aiohttp.py", line 103, in async_do_http_request
    async with self._session.request(method, url, headers=headers, data=body) as response:
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client.py", line 1012, in __aenter__
    self._resp = await self._coro
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client.py", line 483, in _request
    timeout=real_timeout
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 523, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 859, in _create_connection
    req, traces, timeout)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 1004, in _create_direct_connection
    raise last_exc
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 986, in _create_direct_connection
    req=req, client_error=client_error)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 943, in _wrap_create_connection
    raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host 192.168.1.1:47779 ssl:None [Connect call failed ('192.168.1.1', 47779)]

trying this in browser gives me connection refused.. . Re-adding the integration will work a certain time but will fail after a while

StevenLooman commented 5 years ago

Not sure what is happening. Your device might be blocking the updates as a means of protection.

Does it work again later on, or only if you re-add the integration?

thundergreen commented 5 years ago

Indeed it works again after re adding the component

Steven Looman notifications@github.com schrieb am So., 10. Nov. 2019, 18:21:

Not sure what is happening. Your device might be blocking the updates as a means of protection.

Does it work again later on, or only if you re-add the integration?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/home-assistant/home-assistant/issues/26869?email_source=notifications&email_token=ADFUA7Y2HPD2LNWJZCSUGATQTA7JJA5CNFSM4IZXXCBKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEDVCBRY#issuecomment-552214727, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADFUA73CHIMZIRXEPCKEJSDQTA7JJANCNFSM4IZXXCBA .

StevenLooman commented 5 years ago

Does it eventually work again, without re-adding the integration? I.e., does your router start responding again after a while, without you doing anything?

thundergreen commented 5 years ago

I did not really follow this up the last days. but all of udden the sensor stops collecting data and there are error logs regarding that hass cannot connect to the router... restarting hass fixes it. Also i noticed my keyfile and if using the sensors from the component breaks this component somehow. i am using last dev veriosn 0.102.0b2 for the moment.

StevenLooman commented 4 years ago

What do you mean by keyfile?

Do you know how to use custom components? It is worth trying to re-initialize the backend of this component periodically, but I don't want to change it before it is certain this works.

thundergreen commented 4 years ago

@StevenLooman i meant the ssh keyfile instead of password. It breaks my asuswrt component completly. I would go for a custom component yeah. I have the feeling something is broken with asuswrt component for the moment.

barqers commented 4 years ago

@thundergreen @StevenLooman Didn't mean to leave you both hanging but I've just switched to a NetGear Orbi and I'm no longer having issues with the UPnP/IGD component. The last router I had issues on was my Asus RT-AC1750. So it seems the problem is only for Asus routers.

StevenLooman commented 4 years ago

@thundergreen Hi sorry for the delay. I have changed the sensors of the upnp component to reinitialize every hour, see this commit. Please know this is just a test and I have no intention to let this land in Home Assistant itself!

Do you know what to do with this? You can either create a custom component (recommended, copy the files from the upnp component to the custom component and apply the changes in the commit), or edit the python files in your Home Assistant installation.

jacekpaszkowski commented 4 years ago

in addition to this and my issue #30896 (which was marked as duplicate) i also get some timeout errors but sesnors work. Of course till next restart.

2020-01-17 19:17:10 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.openwrt_router_packets_sec_received fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/async_upnp_client/aiohttp.py", line 103, in async_do_http_request
    async with self._session.request(method, url, headers=headers, data=body) as response:
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client.py", line 1012, in __aenter__
    self._resp = await self._coro
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client.py", line 504, in _request
    await resp.start(conn)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client_reqrep.py", line 847, in start
    message, payload = await self._protocol.read()  # type: ignore  # noqa
  File "/usr/local/lib/python3.7/site-packages/aiohttp/streams.py", line 591, in read
    await self._waiter
concurrent.futures._base.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 281, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 459, in async_device_update
    await self.async_update()
  File "/usr/src/homeassistant/homeassistant/components/upnp/sensor.py", line 200, in async_update
    new_value = await self._async_fetch_value()
  File "/usr/src/homeassistant/homeassistant/components/upnp/sensor.py", line 254, in _async_fetch_value
    return await self._device.async_get_total_packets_received()
  File "/usr/src/homeassistant/homeassistant/components/upnp/device.py", line 153, in async_get_total_packets_received
    return await self._igd_device.async_get_total_packets_received()
  File "/usr/local/lib/python3.7/site-packages/async_upnp_client/profiles/igd.py", line 110, in async_get_total_packets_received
    result = await action.async_call()
  File "/usr/local/lib/python3.7/site-packages/async_upnp_client/client.py", line 509, in async_call
    await self.service.requester.async_http_request('POST', url, headers, body)
  File "/usr/local/lib/python3.7/site-packages/async_upnp_client/client.py", line 70, in async_http_request
    body_type=body_type)
  File "/usr/local/lib/python3.7/site-packages/async_upnp_client/aiohttp.py", line 113, in async_do_http_request
    resp_body = None
  File "/usr/local/lib/python3.7/site-packages/async_timeout/__init__.py", line 55, in __aexit__
    self._do_exit(exc_type)
  File "/usr/local/lib/python3.7/site-packages/async_timeout/__init__.py", line 92, in _do_exit
    raise asyncio.TimeoutError
concurrent.futures._base.TimeoutError
2020-01-17 19:17:11 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.openwrt_router_packets_sec_sent fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/async_upnp_client/aiohttp.py", line 103, in async_do_http_request
    async with self._session.request(method, url, headers=headers, data=body) as response:
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client.py", line 1012, in __aenter__
    self._resp = await self._coro
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client.py", line 504, in _request
    await resp.start(conn)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client_reqrep.py", line 847, in start
    message, payload = await self._protocol.read()  # type: ignore  # noqa
  File "/usr/local/lib/python3.7/site-packages/aiohttp/streams.py", line 591, in read
    await self._waiter
concurrent.futures._base.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 281, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 459, in async_device_update
    await self.async_update()
  File "/usr/src/homeassistant/homeassistant/components/upnp/sensor.py", line 200, in async_update
    new_value = await self._async_fetch_value()
  File "/usr/src/homeassistant/homeassistant/components/upnp/sensor.py", line 256, in _async_fetch_value
    return await self._device.async_get_total_packets_sent()
  File "/usr/src/homeassistant/homeassistant/components/upnp/device.py", line 157, in async_get_total_packets_sent
    return await self._igd_device.async_get_total_packets_sent()
  File "/usr/local/lib/python3.7/site-packages/async_upnp_client/profiles/igd.py", line 120, in async_get_total_packets_sent
    result = await action.async_call()
  File "/usr/local/lib/python3.7/site-packages/async_upnp_client/client.py", line 509, in async_call
    await self.service.requester.async_http_request('POST', url, headers, body)
  File "/usr/local/lib/python3.7/site-packages/async_upnp_client/client.py", line 70, in async_http_request
    body_type=body_type)
  File "/usr/local/lib/python3.7/site-packages/async_upnp_client/aiohttp.py", line 113, in async_do_http_request
    resp_body = None
  File "/usr/local/lib/python3.7/site-packages/async_timeout/__init__.py", line 55, in __aexit__
    self._do_exit(exc_type)
  File "/usr/local/lib/python3.7/site-packages/async_timeout/__init__.py", line 92, in _do_exit
    raise asyncio.TimeoutError
concurrent.futures._base.TimeoutError
jaydub385 commented 4 years ago

same issue as jacekpaszkowski with the timeout error. Home Assistant 0.104.2. Sometimes after removing the entities and restarting they come back. Any way to force a rediscovery?

StevenLooman commented 4 years ago

Nothing has changed in recent versions of Home Assistant. Reinitialization (not rediscovery) is done in the commit from this comment, albeit in a hacky and certainly not a production-usable way. Please test this if you have the means and knowledge on how to do so.

stale[bot] commented 4 years ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue now has been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

StevenLooman commented 4 years ago

A lot has changed with #33108 and will be included in the next release. This can be closed @robbiet480 .