Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using !Include to templates in .yaml #57

Open
OscarGonz95 opened this issue Dec 6, 2022 · 3 comments
Open

Using !Include to templates in .yaml #57

OscarGonz95 opened this issue Dec 6, 2022 · 3 comments

Comments

@OscarGonz95
Copy link

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
Copy link

ildar170975 commented Dec 6, 2022

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
Copy link
Author

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
Copy link

ildar170975 commented Dec 6, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants