custom-cards / decluttering-card

🧹 Declutter your lovelace configuration with the help of this card
MIT License
386 stars 30 forks source link

Using !Include to templates in .yaml #57

Open OscarGonz95 opened 1 year ago

OscarGonz95 commented 1 year ago

Hello,

My decluttering templates are taking too much code lines and im looking to split my code in different .yaml files.

For now im didnt find any solution on the old posts, so it is possible to use !include my_template.yaml???

I would appreciate some help!

Thanks

ildar170975 commented 1 year ago

As an example:

configuration.yaml:

homeassistant:
  ...
  allowlist_external_dirs:
    ...
    - /config/lovelace
...
lovelace: !include lovelace/lovelace.yaml

lovelace/lovelace.yaml:

mode: storage
dashboards:
  ...
  system:
    mode: yaml
    title: System
    icon: mdi:home-assistant
    show_in_sidebar: true
    require_admin: false
    filename: lovelace/lovelace-system.yaml

lovelace/lovelace-system.yaml:

decluttering_templates: !include_dir_merge_named templates-decluttering/
views:
  - !include views/system/general.yaml
  ...

Folder lovelace/templates-decluttering contains files (may be grouped in folders) for decluttering templates - either "1 file = 1 template" or "1 file = several related templates":

..
template_1.yaml
template_2.yaml

lovelace/templates-decluttering/template_1.yaml:

template_1:
  default:
    ...
  card:
    ...

So, each dashboard file (like "lovelace-system.yaml") should include that decluttering_templates: !include_dir_merge_named templates-decluttering/ string to have your templates available.

OscarGonz95 commented 1 year ago

I'm getting some issues following your steps. Copy everything and creating the folder + lovelace.yaml. On lovelace-system.yaml I did just for test a fast view instead of import. image

decluttering_templates: !include_dir_merge_named templates-decluttering/
views:
  - title: Test
    cards:
      - type: picture
        image: https://demo.home-assistant.io/stub_config/t-shirt-promo.png
        tap_action:
          action: none
        hold_action:
          action: none

Deleting thse"..." from your example code. I try to validate the config and i get this issue:

"Invalid config for [lovelace]: Url path needs to contain a hyphen (-) for dictionary value @ data['lovelace']['dashboards']. Got OrderedDict([('system', OrderedDict([('mode', 'yaml'), ('title', 'System'), ('icon', 'mdi:home-assistant'), ('show_in_sidebar', True), ('require_admin', False), ('filename', 'lovelace/lovelace-system.yaml')]))]). (See /config/configuration.yaml, line 67)."

Maybe a mistake on the !import

lovelace: !include lovelace/lovelace.yaml

to

lovelace: !include /lovelace/lovelace.yaml

But anyways i had error:

Error loading /config/configuration.yaml: in "/config/configuration.yaml", line 68, column 11: Unable to read file /lovelace/lovelace.yaml.

Thanks for your help!

ildar170975 commented 1 year ago

Check again steps in my post and compare with your setup. If you still experience errors - then post your "lovelace.yaml", "lovelace-system.yaml" & "configuration.yaml" files.

BTW, your issue is neither a bug nor a feature request. It is just a question. I strongly suggest you to ask similar questions in a dedicated decluttering-card Community thread. These questions should be posted there instead if being lost on Github.