Websocket library brake AppDaemon add-on connection

I am using HA OS on Raspberry.
I have installed the AppDaemon Add-on from the store and i’m trying to import “websocket” library during app startup.
When i add websocket python library the startup process of the python scripts brake and I receive the following error:
2024-03-26 11:40:00.858710 WARNING HASS: Disconnected from Home Assistant, retrying in 5 seconds

Also adding the token nothing changes.

Here the full log:

Collecting websocket
  Downloading websocket-0.2.1.tar.gz (195 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 195.3/195.3 kB 1.6 MB/s eta 0:00:00
  Preparing metadata (setup.py): started
  Preparing metadata (setup.py): finished with status 'done'
Collecting gevent (from websocket)
  Downloading gevent-24.2.1-cp311-cp311-musllinux_1_1_aarch64.whl.metadata (13 kB)
Collecting greenlet (from websocket)
  Downloading https://wheels.home-assistant.io/musllinux-index/greenlet-3.0.3-cp311-cp311-musllinux_1_2_aarch64.whl (1.0 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.0/1.0 MB 4.0 MB/s eta 0:00:00
Collecting zope.event (from gevent->websocket)
  Downloading zope.event-5.0-py3-none-any.whl.metadata (4.4 kB)
Collecting zope.interface (from gevent->websocket)
  Downloading https://wheels.home-assistant.io/musllinux-index/zope.interface-6.2-cp311-cp311-musllinux_1_2_aarch64.whl (205 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 205.5/205.5 kB 11.0 MB/s eta 0:00:00
Requirement already satisfied: setuptools in /usr/lib/python3.11/site-packages (from zope.event->gevent->websocket) (68.2.2)
Downloading gevent-24.2.1-cp311-cp311-musllinux_1_1_aarch64.whl (5.4 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 5.4/5.4 MB 6.2 MB/s eta 0:00:00
Downloading zope.event-5.0-py3-none-any.whl (6.8 kB)
Building wheels for collected packages: websocket
  Building wheel for websocket (setup.py): started
  Building wheel for websocket (setup.py): finished with status 'done'
  Created wheel for websocket: filename=websocket-0.2.1-py3-none-any.whl size=192113 sha256=4c4b4b2c1bdfbd85b858f2f9213b9af3441b78849b1053771470eace4830cbbf
  Stored in directory: /tmp/pip-ephem-wheel-cache-14j0lw5j/wheels/5c/27/8d/6df11772ae53bc15857d5e435874915eeceb03f528314e5b61
Successfully built websocket
Installing collected packages: zope.interface, zope.event, greenlet, gevent, websocket
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
Successfully installed gevent-24.2.1 greenlet-3.0.3 websocket-0.2.1 zope.event-5.0 zope.interface-6.2
s6-rc: info: service init-appdaemon successfully started
s6-rc: info: service appdaemon: starting
s6-rc: info: service appdaemon successfully started
s6-rc: info: service legacy-services: starting
s6-rc: info: service legacy-services successfully started
[11:39:39] INFO: Starting AppDaemon...
2024-03-26 11:39:54.060415 INFO AppDaemon: AppDaemon Version 4.4.2 starting
2024-03-26 11:39:54.069288 INFO AppDaemon: Python version is 3.11.6
2024-03-26 11:39:54.070409 INFO AppDaemon: Configuration read from: /config/appdaemon.yaml
2024-03-26 11:39:54.071728 INFO AppDaemon: Added log: AppDaemon
2024-03-26 11:39:54.072976 INFO AppDaemon: Added log: Error
2024-03-26 11:39:54.074085 INFO AppDaemon: Added log: Access
2024-03-26 11:39:54.075218 INFO AppDaemon: Added log: Diag
2024-03-26 11:39:54.913258 INFO AppDaemon: Loading Plugin HASS using class HassPlugin from module hassplugin
2024-03-26 11:39:55.778357 INFO HASS: HASS Plugin Initializing
2024-03-26 11:39:55.778971 WARNING HASS: ha_url not found in HASS configuration - module not initialized
2024-03-26 11:39:55.779772 INFO HASS: HASS Plugin initialization complete
2024-03-26 11:39:55.781628 INFO AppDaemon: Initializing HTTP
2024-03-26 11:39:55.783043 INFO AppDaemon: Using 'ws' for event stream
2024-03-26 11:39:55.817621 INFO AppDaemon: Starting API
2024-03-26 11:39:55.830244 INFO AppDaemon: Starting Admin Interface
2024-03-26 11:39:55.831818 INFO AppDaemon: Starting Dashboards
2024-03-26 11:39:55.850436 WARNING HASS: Disconnected from Home Assistant, retrying in 5 seconds
2024-03-26 11:39:56.007600 INFO AppDaemon: App 'hello_world' added
2024-03-26 11:39:56.011047 INFO AppDaemon: App 'test' added
2024-03-26 11:39:56.012729 INFO AppDaemon: Found 2 active apps
2024-03-26 11:39:56.013826 INFO AppDaemon: Found 0 inactive apps
2024-03-26 11:39:56.015098 INFO AppDaemon: Found 0 global libraries
2024-03-26 11:39:56.016145 INFO AppDaemon: Starting Apps with 2 workers and 2 pins
2024-03-26 11:39:56.020664 INFO AppDaemon: Running on port 5050
2024-03-26 11:40:00.858710 WARNING HASS: Disconnected from Home Assistant, retrying in 5 seconds
2024-03-26 11:40:05.866347 WARNING HASS: Disconnected from Home Assistant, retrying in 5 seconds
2024-03-26 11:40:10.873223 WARNING HASS: Disconnected from Home Assistant, retrying in 5 seconds

my appdaemon yaml:

appdaemon:
  latitude: 52.379189
  longitude: 4.899431
  elevation: 2
  time_zone: Europe/Amsterdam
  plugins:
    HASS:
      type: hass
      ha_url: http://127.0.0.1:8123
      token: ###TOKEN ANONYMIZED###
http:
  url: http://127.0.0.1:5050
admin:
api:
hadashboard:

And a screen of the configuration page.

can someone helps me understand how to solve the issue?
I’m struggling on it from days

I’m not entirely certain, but I’m wondering if using the websocket library in your code is causing the HA disconnect. The HA plugin uses websocket itself as the connection, so maybe when you are creating your websocket, they are conflicting on the same port? Without seeing your app(s), it’s hard to determine.

What are you using websocket for?

At the moment i’m only importing the library in the config of AppDaemon, the script I need is still on my local machine. The issue appears simply pre-loading the library.

I need to integrate my solar inverter in HA (no addon actually available for my product).
The screep just login in the web page, send a WS request and write the JSON in a local file that HA should monitor. I just need a WS client for sending a simple request, no ports need to be exposed by HA.

I’ve resolved the issue. The “websocket” library was conflicting with the one already in use by AppDaemon. I simply resolved it by importing it directly into the script rather than through the configuration interface.