I would like to daemonize a task/tasks in some app. It is going to be a websocket server and list of clients. I want to start all my state/event listeners with only one app which is going to share the data with other app only when it received state/event changes with websockets.
The problem that when I starts a websocket server it block the starting process for other apps. Even when I tried to run this tasks with “run_once”, it still blocks.
Could you please help me to find a solution to archive my goal
To do what you want, a plugin will need to be developed which supports Websockets. It wouldn’t be possible to do it with an app, also considering that python websockets works with asyncio and the apps don’t.
Might be you can help me to figure out, how I can listen to many state changes/events with consuming less resources.
I’m struggling of slowing down (sometimes to full freeze) of appdaemon apps, because of many apps listening to the same sensors.
I was trying to create a different layer (app), which is only one is listening to all the sensors and then send the states/events to other apps. But this implementation I was trying to decrease numbers of listeners in all my apps
If you have different apps listening to the same sensors, it shouldn’t freeze AD, unless I don’t understand what you saying. Each app’s callback is executed in a thread, and the same happens for the rest.
Unless you have in some of those apps, a function blocking the thread and if this happens especially in AD 3.0.5 below, yes AD will cry of thread starvation and sometimes freeze. You will need to let us know what kind of function you are running to better advise on what to do.
So you most likely issue (pending what you can show me samples of your app), is not the fact you listening to the same sensor many times, but that you have blocking functions holding up your threads until all threads are possibly blocked and yep freeze.
This essentially is what AppDaemon already does in the background, subscribing to the Home Assistant API and getting all events and state changes. Then, callbacks in your apps basically check against that data already coming in from Home Assistant.
To echo what some of the other posters have said, you’ve either got some blocking functions or a ridiculous number of apps.