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
71.13k stars 29.8k forks source link

Issues with Velux intigration not loading #121635

Open frr032 opened 2 months ago

frr032 commented 2 months ago

The problem

When I restart HS the Velux integration does not load. See the log entry below.

What version of Home Assistant Core has the issue?

2024.7.1

What was the last working version of Home Assistant Core?

2024.6.1

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Velux

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

There are tow log snips below.  The first one is during a HA restart.  The second one is after turing on Debug logging on the integration and reloading it.

After HS restart..............................
Logger: homeassistant.config_entries
Source: config_entries.py:586
First occurred: 4:40:35 PM (1 occurrences)
Last logged: 4:40:35 PM

Error setting up entry 192.168.1.159 for velux
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 586, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/velux/__init__.py", line 52, in async_setup_entry
    await module.async_start()
  File "/usr/src/homeassistant/homeassistant/components/velux/__init__.py", line 102, in async_start
    await self.pyvlx.load_scenes()
  File "/usr/local/lib/python3.12/site-packages/pyvlx/pyvlx.py", line 106, in load_scenes
    await self.scenes.load()
  File "/usr/local/lib/python3.12/site-packages/pyvlx/scenes.py", line 56, in load
    await get_scene_list.do_api_call()
  File "/usr/local/lib/python3.12/site-packages/pyvlx/api/api_event.py", line 29, in do_api_call
    await self.pyvlx.check_connected()
  File "/usr/local/lib/python3.12/site-packages/pyvlx/pyvlx.py", line 83, in check_connected
    await self.connect()
  File "/usr/local/lib/python3.12/site-packages/pyvlx/pyvlx.py", line 58, in connect
    await self.connection.connect()
  File "/usr/local/lib/python3.12/site-packages/pyvlx/connection.py", line 103, in connect
    self.transport, _ = await self.loop.create_connection(
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1122, in create_connection
    raise exceptions[0]
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1104, in create_connection
    sock = await self._connect_sock(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1007, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/local/lib/python3.12/asyncio/selector_events.py", line 641, in sock_connect
    return await fut
           ^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/selector_events.py", line 681, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
ConnectionRefusedError: [Errno 111] Connect call failed ('192.168.1.159', 51200)

================================================================================= 

AFTER turning on DEBUG logging and reloading the integration........................................

Logger: homeassistant.config_entries
Source: config_entries.py:586
First occurred: 4:40:35 PM (2 occurrences)
Last logged: 6:15:16 PM

Error setting up entry 192.168.1.159 for velux
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 586, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/velux/__init__.py", line 52, in async_setup_entry
    await module.async_start()
  File "/usr/src/homeassistant/homeassistant/components/velux/__init__.py", line 102, in async_start
    await self.pyvlx.load_scenes()
  File "/usr/local/lib/python3.12/site-packages/pyvlx/pyvlx.py", line 106, in load_scenes
    await self.scenes.load()
  File "/usr/local/lib/python3.12/site-packages/pyvlx/scenes.py", line 56, in load
    await get_scene_list.do_api_call()
  File "/usr/local/lib/python3.12/site-packages/pyvlx/api/api_event.py", line 29, in do_api_call
    await self.pyvlx.check_connected()
  File "/usr/local/lib/python3.12/site-packages/pyvlx/pyvlx.py", line 83, in check_connected
    await self.connect()
  File "/usr/local/lib/python3.12/site-packages/pyvlx/pyvlx.py", line 58, in connect
    await self.connection.connect()
  File "/usr/local/lib/python3.12/site-packages/pyvlx/connection.py", line 103, in connect
    self.transport, _ = await self.loop.create_connection(
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1122, in create_connection
    raise exceptions[0]
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1104, in create_connection
    sock = await self._connect_sock(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1007, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/local/lib/python3.12/asyncio/selector_events.py", line 641, in sock_connect
    return await fut
           ^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/selector_events.py", line 681, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
ConnectionRefusedError: [Errno 111] Connect call failed ('192.168.1.159', 51200)

Additional information

This integration is important to me as it closes my skylights when it starts to rain.

Clicking on Known Issues in the Velux integration and log a new issue brought me here. If this is placed in the incorrect area please direct me on where to log this issue. Thanks for your help!

home-assistant[bot] commented 2 months ago

Hey there @julius2342, @deermaximum, mind taking a look at this issue as it has been labeled with an integration (velux) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `velux` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign velux` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


velux documentation velux source (message by IssueLinks)

mib1185 commented 2 months ago

ConnectionRefusedError: [Errno 111] Connect call failed ('192.168.1.159', 51200) means that the target system did not accept the connection request - maybe the KLF 200 gateway is not reachable anymore or needs to be rebooted?

frr032 commented 2 months ago

mib1185 Thanks so much for the reply.

The KLF 200 gateway is active and responds to pings even when the integration does not load. It normally works "most" of the time. However, at times, especially when HA is restarted, the integration does not load. I have an automation that reboots the KLF 200 on HA shutdown by calling this service: Velux: Reboot gateway. It also has been rebooted many times after HA has restarted, and this does not seem to consistently fix the issue. It does sometimes. I have a controllable outlet on the KLF 200 so I can remotely reboot it. I'm new to HA.

How would I detect that the Velux integration has an issue so I can run an automation to reboot the KLF 200 gateway by cycling its power. It may take several reboots.

Also, for a long time I originally, used the Velux integration that needed to be manually installed and configured. I recently changed to the integration that is configured through the UI.

The original integration seemed more stable and had several more useful entities. Things like velocity, connection counter, How would I get those entities back?

mtrojan commented 2 months ago

Same issue here.

2024-07-12 18:32:34.764 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry 192.168.2.11 for velux Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/config_entries.py", line 586, in async_setup result = await component.async_setup_entry(hass, self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/velux/init.py", line 52, in async_setup_entry await module.async_start() File "/usr/src/homeassistant/homeassistant/components/velux/init.py", line 102, in async_start await self.pyvlx.load_scenes() File "/usr/local/lib/python3.12/site-packages/pyvlx/pyvlx.py", line 106, in load_scenes await self.scenes.load() File "/usr/local/lib/python3.12/site-packages/pyvlx/scenes.py", line 56, in load await get_scene_list.do_api_call() File "/usr/local/lib/python3.12/site-packages/pyvlx/api/api_event.py", line 29, in do_api_call await self.pyvlx.check_connected() File "/usr/local/lib/python3.12/site-packages/pyvlx/pyvlx.py", line 83, in checkconnected await self.connect() File "/usr/local/lib/python3.12/site-packages/pyvlx/pyvlx.py", line 58, in connect await self.connection.connect() File "/usr/local/lib/python3.12/site-packages/pyvlx/connection.py", line 103, in connect self.transport, = await self.loop.create_connection( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1149, in create_connection transport, protocol = await self._create_connection_transport( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1182, in _create_connection_transport await waiter ConnectionAbortedError: SSL handshake is taking longer than 60.0 seconds: aborting the connection

mib1185 commented 1 month ago

@julius2342, @deermaximum maybe you have further ideas what could be checked?

pergolafabio commented 1 month ago

Guys, are you using the reboot service ? the KLF only allows one connection, so when you restart HA, the next connection sometimes fails its described here: https://www.home-assistant.io/integrations/velux/#service-veluxreboot_gateway

md1986 commented 2 weeks ago

Guys, are you using the reboot service ?

Thanks for the workaround. However, IMHO this should be built into the code. When I compared the custom integration with this official one, I found that this is exactly the difference that makes this one stop working. I added the code in the DEV container and connected the instance to the gateway. When shutting down HASS, sure enough the gateway rebooted and after starting the instance again, it could connect as expected.

I consider to contribute the code but my knowledge in Python is limited to say the least and I could not write a working unit test for the new code. I am not sure if this would be accepted by the maintainers.

pergolafabio commented 2 weeks ago

i believe it was part of the new pyVlx component already , we need to wait for it

md1986 commented 2 weeks ago

i believe it was part of the new pyVlx component already , we need to wait for it

It is. This is the code I compared. What do you mean “we need to wait for it”? I didn’t read anything about that one replacing this one.

pergolafabio commented 2 weeks ago

There was a PR to update the pyvlx component in the HA core , but not approved yet

Grandma-Betty commented 2 weeks ago

Same issue here as described above:

Logger: homeassistant.config_entries
Source: config_entries.py:604
First occurred: 28 August 2024 at 07:47:12 (2 occurrences)
Last logged: 10:04:14

Error setting up entry 192.168.1.12 for velux
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 604, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/velux/__init__.py", line 52, in async_setup_entry
    await module.async_start()
  File "/usr/src/homeassistant/homeassistant/components/velux/__init__.py", line 102, in async_start
    await self.pyvlx.load_scenes()
  File "/usr/local/lib/python3.12/site-packages/pyvlx/pyvlx.py", line 106, in load_scenes
    await self.scenes.load()
  File "/usr/local/lib/python3.12/site-packages/pyvlx/scenes.py", line 56, in load
    await get_scene_list.do_api_call()
  File "/usr/local/lib/python3.12/site-packages/pyvlx/api/api_event.py", line 29, in do_api_call
    await self.pyvlx.check_connected()
  File "/usr/local/lib/python3.12/site-packages/pyvlx/pyvlx.py", line 83, in check_connected
    await self.connect()
  File "/usr/local/lib/python3.12/site-packages/pyvlx/pyvlx.py", line 58, in connect
    await self.connection.connect()
  File "/usr/local/lib/python3.12/site-packages/pyvlx/connection.py", line 103, in connect
    self.transport, _ = await self.loop.create_connection(
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1122, in create_connection
    raise exceptions[0]
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1104, in create_connection
    sock = await self._connect_sock(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1007, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/local/lib/python3.12/asyncio/selector_events.py", line 641, in sock_connect
    return await fut
           ^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/selector_events.py", line 681, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
OSError: [Errno 113] Connect call failed ('192.168.1.12', 51200)
md1986 commented 2 weeks ago

Same issue here as described above:

Follow the workaround described by @pergolafabio. Works like a charm for me.