jimz011 / homekit-infused

Homekit Infused 5 2023
https://jimz011.github.io/homekit-infused/
Other
868 stars 138 forks source link

Error in HA, Frontend gets stuck #195

Closed Qpernicus closed 1 year ago

Qpernicus commented 1 year ago

Ok, so my frontend gets unresponsive since installing and using HKI. Although i have no direct cause for this, it just seems to get itself stuck (black screen, no buttons). But since installing HKI i also get this in my log quite frequently:

Logger: homeassistant.components.websocket_api.http.connection
Source: hki-base/base.yaml:4
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 19:16:12 (1 occurrences)
Last logged: 19:16:12

[139790127855072] Error handling message: Unknown error (unknown_error) from 192.168.178.92 (Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 27, in _handle_async_response
    await func(hass, connection, msg)
  File "/usr/src/homeassistant/homeassistant/components/lovelace/websocket.py", line 38, in send_with_error_handling
    result = await func(hass, connection, msg, config)
  File "/usr/src/homeassistant/homeassistant/components/lovelace/websocket.py", line 86, in websocket_lovelace_config
    return await config.async_load(msg["force"])
  File "/usr/src/homeassistant/homeassistant/components/lovelace/dashboard.py", line 186, in async_load
    is_updated, config = await self.hass.async_add_executor_job(
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/lovelace/dashboard.py", line 205, in _load_config
    config = load_yaml(self.path, Secrets(Path(self.hass.config.config_dir)))
  File "/usr/src/homeassistant/homeassistant/util/yaml/loader.py", line 155, in load_yaml
    return parse_yaml(conf_file, secrets)
  File "/usr/src/homeassistant/homeassistant/util/yaml/loader.py", line 168, in parse_yaml
    return _parse_yaml(SafeLoader, content, secrets)
  File "/usr/src/homeassistant/homeassistant/util/yaml/loader.py", line 198, in _parse_yaml
    yaml.load(content, Loader=lambda stream: loader(stream, secrets))
  File "/usr/local/lib/python3.10/site-packages/yaml/__init__.py", line 81, in load
    return loader.get_single_data()
  File "/usr/local/lib/python3.10/site-packages/yaml/constructor.py", line 51, in get_single_data
    return self.construct_document(node)
  File "/usr/local/lib/python3.10/site-packages/yaml/constructor.py", line 55, in construct_document
    data = self.construct_object(node)
  File "/usr/local/lib/python3.10/site-packages/yaml/constructor.py", line 100, in construct_object
    data = constructor(self, node)
  File "/usr/src/homeassistant/homeassistant/util/yaml/loader.py", line 325, in _ordered_dict
    nodes = loader.construct_pairs(node)
  File "/usr/local/lib/python3.10/site-packages/yaml/constructor.py", line 155, in construct_pairs
    value = self.construct_object(value_node, deep=deep)
  File "/usr/local/lib/python3.10/site-packages/yaml/constructor.py", line 100, in construct_object
    data = constructor(self, node)
  File "/usr/src/homeassistant/homeassistant/util/yaml/loader.py", line 246, in _include_yaml
    return _add_reference(load_yaml(fname, loader.secrets), loader, node)
  File "/config/custom_components/lovelace_gen/__init__.py", line 32, in load_yaml
    stream = io.StringIO(jinja.get_template(fname).render({**args, "_global": llgen_config}))
  File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 1301, in render
    self.environment.handle_exception()
  File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 936, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "/config/hki-base/base.yaml", line 4, in top-level template code
    {% for name, data in _global.views.items() %}
  File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 485, in getattr
    return getattr(obj, attribute)
jinja2.exceptions.UndefinedError: 'dict object' has no attribute 'views'

So my assumption is: The error in HKI Base causes the system to loop itself into destruction. Only thing i changed in the last 10 days is using HKI, only time i have these hiccups is the last 10 days. Not scientific i know.

jimz011 commented 1 year ago

sounds to me like you also have DD installed. you will have to make sure that you follow some steps to make both dashboards work since they both use a component (lovelace_gen) which can only be used once.

Qpernicus commented 1 year ago

I had that installed, but uninstalled, only left the config-yamls, but no lovelace_gen there.. as far as i can see.

Qpernicus commented 1 year ago

I removed the dwains files just in case..

Qpernicus commented 1 year ago

I might be mistaken but after reboot, it still gives the error...or its from just BEFORE reboot

jimz011 commented 1 year ago

You should clear the logs first and then reboot, but now we are on the subject,

Do you have the DD component installed? Dwains Dash uses a modified lovelace_gen, they are named differently, but they are conflicting.

Your error states that it can not find the dictionary object views:, which is a required dictionary object for HKI. If you have installed HKI with lovelace_gen and don't use any other dashboard with that, then it should work without a problem. If you have DD installed you already have lovelace_gen and you must uninstall lovelace_gen from HKI as well as the need for commenting out line 1 in /packages/homekit-infused/hki_configuration.yaml, you will have to do this commenting out of line 1 every time you update HKI.

Last thing I can think of is that you have removed line 1 in /hki-user/config/views.yaml which should have the value views:, if that is the case then it will also fail to find the views value.

One more thing, I have no idea about any compatibility with other dashboards that use some form of lovelace_gen (maybe minimalist ui for example). For now the only officially supported dashboards by HKI are the default HA storage dashboards, custom YAML dashboards, energy dashboards and Dwains dashboard. If you happen to have uninstalled DD completely, this will also mean that you don't have lovelace_gen anymore (and you will need to install that and uncomment the line in the config file). If you did disable DD and still have it installed it will probably still load the DD component and thus you will have to do the opposite by not using lovelace_gen.

I will give you a tip on reading errors, usually the actual error is displayed somewhere in the last 10 lines, in this case:

  File "/config/hki-base/base.yaml", line 4, in top-level template code
    {% for name, data in _global.views.items() %}
  File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 485, in getattr
    return getattr(obj, attribute)
jinja2e.exceptions.UndefinedError: 'dict object' has no attribute 'views'

The last line explains what the error is, in this case it means that it can simply not find the dictionary object named views (which is defined in /hki-user/config/views.yaml on line 1).

EDIT: You could share the first few lines of your views.yaml file if you want me to take a look at it (if you use any split file configuration, please also share the first few lines of any of your views.

Qpernicus commented 1 year ago

Views.yaml:

views: !include_dir_merge_named ../views

jimz011 commented 1 year ago

if you use any split file configuration, please also share the first few lines of any of your views.

Qpernicus commented 1 year ago

I split up the whole config, or do you mean HKI specific?

My views are split up like yours mainly. Zo above in views.yaml, and this in de folder views:

# Home
home:
  title: greeting

But my whole config is more like this:

configuration.yaml:

homeassistant: !include_dir_merge_named /config/includes/home_assistant

in that folder, customize.yaml, auth_mfa and packages.yaml. In packages.yaml:

packages: !include_dir_named /config/includes/integrations

In that folder a folder include with all the different stuff you normally find in configuration.yaml and a folder packages with your hki packages folder (i adjusted the '!Includes' accordingly)..

And my config splits like that

Qpernicus commented 1 year ago

I'm leaning towards saying this is fixed

A couple of days ago I reinstalled lovelace_gen after removing the dwain files. Since then I didn't see the error (although I didn't reboot often) and my GUI didn't hang

jimz011 commented 1 year ago

@Qpernicus my apologies for not replying sooner, I have looked into your issue, but it is very hard to debug something like this when the default options are changed (in your case paths to specific folders and such).

But your last message sounds good, it should work properly when the files are found. If you don't get the error then I assume it is working correctly now (you could try restarting a couple of times just to be sure).

Qpernicus commented 1 year ago

Mmmmm annoyingly it's still there intermittently. Ran out of resources to troubleshoot

jimz011 commented 1 year ago

I have read your messages, but honestly I wouldn't really know how to help you without knowing exactly what you have installed (other than HKI), how you have set your HA up as you have mentioned that you have split everything up into separate parts.

HKI was written in such a way that it works fine when a default install was done. But since your install is everything but default, I would have to check out everything.

If you join me on discord we might be able to find some solution to this (either by doing streams or remote desktop or something like that).

Qpernicus commented 1 year ago

Hi. Sorry I forgot to reply here. Decided to leave HKI for now. I wasn't will to go all-in on HKI, and the troubles stayed so I removed everything into a backup folder for perhaps a later day.