JoDehli / PyLoxone

Python Loxone binding
Apache License 2.0
162 stars 40 forks source link

[Bug]: #247

Closed mariovw closed 2 months ago

mariovw commented 2 months ago

Describe the bug

After home assistant Core update 2024.3.0 the integration stop working correctly. After download to previous version everything start working again

Firmware of your Miniserver

Miniserver (Gen 1) por Loxone Firmware: 11.1.9.14

HomeAssistant install method

Gassió (HACS)

Version of HomeAssistant

2024.3.0

Version of Pyloxone

0.6.2

Update pyloxone

Yes

Log

Settings for the log can be found on the main page under the section Log Configuration

elRadix commented 2 months ago

Same issue downgraded hass os back to February

JoDehli commented 2 months ago

@elRadix @mariovw

can you provide error messages? because I see no errors on my system with the newest HA. I can do nothing if I can not reproduce it. I have only a view WARININGS which can be ignored until Home Assistant Core 2025.3.

mariovw commented 2 months ago

Hi @JoDehli,

I am not a code expert but if upgrade to versión 2024.3.0 and I go to the logs I can see the following:

Registrador: homeassistant.config_entries
Fuente: config_entries.py:504
Ocurrió por primera vez: 20:33:52 (1 ocurrencias)
Último inicio de sesión: 20:33:52

