Lovelace: A method of splitting the configuration into several files

I followed the installation instructions step by step but now I have the following problem:
python 3 is required but I dont know how to install it on my machine.
I use hass.io on a tinker board and I am currently using the IDE addon.

There’s a special section in the readme for usage on hass.io. Home Assistant itself runs on python3 so it’s definitely available, but a bit harder to get at in hass.io since it’s inside a container.

How would someone run this who is using docker for running HA? Is it the same procedure as for hassio?

And just to clarify my understanding of this if I decide to go this route instead of the standard !include statements…

in the lovelace directory (that I created in my config folder) I would create a main.yaml file with the similar structure as the existing ui-lovelace.yaml file but I use !include statements pointing to other files that will get compiled into the new ui-lovelace.yaml file when i run the generator command?

is there any benefit to running this compared to using the current built-in !include functionality?

It would be the same procedure as for hass.io, yes. I use that myself, running Home Assistant in docker.

Your understanding of the procedure is correct.

The main benefit isn’t really the include function anymore, since it’s been decided that functionality will stay in core indefinitely. Instead, I’d say the main benefits are the jinja templating and the !file statement.

In short, lovelace-gen isn’t as useful as it seemed it would become. Which is great!

1 Like

Also, see this topic for more recent updates and discussion.

Hi. Trying to get lovelace-gen up and running but i keep getting the following error with python3



What am i doing wrong?

You’re using a version of python 3 (3.5) that’s more than two years old. However, that version is supported by Home Assistant, so I should change lovelace-gen to work with it as well… Expect an update in the next few days.

Thanks. :slight_smile:

It’s updated now. The new version should work in python 3.5.3.

Hi @thomasloven

I’ve added

anchors:
  mystyle: &mystyle
    card:
       ....styling....

to one of my includes but after generation in ui-lovelace.yaml there is only

anchors:
  mystyle:
    card:
       ....styling....

left. I’ve got generation errors, I thought because the reference (&mystyle) is missing.

Example reference:

- type: custom:button-card
  entitiy: switch.dummy
  styles:
      <<: *mystyle

If I add the parts to ui-lovelace.yaml manually it works like a charm.

Is it possible to use anchors with the generation script?

Only in the same file, unfortunately.

I cant seem to get this working, the script complains about not finding floorplan.yaml even though it is in the lovelace directory. What can I be doing wrong?

bash-5.0# python3 lovelace-gen.py
Processing of yaml failed.
floorplan.yaml {"no_other":"true"}
Traceback (most recent call last):
  File "lovelace-gen.py", line 82, in <module>
    main()
  File "lovelace-gen.py", line 68, in main
    raise e
  File "lovelace-gen.py", line 64, in main
    data = process_file(MAIN_FILE)
  File "lovelace-gen.py", line 35, in process_file
    return yaml.load(template.render()+ '\n')
  File "/usr/local/lib/python3.7/site-packages/ruamel/yaml/main.py", line 331, in load
    return constructor.get_single_data()
  File "/usr/local/lib/python3.7/site-packages/ruamel/yaml/constructor.py", line 111, in get_single_data
    return self.construct_document(node)
  File "/usr/local/lib/python3.7/site-packages/ruamel/yaml/constructor.py", line 121, in construct_document
    for _dummy in generator:
  File "/usr/local/lib/python3.7/site-packages/ruamel/yaml/constructor.py", line 1553, in construct_yaml_map
    self.construct_mapping(node, data, deep=True)
  File "/usr/local/lib/python3.7/site-packages/ruamel/yaml/constructor.py", line 1458, in construct_mapping
    value = self.construct_object(value_node, deep=deep)
  File "/usr/local/lib/python3.7/site-packages/ruamel/yaml/constructor.py", line 174, in construct_object
    for _dummy in generator:
  File "/usr/local/lib/python3.7/site-packages/ruamel/yaml/constructor.py", line 1545, in construct_yaml_seq
    data.extend(self.construct_rt_sequence(node, data))
  File "/usr/local/lib/python3.7/site-packages/ruamel/yaml/constructor.py", line 1304, in construct_rt_sequence
    ret_val.append(self.construct_object(child, deep=deep))
  File "/usr/local/lib/python3.7/site-packages/ruamel/yaml/constructor.py", line 167, in construct_object
    data = constructor(self, node)
  File "lovelace-gen.py", line 38, in include_statement
    return process_file(node.value)
  File "lovelace-gen.py", line 35, in process_file
    return yaml.load(template.render()+ '\n')
  File "/usr/local/lib/python3.7/site-packages/ruamel/yaml/main.py", line 331, in load
    return constructor.get_single_data()
  File "/usr/local/lib/python3.7/site-packages/ruamel/yaml/constructor.py", line 111, in get_single_data
    return self.construct_document(node)
  File "/usr/local/lib/python3.7/site-packages/ruamel/yaml/constructor.py", line 121, in construct_document
    for _dummy in generator:
  File "/usr/local/lib/python3.7/site-packages/ruamel/yaml/constructor.py", line 1553, in construct_yaml_map
    self.construct_mapping(node, data, deep=True)
  File "/usr/local/lib/python3.7/site-packages/ruamel/yaml/constructor.py", line 1458, in construct_mapping
    value = self.construct_object(value_node, deep=deep)
  File "/usr/local/lib/python3.7/site-packages/ruamel/yaml/constructor.py", line 174, in construct_object
    for _dummy in generator:
  File "/usr/local/lib/python3.7/site-packages/ruamel/yaml/constructor.py", line 1545, in construct_yaml_seq
    data.extend(self.construct_rt_sequence(node, data))
  File "/usr/local/lib/python3.7/site-packages/ruamel/yaml/constructor.py", line 1304, in construct_rt_sequence
    ret_val.append(self.construct_object(child, deep=deep))
  File "/usr/local/lib/python3.7/site-packages/ruamel/yaml/constructor.py", line 167, in construct_object
    data = constructor(self, node)
  File "lovelace-gen.py", line 38, in include_statement
    return process_file(node.value)
  File "lovelace-gen.py", line 31, in process_file
    template = jinja.get_template(path)
  File "/usr/local/lib/python3.7/site-packages/jinja2/environment.py", line 830, in get_template
    return self._load_template(name, self.make_globals(globals))
  File "/usr/local/lib/python3.7/site-packages/jinja2/environment.py", line 804, in _load_template
    template = self.loader.load(self, name, globals)
  File "/usr/local/lib/python3.7/site-packages/jinja2/loaders.py", line 113, in load
    source, filename, uptodate = self.get_source(environment, name)
  File "/usr/local/lib/python3.7/site-packages/jinja2/loaders.py", line 187, in get_source
    raise TemplateNotFound(template)
jinja2.exceptions.TemplateNotFound: floorplan.yaml {"no_other":"true"}

lovelace-gen has been replaced with lovelace_gen (sorry about the confusing name), which is much better and easier to use: 🔹 Lovelace_gen - Add abilities to ui_lovelace.yaml

Thanks! But I tried also this version but seems that I cant take control over the Lovelace UI with lovelace: mode: yaml in my config. Then I only get “Saving failed: Not supported”. If I remove this I can get control. Also I don’t have the “Refresh” option in my dashboard, perhaps due to the same reason?

That’s correct. With mode: yaml you cannot use the gui editor. https://www.home-assistant.io/lovelace/yaml-mode/