Split dashboard yaml

Hi,

I develop my dashboard with Yaml. I try to split my code to organize and to make it more readable.

My code is as below:

- title: "Home"
  path: "home"
  cards:
    
    #!include "home/person.yaml"
    #!include "home/welcome.yaml"
    !include "home/room_menu.yaml" 
    !include "home/scenes.yaml"

When I add one include it works well.

What is the syntax to use a second !include?

image

That looks correct to me.

Have you actually tried it and it doesn’t work or are you just relying on the error being thrown in the editor?

I tried but I have an error:

while parsing a block mapping in “/config/ui_lovelace_minimalist/dashboard/views/home.yaml”, line 1, column 3 expected , but found ‘’ in “/config/ui_lovelace_minimalist/dashboard/views/home.yaml”, line 5, column 5

Please post the code you’re trying to include, aka “home.yaml”. :slight_smile:

We can’t see what you’re trying to include, and the error states, there is something wrong in this file. :slight_smile:

Not directly related to solving your issue. Since you are developing dashboards in YAML mode, consider adding lovelace_gen in, it provides additional techniques for composing displays.

ui-lovelace.yaml

---
button_card_templates: !include_dir_merge_named "../../custom_components/ui_lovelace_minimalist/__ui_minimalist__/ulm_templates/"

title: "Home"
theme: "minimalist-desktop"
background: "var(--background-image)"
views:
  !include "views/home.yaml"

views/home.yaml where I have the issue

- title: "Home"
  path: "home"
  cards:
    !include "home/person.yaml"
    !include "home/welcome.yaml"
    #!include "home/room_menu.yaml" 
    #!include "home/scenes.yaml"
              

views/home/person.yaml

- type: 'custom:button-card'
  template: card_person
  entity: person.passy
  variables:
    ulm_card_person_entity: person.passy
    ulm_card_person_use_entity_picture: true
    ulm_card_person_icon: mdi:face-man
    ulm_card_person_battery: sensor.android_battery_level

views/home/wecome.yaml

- type: "custom:button-card"
  template: "card_esh_welcome"
  triggers_update: "input_boolean.collapse_welcome"
  variables:
    ulm_card_esh_welcome_collapse: input_boolean.collapse_welcome
    ulm_weather: "weather.lyon"
    entity_1:
      nav: "house"
      icon: "mdi:home"
      name: "Passy"
      color: "blue"
    entity_2:
      nav: "lights"
      icon: "mdi:lightbulb"
      name: "Lumières"
      color: "yellow"
    entity_3:
      nav: "security"
      icon: "mdi:shield"
      name: Sécurité
      color: "green"
    entity_4:
      nav: "network"
      icon: "mdi:nas"
      name: Lab
      color: "purple"
    entity_5:
      nav: "network"
      icon: "mdi:flask"
      name: Lab
      color: "red"

First, please remove the quotation marks around the file paths.

Eg. this

views:
  !include "views/home.yaml"

should be

views:
  !include views/home.yaml

Same for the other includes. :slight_smile:

I personally prefer to use a dash in front of menus, makes it better readable for me (EDIT: this is optional!):

cards:
  - !include home/person.yaml
  - !include home/welcome.yaml

No, your problem is in the home/scenes.yaml file, which you have not yet posted.

I don’t think that’s correct. My !includes are all enclosed in quotes. Tho they are single quotes but I don’t think it matters as long as it’s consistent.

views:
  - !include '/config/lovelace_views/lovelace_main_view.yaml'
  - !include '/config/lovelace_views/lovelace_octoprint_view.yaml'
  - !include '/config/lovelace_views/lovelace_smoker_view.yaml'
.
.

That might be the problem tho. Mine have dashes.

To the OP…

add dashes to the views/home.yaml contents:

- title: "Home"
  path: "home"
  cards:
    - !include "home/person.yaml"
    - !include "home/welcome.yaml"

in yaml dashboards alol the cards need to start with a dash so each !include should have a dash in front of it since it’s effectively a card.

but then you need to remove the dash in front of the card i the sub nests since the !includes already contain the dashes. Otherwise the yaml interpreter sees two dashes in a row.

