Appdaemon loses connection to HA

Hi,
Since a while, and most probably from the moment I’ve ugraded HA to 0.116, appdaemon to 4.0.5 and Python to 3.8.6 the HADashboard is losing connection to HA instance, which is demonstrated by inability to trigger scripts from HADashboard and not refreshing new entities (e.g. scripts). It is resolved by restarting appdaemon but comes back again after a while. I have not noticed any errors in the log other than mentioning that it can’t run the script. Any ideas?

Please post the logs. Do you see any websocket or authentication errors in the Home Assistant log? Have you configured all available logs in appdaemon?

How did you install HA and appdaemon, i.e. supervised install, virtual enviroment or docker?

Before switching to docker, I had similar issues from time to time due to conflicting python dependencies.

I have now enabled all logs but at the start they are empty. The appdaemon_daemon.log has no errors for now. Let’s see once it disconnects again. The appdaemon was installed as part of the HA Core community plugin to FreeNAS and so far was working ok. So it is installed in a FreeNAS jail in a virtualenv:

Testing virtualenv...

 CWD: /usr/local/share/appdaemon
 Python 3.8.6
 AppDaemon 4.0.5

And here is the appdaemon_daemon.log:

2020-10-27 14:19:52.361000 INFO AppDaemon: AppDaemon Version 4.0.5 starting
2020-10-27 14:19:52.361274 INFO AppDaemon: Python version is 3.8.6
2020-10-27 14:19:52.361411 INFO AppDaemon: Configuration read from: /home/hass/appdaemon/conf/appdaemon.yaml
2020-10-27 14:19:52.361551 INFO AppDaemon: Added log: AppDaemon
2020-10-27 14:19:52.361695 INFO AppDaemon: Added log: Error
2020-10-27 14:19:52.361830 INFO AppDaemon: Added log: Access
2020-10-27 14:19:52.361966 INFO AppDaemon: Added log: Diag
2020-10-27 14:19:52.387396 INFO AppDaemon: Loading Plugin HASS using class HassPlugin from module hassplugin
2020-10-27 14:19:52.415701 INFO HASS: HASS Plugin Initializing
2020-10-27 14:19:52.415901 INFO HASS: HASS Plugin initialization complete
2020-10-27 14:19:52.416366 INFO AppDaemon: Initializing HTTP
2020-10-27 14:19:52.416690 INFO AppDaemon: Using 'ws' for event stream
2020-10-27 14:19:52.420480 INFO AppDaemon: Starting API
2020-10-27 14:19:52.424249 INFO AppDaemon: Starting Admin Interface
2020-10-27 14:19:52.424574 INFO AppDaemon: Starting Dashboards
2020-10-27 14:19:52.437794 WARNING AppDaemon: Threads directive is deprecated apps - will be pinned. Use total_threads if you want to unpin your apps
2020-10-27 14:19:52.441772 INFO HASS: Connected to Home Assistant 0.116.2

no errors so far.

Ok, good. You can also add

logs:
  homeassistant.components.websocket_api

to your logger config in HA so you can see any websocket error since that’s how appdaemon talks to HA. I would guess the websocket connection goes down for some reason.

OK, I’ve had no logger configuration at all so I’ve added the following:

logger:
  default: warning
  logs:
    homeassistant.components.websocket_api: warning

Let me know if that is good enough

I would set the log level to info to start with.

OK, so here we go. HADashboard cannot run scripts anymore from mode widget. The following is logged in appdaemon_daemon.log. Scripts triggered from script widget work ok:

2020-10-27 18:10:02.612065 WARNING AppDaemon: Unknown domain (default/script) in call_service from stream
2020-10-27 18:10:25.640166 INFO AppDaemon: Loading custom skin 'sypialnia'
2020-10-27 18:10:25.656835 INFO AppDaemon: function [get_dashboard] finished in 16 ms
2020-10-27 18:10:25.677621 INFO AppDaemon: Client disconnection from Sypialnia
2020-10-27 18:10:26.636078 INFO AppDaemon: New client Sypialnia connected
2020-10-27 18:11:14.906043 WARNING AppDaemon: Unknown domain (default/script) in call_service from stream

nothing in the other log files, they have 0666 access rights but maybe should be different?
Also, nothing in ha log. After restarting appdaemon service all work ok again.

Ok, so it has nothing to do with the websocket connection to HA. Looks like a namespace issue. Check out this thread. Unknown domain (default/remote) in call_service

Seems similar but a bit different. I’ve posted my case in that topic. What is strange is that I can call the same script from script widget but not from mode widget. It happens every time after HA is restarted (entire system) and is resolved after restarting appdaemon service.