Simple YAML syntax question: includes, indentation

This seems simple but I can’t figure out the magic spacing (or something).

I have this sort of card repeated throughout many dashboards (now in yaml files not storage):

  - type: grid
    cards:
      - type: custom:auto-entities
        card:
          type: entities
          title: Cameras
        filter:
          include:
            - device: BlueIris*
          exclude:
            - entity_id: '*update'
            - entity_id: '*signal*'
            - entity_id: '*ble_strength*'
            - entity_id: '*rebooted'
            - entity_id: '*reboot'
            - entity_id: '*battery_level'
            - entity_id: '*last_seen'
            - domain: automation
            - hidden_by: user
            - hidden_by: integration
        sort:
          method: name
          ignore_case: true
        grid_options:
          columns: full

I wanted to take the excludes and put them in a file, so I created this file (ui-common-excludes.yaml):

- entity_id: '*update'
- entity_id: '*signal*'
- entity_id: '*ble_strength*'
- entity_id: '*rebooted'
- entity_id: '*reboot'
- entity_id: '*battery_level'
- entity_id: '*last_seen'
- domain: automation
- hidden_by: user
- hidden_by: integration

The hyphens are in the first column. Then I did this:

  - type: grid
    cards:
      - type: custom:auto-entities
        card:
          type: entities
          title: Cameras
        filter:
          include:
            - device: BlueIris*
          exclude: !include ui-common-excludes.yaml
        sort:
          method: name
          ignore_case: true
        grid_options:
          columns: full

And that all works fine. But suppose I also want to exclude something additional in one only, e.g. maybe a “domain: light”. I can’t seem to find a place to put it, e.g.

  - type: grid
    cards:
      - type: custom:auto-entities
        card:
          type: entities
          title: Cameras
        filter:
          include:
            - device: BlueIris*
          exclude: !include ui-common-excludes.yaml
            - domain: light 
        sort:
          method: name
          ignore_case: true
        grid_options:
          columns: full

All variations of these complain about bad indentation. I’ve tried repositioning the include on the next line, changing indentation in the file, no luck so far.

Is there some way I can see the actual resulting yaml after doing the include, so I can judge what’s wrong with it?

And/or is there a way to do what I’m trying?

Linwood

I get contradicting search results on this.
I will have to test first. :slight_smile:

You cannot merge two “include” lists.
Wait, let’s test that " !include_dir_merge_list" option.
No, false alarm.
So, again - You cannot merge two “include” lists ))

It seems to be possible to use !include_dir_merge_list, but it will be a bit confusing.
include_dir_merge_list does include all files in the directory, but also files subdirectories and you can also insert yaml files in that directory and those subdirectories that include other files outside the directory.

Am confused by the second last and last. I’m not trying to merge two include lists, at least I do not think so. I’m trying to combine an include list with manually entered items. It doesn’t seem happy with the indentation of the manual items.

I’m basically just trying to replace a piece of code used repetitively, notably so I can change it in one place rather than 50 places if I add another exclude to it.

I apologize if I’m misinterpreting the answers in that regard, but I can’t connect the idea of a merge list (with there’s only one include).

Do you mean that I’m using the include in multiple places? It seems perfectly happy with that, I used it in more than one place in the same file, and didn’t hit a problem until I needed to supplement it with some additional items.

I just imagined that a user then will have to use SEVERAL “include” subdirectories for different sets of filters…

OK:

xxx: !include file.yaml

where file.yaml:

- xxx: xxx
  xxx: xxx
- xxx: xxx
  xxx: xxx
- xxx: xxx
  xxx: xxx

also OK:

xxx:
  - xxx: xxx
    xxx: xxx
  - !include file.yaml

where file.yaml:

xxx: xxx
xxx: xxx

The problem is that once you include a list (without the - in front), then you can not add items (with the - in front) any longer.
The trick with include_dir_merge_list is that it can combine the files in a directory and those files can contain an include list each.

