Hi all.
I’m building an irrigation management dashboard
I have to manage multiple irrigation zones and each zone has, in fact, the same schema in the frontend and therefore, in fact, I have the same YAML duplicated several times where only the entities change.
For example, this is a one irrigation zone, i need to replicate this for X zones.
Now, YAML doesn’t have a parameterization, I can’t create a YAML template to pass the entities to use.
I tried with lovelace_gen, but besides looking a bit abandoned, it has limitations with jinja so I abandoned it.
I’m trying with anchors, which, although they don’t allow me to reduce the code -but I still have to duplicate the files- allow me to have a whole part of the configuration at the top of the YAML file.
This above all because, with a view to releasing the code also for other people who want it, personal configuration remains easier in this way.
However, even these seem to have problems with jinja.
For example.
I have this anchors at the top of the yaml file
homeassistant:
entity_list:
e2: &activator "switch.irrigazione_orto"
e2a: &groupZone "group.zone1_onoff"
e2b: &manualDuration "input_number.zone1_manual_duration"
e3: &groupZoneWeek "group.zone1_weeday"
e4: &zoneMon "input_boolean.zone1_monday"
e5: &zoneTue "input_boolean.zone1_tuesday"
e6: &zoneWed "input_boolean.zone1_wednesday"
e7: &zoneThu "input_boolean.zone1_thursday"
e8: &zoneFri "input_boolean.zone1_friday"
e9: &zoneSat "input_boolean.zone1_saturday"
e10: &zoneSun "input_boolean.zone1_sunday"
fascia1: &fascia1 "irrigation_zone1_slot1.yaml"
fascia2: &fascia2 "irrigation_zone1_slot2.yaml"
fascia3: &fascia3 "irrigation_zone1_slot3.yaml"
fascia4: &fascia4 "irrigation_zone1_slot4.yaml"
includeFile1: !include &includeFile1 irrigation_zone1_slot1.yaml
includeFile2: !include &includeFile2 irrigation_zone1_slot2.yaml
includeFile3: !include &includeFile3 irrigation_zone1_slot3.yaml
includeFile4: !include &includeFile4 irrigation_zone1_slot4.yaml
Working fine if I use anchor in entity, name or others
type: custom:button-card
entity: *groupZone
template: irrigation_zone
name: *zone
icon: mdi:checkbox-blank-outline
But, if I use in the code below, they rightly don’t work.
type: custom:mushroom-template-card
icon: |
{% if is_state ('*activator', 'on') %}
mdi:stop-circle-outline
{% else %}
mdi:play-circle-outline
{% endif %}
entity: *activator
icon_color: |
{% if is_state ('*activator', 'on') %}
#cb3235
{% elif is_state ('*activator ', 'off') %}
#50c878
{% else %}
grey
{% endif %}
I tried different solution but without success.
The same problem is also on this:
type: custom:button-card
template: settings
styles:
card:
- background-color: |
[[[
if (states['*activator'].state == 'off') return 'transparent';
else return 'rgb(80, 200, 120, 0.2)';
]]]
Is there a solution or an alternative?
Regards,
Marco