views/home/person.yaml:

  type: 'custom:button-card'
  template: card_person
  entity: person.passy
  variables:
    ulm_card_person_entity: person.passy
    ulm_card_person_use_entity_picture: true
    ulm_card_person_icon: mdi:face-man
    ulm_card_person_battery: sensor.android_battery_level

I’m not real sure I see the benefit of having nested includes unless you are using the same cards in several places. Otherwise it gets confising as we see here.

Thanks for your answers so some news:

If I use this code:

title: "Home"
path: "home"
cards:
  - !include "home/person.yaml"
  - !include "home/welcome.yaml"

It only shows the first file. The second is ignored

With this code:

- title: "Home"
  path: "home"
  cards:
    - !include "home/person.yaml"
    - !include "home/welcome.yaml"

I have the error No Card type configured

title: "Home"
path: "home"
cards:
  !include home/person.yaml
  !include home/welcome.yaml

I have the error

in “/config/ui_lovelace_minimalist/dashboard/views/home.yaml”, line 4, column 3: Unable to read file /config/ui_lovelace_minimalist/dashboard/views/home/person.yaml !include home/welcome.yaml.

I can’t see how to sort it out

Any ideas or erros I am writing?
This error:
in “/config/ui_lovelace_minimalist/dashboard/views/home.yaml”, line 4, column 3: Unable to read file /config/ui_lovelace_minimalist/dashboard/views/home/person.yaml !include home/welcome.yaml.

That’s the one to go with! :wink: @finity that’s wrong in your example, as “title” isn’t a menu item, it’s first level, so no dash in front. :laughing:

Next step: use that code in that format. It is correct, so we need to see where the error is coming from.

Would you mind and please post your directory structure (with files). We need to see, where the files physically are stored, maybe it’s something with an uncorrect path or something like that. :slight_smile:

So please post:

  • directory structure
  • content of home/welcome.yaml

We’ll get there! :slight_smile:

Thanks.

So directory structure

image

welcome.yaml

- type: "custom:button-card"
  template: "card_esh_welcome"
  triggers_update: "input_boolean.collapse_welcome"
  variables:
    ulm_card_esh_welcome_collapse: input_boolean.collapse_welcome
    ulm_weather: "weather.lyon"
    entity_1:
      nav: "house"
      icon: "mdi:home"
      name: "Passy"
      color: "blue"
    entity_2:
      nav: "lights"
      icon: "mdi:lightbulb"
      name: "Lumières"
      color: "yellow"
    entity_3:
      nav: "security"
      icon: "mdi:shield"
      name: Sécurité
      color: "green"
    entity_4:
      nav: "network"
      icon: "mdi:nas"
      name: Lab
      color: "purple"
    entity_5:
      nav: "network"
      icon: "mdi:flask"
      name: Lab
      color: "red"

But I don’t know why now I have these rerrors. It means it can access and open the files but it can’t find the cards.

Ok I have investigated to better understand.

So in view.yaml

views:
  !include views/home.yaml

views is an array so I should move:

  • !include views/home.yaml to - !include views/home.yaml
    no?

Then in home.yaml

title: "Home"
path: "home"
cards:
  - !include home/person.yaml
  - !include home/welcome.yaml

title and other properties are not an array but part of the file home.yaml

However my include are part of cards so they are items of the array and should have -

Finally, my files are not part of an array and should not start with -

So person.yaml

type: "custom:button-card"
template: custom_card_imswel_person
variables:
  ulm_card_imswel_person_entity: person.passy
  ulm_card_imswel_person_wifi_tracker: device_tracker.android
  ulm_card_imswel_person_gps_tracker: device_tracker.android
  ulm_card_imswel_person_findmy_script: script.find_my_phone
  ulm_card_imswel_person_use_entity_picture: true
  ulm_card_person_battery: sensor.android_battery_level

And now it works perfectly

Available if you need some help but easiuer to clarify the code and reuse some blocks :wink:

yeah I added an extra dash by mistake

That’s one of the reasons, why YAML is so complicated at times… :rofl: I do love it, because it’s good to read (compared to other languages), but it’s really, really picky.

@dalton5
Great you got it working!