I am trying to reuse some code in my template through a node anchor. I just don’t get it to work. This is the code:
- sensor:
- name: "NextHoliday"
state: "OK"
attributes:
dummy: &order
>
{% set a = states.sensor.new_year_s_day.state | int %}
{% set b = states.sensor.easter_sunday.state | int %}
{% set c = states.sensor.easter_monday.state | int %}
{% set d = states.sensor.labor_day_may_day.state | int %}
{% set e = states.sensor.ascension_day.state | int %}
{% set f = states.sensor.whit_sunday.state | int %}
{% set g = states.sensor.whit_monday.state | int %}
{% set h = states.sensor.belgian_national_day.state | int %}
{% set i = states.sensor.assumption_of_mary.state | int %}
{% set j = states.sensor.armistice_day.state | int %}
{% set k = states.sensor.christmas_day.state | int %}
{% set l = states.sensor.boxing_day.state | int %}
{% set earliest = (a,b,c,d,e,f,g,h,i,j,k,l) | min %}
{% if a == earliest %}
{% set name = state_attr('sensor.new_year_s_day', 'friendly_name') %}
{% set date = state_attr('sensor.new_year_s_day', 'date') %}
{% elif b == earliest %}
{% set name = state_attr('sensor.easter_sunday', 'friendly_name') %}
{% set date = state_attr('sensor.easter_sunday', 'date') %}
{% elif c == earliest %}
{% set name = state_attr('sensor.easter_monday', 'friendly_name') %}
{% set date = state_attr('sensor.easter_monday', 'date') %}
{% elif d == earliest %}
{% set name = state_attr('sensor.labor_day_may_day', 'friendly_name') %}
{% set date = state_attr('sensor.labor_day_may_day', 'date') %}
{% elif e == earliest %}
{% set name = state_attr('sensor.ascension_day', 'friendly_name') %}
{% set date = state_attr('sensor.ascension_day', 'date') %}
{% elif f == earliest %}
{% set name = state_attr('sensor.whit_sunday', 'friendly_name') %}
{% set date = state_attr('sensor.whit_sunday', 'date') %}
{% elif g == earliest %}
{% set name = state_attr('sensor.whit_monday', 'friendly_name') %}
{% set date = state_attr('sensor.whit_monday', 'date') %}
{% elif h == earliest %}
{% set name = state_attr('sensor.belgian_national_day', 'friendly_name') %}
{% set date = state_attr('sensor.belgian_national_day', 'date') %}
{% elif i == earliest %}
{% set name = state_attr('sensor.assumption_of_mary', 'friendly_name') %}
{% set date = state_attr('sensor.assumption_of_mary', 'date') %}
{% elif j == earliest %}
{% set name = state_attr('sensor.armistice_day', 'friendly_name') %}
{% set date = state_attr('sensor.armistice_day', 'date') %}
{% elif k == earliest %}
{% set name = state_attr('sensor.christmas_day', 'friendly_name') %}
{% set date = state_attr('sensor.christmas_day', 'date') %}
{% elif l == earliest %}
{% set name = state_attr('sensor.boxing_day', 'friendly_name') %}
{% set date = state_attr('sensor.boxing_day', 'date') %}
{% else %}
n/a
{% endif %}
{{ earliest }}
days: >
*order
{{ earliest }}
name: >
*order
{{ name }}
date: >
*order
{{ date }}
So the result from this is the following senor values:
dummy: 61
days: '*order'
name: '*order'
date: '*order'
friendly_name: NextHoliday
changing the last part of the template to:
days: *order
{{ earliest }}
name: *order
{{ name }}
date: *order
{{ date }}
Gives me an error in the configuraiton check:
Error loading /config/configuration.yaml: while parsing a block mapping
in "/config/configuration.yaml", line 190, column 9
expected <block end>, but found '{'
in "/config/configuration.yaml", line 246, column 11
Line 190 is line of: dummy: &order
and line 246 is the line of: {{ earliest }}
I am kinda at a loss how to solve this. So how do I call the &order anchor in the next option of the template?