Error setting up entry PyLoxone for loxone
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/httpx/_transports/default.py", line 69, in map_httpcore_exceptions
    yield
  File "/usr/local/lib/python3.12/site-packages/httpx/_transports/default.py", line 373, in handle_async_request
    resp = await self._pool.handle_async_request(req)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/httpcore/_async/connection_pool.py", line 216, in handle_async_request
    raise exc from None
  File "/usr/local/lib/python3.12/site-packages/httpcore/_async/connection_pool.py", line 196, in handle_async_request
    response = await connection.handle_async_request(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/httpcore/_async/connection.py", line 101, in handle_async_request
    return await self._connection.handle_async_request(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/httpcore/_async/http11.py", line 143, in handle_async_request
    raise exc
  File "/usr/local/lib/python3.12/site-packages/httpcore/_async/http11.py", line 113, in handle_async_request
    ) = await self._receive_response_headers(**kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/httpcore/_async/http11.py", line 186, in _receive_response_headers
    event = await self._receive_event(timeout=timeout)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/httpcore/_async/http11.py", line 238, in _receive_event
    raise RemoteProtocolError(msg)
httpcore.RemoteProtocolError: Server disconnected without sending a response.

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

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 504, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/loxone/__init__.py", line 175, in async_setup_entry
    if not await miniserver.async_setup():
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/loxone/miniserver.py", line 133, in async_setup
    request_code = await self.lox_config.getJson()
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/loxone/api.py", line 105, in getJson
    api_resp = await client.get("/jdev/cfg/apiKey")
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/httpx/_client.py", line 1801, in get
    return await self.request(
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/httpx/_client.py", line 1574, in request
    return await self.send(request, auth=auth, follow_redirects=follow_redirects)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/httpx/_client.py", line 1661, in send
    response = await self._send_handling_auth(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/httpx/_client.py", line 1689, in _send_handling_auth
    response = await self._send_handling_redirects(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/httpx/_client.py", line 1726, in _send_handling_redirects
    response = await self._send_single_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/httpx/_client.py", line 1763, in _send_single_request
    response = await transport.handle_async_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/httpx/_transports/default.py", line 372, in handle_async_request
    with map_httpcore_exceptions():
  File "/usr/local/lib/python3.12/contextlib.py", line 158, in __exit__
    self.gen.throw(value)
  File "/usr/local/lib/python3.12/site-packages/httpx/_transports/default.py", line 86, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.RemoteProtocolError: Server disconnected without sending a response.
/

If you need another log, please let me know how to proceed.

In my HA all entities sync with loxone doesn't work. For example, I have temp, wind a luninity sensors and they doesn't load anything. Also other entities appears ON and they aren't.

I also upgrade to pyloxone V0.6.3 and nothing is fixed.

Hope this help.

Many thanks for support Mario

JoDehli commented 2 months ago

@mariovw I know now what has changed under the hood. The library called httpx which I use to establish the first connection has been updated since with the new home assistant release. I found some posts where similar errors occurred. The strange thing is that it happened frequently especially when the requested server, in your case the miniserver, has a special http server implementation.

Do you have a big installation? And do you use the internal address or do you use a dns service? And occours the error everytime or does it sometimes connect successfully?

I made a little change on the newest commit on the master branch. Can you copy it manually to your installation and test it?

mariovw commented 2 months ago

Hi @JoDehli ,

I did the changes you proposed and after testing the problem remain... Answering your questions...

image

and buttons doesn't work. I have also buttons to open the main door and garage door and doesn't work

Please le me know if you need further details on any point

Best regards, Mario

Note: I attahced below what I can see in the log

Este error se originó a partir de una integración personalizada.

Logger: homeassistant
Source: custom_components/loxone/api.py:371
Integration: PyLoxone (documentation, issues)
First occurred: 12:33:11 (4 occurrences)
Last logged: 12:33:38

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 1302, in close_connection
    await self.transfer_data_task
  File "/usr/local/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 970, in transfer_data
    await asyncio.shield(self._put_message_waiter)
asyncio.exceptions.CancelledError

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

Traceback (most recent call last):
  File "/config/custom_components/loxone/miniserver.py", line 182, in listen_loxone_send
    await self.api.send_websocket_command(device_uuid, value)
  File "/config/custom_components/loxone/api.py", line 371, in send_websocket_command
    await self._ws.send(command)
  File "/usr/local/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 635, in send
    await self.ensure_open()
  File "/usr/local/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 935, in ensure_open
    raise self.connection_closed_exc()
websockets.exceptions.ConnectionClosedError: sent 1011 (unexpected error) keepalive ping timeout; no close frame received
JoDehli commented 2 months ago

@mariovw in your previous log was the problem by establishing the connection. I think at the moment I can not really help as I can not reproduce it.

Tommy032017 commented 2 months ago

Same issue and connections do not establish anymore. May be this helps: File "/config/custom_components/loxone/__init__.py", line 218, in handle_websocket_command await miniserver.api.send_websocket_command(device_uuid, value) File "/config/custom_components/loxone/api.py", line 369, in send_websocket_command await self._ws.send(command) File "/usr/local/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 635, in send await self.ensure_open() File "/usr/local/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 935, in ensure_open raise self.connection_closed_exc() websockets.exceptions.ConnectionClosedError: sent 1011 (unexpected error) keepalive ping timeout; no close frame received

Additional comment and news: Loxone is Gen1 with latest Beta. So I reinstalled PyLoxone 0.6.3, reboot Loxone and reboot HA and everything works fine again. No interruptions since last few minutes.

mariovw commented 2 months ago

Hi all,

I followed the steps shared by @Tommy032017 and everything is working again.

Thanks everybody! Mario

JoDehli commented 2 months ago

@mariovw what did you do? Update to the new beta?

mariovw commented 2 months ago

Hi again,

No, I have updated to the latest version but not the beta. But let me tell you about some behavior that I have seen. A new HA update has arrived. After updating it stopped working again. It seemed strange to me and I tried restarting the Loxone server. And after that everything start working again.

I think that restarting the Loxone server from the beginning would have worked everything.

I hope this helps.

Tommy032017 commented 2 months ago

No Updates. Only reinstall Pyloxone and reboots.

13.03.2024 19:12:00 Joachim D. @.***>:

@mariovw[https://github.com/mariovw] what did you do? Update to the new beta?

— Reply to this email directly, view it on GitHub[https://github.com/JoDehli/PyLoxone/issues/247#issuecomment-1995237615], or unsubscribe[https://github.com/notifications/unsubscribe-auth/AGKQM3ABXOU2JMLXFJKIHFDYYCJG5AVCNFSM6AAAAABENIAPCCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOJVGIZTONRRGU]. You are receiving this because you were mentioned. [Verfolgungsbild][https://github.com/notifications/beacon/AGKQM3E2GPDDJBMSMZ3ANWLYYCJG5A5CNFSM6AAAAABENIAPCCWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTTW5TUO6.gif]

JoDehli commented 2 months ago

@Tommy032017 @mariovw The beta should not be used. It was a bad idea to release it. I has a complete different websocket implementation. I work on another implementation which should work as stable as the current release but is better maintainable. Thanks for your help.

mariovw commented 1 month ago

Hi all,

After new HA update (2024.3.3) it stop working again. I tried lot of things... Reinstall, update, reset the loxone server,... But nothing.. The pyloxone loads in HA but doesn't read well the devices... Someone has the same issue?

Best

JoDehli commented 1 month ago

@mariovw I have also the newest version installed without any issues. I think it is a problem with your connection between the miniserver and you ha installation. If there is a problem the connections shuts down and newer comes back. I had that in the past with a user which had the ha and the loxone in different networks. The solution was to keep them on the same network. I think you should search on your side for such problems.

mariovw commented 1 month ago

Hi @JoDehli,

Thanks for you feedback! It helped me to solve the problem!

It's true I have my HA and Loxone server in two different netwoks. Connecting all in the same network wasn't feasible to me or at least I would need lot of time to setup everything. But I was thinking in another solution. My Loxone server has two ports opened in my main router. One for internal communication (port 80) and another one for external communications. The solution to allow the communications between Loxone and HA is open the port 80 in the router where HA is connected allowing access through this port between the two routers.

Now everything is working again. Nevertheless I don't know why it was working in the past...

Hope this helps to others with the same problem

Thanks to all,

JoDehli commented 1 month ago

@mariovw I think it has to do with the update of the http lib which ha uses. Hopefully the problem is solved forever and not until the next ha update ;-)

mariovw commented 1 month ago

Hi Again,

after rebooting it crashes again! So sadly it's not the final solution. I'll play with the router for IP Forwading options and try to enhance the communication between the two networks.

I'll let you know any advance