Yaml question - !include a list of items from another file

Hi :wave::
Having some issue with yaml refactoring, I have a file defines a sub list of elements to be included in picture element card. How can I include this sub-list of items into elements section?
Tried both the syntax with and without - in front of !include but it doesn’t work…
Structure of the main yaml:

…
elements:
   !include other-elements.yaml # this doesn’t work
   - type: state-icon
      ……
   - type: state-label
…

So other-elements looks like

- type: conditional
  ….
- type: state-icon
  …

You cannot merge two lists.
In your particular case, consider another way:

type: p-e
image: …
elements:
  - some mandatory element
  - some mandatory element
  - type: conditional
    … condition must be always true
    elements: !include bla bla bla
1 Like

Wow that’s really smart trick thanks a lot and definitely going to try it out!

Then please respond here if it works, I think it should, at least it works like this in some my setup.

I just need to find something that always returns true without introducing even more helpers…

Create a template binary sensor which is ON, not a big deal.

1 Like

Would like to confirm this approach works - I used the up time sensor and make sure the value is not empty :slight_smile:
Now I need to rethink how to organize all my elements. Now they’re in various list files but now I can even have a map where I can define a template to avoid the annoying warnings of dup keys

An empty and condition is always true. (An empty or condition is always false.)

Hi @Ildar_Gabdullin :
I’m sorry to bother you again, and I was too quick to conclude this workaround works.
To some extend yes it allows me to merge lists defined in several yamls, but it looks like card-mod styling is now broken.
I attach below the working version of floor-plan.yaml:

type: picture-elements
image: /local/floorplan/transparent.png?version=F00CBEDA34B4711C8F5B7C8057BAB745
elements: !include_dir_merge_list floor-plan/
card_mod:
  style: |
    ha-card {
      max-width: 1200px;
      height: 100%;  
      margin: auto;
    }

When I convert this to the below (only include 2 yamls), simple card-mod styling inside the thermostats.yaml doesn’t work:

type: picture-elements
image: /local/floorplan/transparent.png?version=F00CBEDA34B4711C8F5B7C8057BAB745
elements: 
  - type: conditional
    conditions:
      - entity: sensor.ha_uptime
        state_not: ""
    elements: !include floor-plan/_renders.yaml
  - type: conditional
    conditions:
      - entity: sensor.ha_uptime
        state_not: ""
    elements: !include floor-plan/thermostats.yaml
card_mod:
  style: |
    ha-card {
      max-width: 1200px;
      height: 100%;  
      margin: auto;
    }

The thermostats.yaml is like below:

- &thermostat_base
  type: state-label
  entity: climate.bathroom_thermostat
  title: Bathroom Thermostat
  attribute: current_temperature
  suffix: "°C"
  style: &thermostat_style
    border-radius: 20px
    text-align: center
    background-color: rgba(255,255,255,0.1)
    backdrop-filter: blur(1px)
    opacity: 100%
    font-weight: bold
    font-size: 13px
    top: 27%
    left: 32.5%
  card_mod:
    style: |
      :host {
        color:
          {% if state_attr(config.entity, 'hvac_action') == 'heating' %}
            #ffc108;
          {% else %}
            #45729e;
          {% endif %}
      }
  tap_action:
    action: more-info
  double_tap_action:
    action: none
  hold_action:
    action: more-info

# 2️⃣ Remaining thermostats inherit base, override entity, title, and position
- <<: *thermostat_base
  entity: climate.bedroom_closet_thermostat
  title: Bedroom Closet Thermostat
  style:
    <<: *thermostat_style
    top: 23.5%
    left: 71%

- <<: *thermostat_base
  entity: climate.bedroom_thermostat
  title: Bedroom Thermostat
  style:
    <<: *thermostat_style
    top: 27%
    left: 54.6%
...........

In the past I recall I had issue applying card-mod instead a conditional element, this could be a similar issue. Maybe something to do with the code below but I have no idea where and how to modify:

  card_mod:
    style: |
      :host {
        color:
          {% if state_attr(config.entity, 'hvac_action') == 'heating' %}
            #ffc108;
          {% else %}
            #45729e;
          {% endif %}
      }

I feel that I’m last meter to the finish line so really appreciate if you could give me a hand!

Reading the official document it mentions below:

NOTE: card-mod only works on cards that contain a ha-card element. This includes almost every card which can be seen, but not e.g. conditional, entity_filter, vertical-stack, horizontal-stack, grid.

Note, though that those cards often include other cards, which card-mod can work on.
See the manual for each card to see how to specify parameters for the included card(s).

There are also some posts suggesting card-mod doesn’t always work well with conditional, but here I’m applying it directly to the element instead conditional so not sure what’s missed…

Hi the conditional element in picture-element card is very limited, it only allows to choose simple state is or is not “XXXX”. Can’t do more complex logic there

Check without card-mod, here card-mod is absolutely unrelated to the initial task.
Do not mix several unrelated issues in one thread.
All card%mod related questions should be asked in the main card-mod thread. The fantastic post in card-mod thread contains tutorial for many cases including conditional elements inside picture elements card.

Yes it works to merge the lists - the only thing doesn’t work is styling for all thermostats. I think something to do with conditional element but not sure

It is supported.

What I suggest you to do:

  1. Do not mix several unrelated questions in one thread.
  2. Once you got an answer with a solution, mark it as a solution to tell other users what is an exact solution. Note that posts like “Thank you” or “your solution works” should not be marked as a solution))).
  3. Additional discussion for the same topic can be continued in the same thread (even if it is solved), not needed to create a new thread if this is the same or very close question.
  4. Card-mod questions - in the main card-mod thread, and always check fantastic post before asking.

Thanks mark the solution now, however not sure if the issue is related to the merge list solution or styling of conditional element. I have read your post about styling conditional element, it applies to all elements under conditional, but here I need to style each individual element (as config.entity is different). Should I post this to the card-mod thread?

Conditional sub elements should be styled from the conditional element level. Yes please, post in the main card-mod thread.
But may be there is no need for it - it is described in the fantastic post.

1 Like

Thanks I saw your post on conditional element with 3 alternatives. However all the examples are based on styling all elements - in my case it is true that all thermostats should be styled in the same way, however the card-mod template uses config.entity which doesn’t exist for conditional element.

And you also created a separate thread for that card mod question, I answered there, please mark it as solved. Usually it should be done whenever the task is really solved (and you can unmark it anytime if needed or you got doubts).

1 Like

It does, use “config.elemets[some index].entity instead.

1 Like

Ok I think I will post my question in the main card-mod thread as I’m not sure how in styling I can find the index of the element, or maybe it’s a no go for the goal that I want to achieve…