Hi all:
For simplicity and reuse as much code as possible across similar UI elements, I have migrated from storage to yaml mode for my main dashboard. For history I have another post and reason why I think yaml works better for my needs:
My file structure is as below:
/config/lovelace/floor-plan.yaml
/config/lovelace/floor-plan/thermostats.yaml
/config/lovelace/anchors.yaml
floor-plan.yaml looks like below - I have all elements in different types defined in floor-plan folder, thermostats.yaml is one of them.
type: picture-elements
image: /local/floorplan/transparent.png
elements: !include_dir_merge_list floor-plan/
card_mod:
style: |
ha-card {
max-width: 1200px;
height: 100%;
margin: auto;
}
I have anchors defined in a separated file with the hope that I can reuse it across different device types:
label_style: &label_style
border-radius: 20px
text-align: center
...
thermostat_label: &thermostat_label
type: state-label
style:
<<: *label_style
...
And thermostats (what I want each thermostat to be based on anchors):
- <<: * thermostat_label
entity: climate.bedroom_closet_thermostat
title: Bedroom Closet Thermostat
style:
<<: * label_style
top: 23.5%
left: 71%
Some limitations that I’m aware of:
- !include_dir_merge_list floor-plan/ merges the flat list from all yamls in the folder, that seems to be the only way to merge list of elements organised from different files (I tried to merge list directly with !include but it creates a nested list.
- Because of above thermostat.yaml has to be a list, and it’s not possible to include anchors from another file which is a map
I have tried many different ways but still can’t make it work fully, below is what I have done so far:
- !include the anchor.yaml in parent floor-plan.yaml - looks like thermostats.yaml need to be resolved before merged into floor-plan.yaml, so doesn’t work
- !include the anchor.yaml in thermostats.yaml directly - anchor.yaml is a map and cause the yaml file invalid and cannot be merged
- Copy the anchors from the shared anchor.yaml into thermostats.yaml and change them to list - sort of works but when merged those anchors are part of the configuration and causes configuration errors
- The closest thing so far: I change the first thermostat with anchors, and reuse code in the following thermostats. No configuration errors however I got tons of warning in log saying overriding attributes (
top,left,entity,title,style) are duplicated keys. And I’m still not very happy with this approach as the anchors are not reusable across files - for example the text style need to repeat for each yaml.
- &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
# Second thermostat inherits the base
- <<: *thermostat_base
entity: climate.bedroom_closet_thermostat
title: Bedroom Closet Thermostat
style:
<<: *thermostat_style
top: 23.5%
left: 71%
My Questions
- Is there a best practice for creating reusable thermostat anchors while avoiding all the cons that I mentioned?
- How do people normally handle many similar elements with common configuration with anchors and !include in HA?