Yeah, as I said it is confusing to use it that way.

Maybe YAML anchors can solve it. I have only skimmed the concept, because I decided to go with Lovelace_gen instead to get full dynamic solution.

Not sure.
Anchors are for dictionaries, you can merge dictionaries by “<<: *anchor”, not lists.

Actually this got me there, I just needed to rearrange the order and add a dash:

 - type: grid
    cards:
      - type: custom:auto-entities
        card:
          type: entities
          title: Cameras
        filter:
          include:
            - device: BlueIris*
          exclude: 
            - domain: light 
            - !include ui-common-excludes.yaml
        sort:
          method: name
          ignore_case: true
        grid_options:
          columns: full

I can put my additional excludes in front of the include of the file and it appears to work.

Thank you thank you. I’m sorry I still don’t get the relevance of the include merged, but this works fine.

I’m still curious though – is there a way, much like a pragma on the C compiler expanding includes and macros… that you can see how an include gets built? What the effect of it is, including spacing, etc?

Really?) Are you sure?
Seems my time was wasted.

Am I sure it works? I just did some more testing, and it seems to.

I apologize if the way I asked the question sent you down a different path.

The thing is that this code

is wrong.
You can change it to “include” & see yourself.
And you was too quick with a “solution mark” since your question has no solution. I repeat - you cannot merge lists.

Could you please elaborate on how it is wrong, since it is working in practice?

I’ve gone through one complete dashboard putting in many of these and all appear to be working.

Here is a card with a literal cut and paste (the one above I modified in the editor here):

      - type: grid
        cards:
          - type: custom:auto-entities
            card:
              type: entities
              title: Front Porch (other)
            filter:
              include:
                - area: Front Porch
              exclude:
                - domain: light
                - domain: sensor
                - domain: binary_sensor
                - domain: fan
                - domain: switch
                - !include ui-common-excludes.yaml
            sort:
              method: name
              ignore_case: true

Here’s the include (in moving around I added two spaces before each dash):

  - entity_id: '*update'
  - entity_id: '*signal*'
  - entity_id: '*ble_strength*'
  - entity_id: '*rebooted'
  - entity_id: '*reboot'
  - entity_id: '*battery_level'
  - entity_id: '*last_seen'
  - domain: automation
  - hidden_by: user
  - hidden_by: integration

I’m perfectly willing to believe I have made a mistake since this is primarily just trial and error but…

it works?

What is the error?

Hmmm… maybe you have a point. The syntax is not giving an error but I am getting some inconsistent results. Let me experiment further.

The problem can be easier demonstrated with “include” filter.
Create this file “xxx.yaml”:

- domain: camera

Then this card:

      - type: custom:auto-entities
        card:
          type: entities
        show_empty: false
        filter:
          include:
            - entity_id: zone.home
            - domain: camera

Which creates this:
image

Then test this card:

      - type: custom:auto-entities
        card:
          type: entities
        show_empty: false
        filter:
          include:
            - entity_id: zone.home
            - !include xxx.yaml

image

The resulted file is

          include:
            - entity_id: zone.home
            - - domain: camera

i.e. list inside a list as an element.
With a more complex example it will be

          include:
            - entity_id: zone.home
            - - domain: camera
              - domain: zone

You may not see this with “exclude”.

What you are trying to achieve MAY BE (need to test) possible with a “template” filter & decluttering card.
Assume your auto-entities list has some default “exclude” list - then with an input variable you may define an additional exclude.
Could be complex & cumbersome - but a good educational example.

This is very strange. You are correct – it doesn’t work. It does pass syntax, but it does not exclude all the things in the list.

What I cannot understand is it excludes SOME of the things in the list.

You show an example of “the resulted file is”… do you just know it does that? Or is there a way to see that result? The blind attempts are what is giving me fits.

But you are correct, it is not giving the right answer, even though it is no longer giving syntax errors.