Code: Select all
- platform: template
sensors:
veckodag:
value_template: "{{ ['Måndag','Tisdag','Onsdag','Torsdag','Fredag','Lördag','Söndag'][now().weekday()] }}"
Code: Select all
{%- set now = now() -%}
{%- set year = now.year -%}
{%- set golden_number = (year % 19) + 1 -%}
{%- set solar_correction = ((year - 1600) / 100) | int - ((year - 1600) / 400) | int -%}
{%- set lunar_correction = ((((year - 1400) / 100) * 8) / 25) |int -%}
{%- set paschal_full_moon = (3 - (11 * golden_number) + solar_correction - lunar_correction) % 30 -%}
{%- if (paschal_full_moon == 29) or ((paschal_full_moon == 28) and (golden_number > 11)) -%}
{%- set paschal_full_moon = paschal_full_moon - 1 -%}
{%- endif -%}
{%- set dominical_number = (year + (year / 4) | int - (year / 100) | int + (year / 400) | int) % 7 -%}
{%- set first_sunday = (8 - dominical_number) % 7 -%}
{%- set days_between_easter_and_pfm = (4 - dominical_number - paschal_full_moon) % 7 + 1 -%}
{%- set easter_after_march21 = paschal_full_moon + days_between_easter_and_pfm -%}
{%- set easter = now.replace(month=3, day=21) + timedelta(days=easter_after_march21) -%}
{%- set julaftondag = ( ( ( year | string) + "-12-24" ) | as_datetime ).weekday() -%}
{%- if ( julaftondag == 6 ) -%}
{%- set adventoffset = 0 -%}
{%- else -%}
{%- set adventoffset = julaftondag -%}
{%- endif -%}
{%- set adventdag_4 = 23 - adventoffset -%}
{%- set advent4 = ( ( year | string) + "-12-" + (adventdag_4| string) ) | as_datetime -%}
{%- if ( (now.month == easter.month) and (now.day == easter.day) ) -%} Påskdagen
{%- elif ( (now.month == (easter.date() - timedelta(days=1)).month) and (now.day == (easter.date() - timedelta(days=1)).day) ) -%} Påskafton
{%- elif ( (now.month == (easter.date() - timedelta(days=2)).month) and (now.day == (easter.date() - timedelta(days=2)).day) ) -%} Långfredag
{%- elif ( (now.month == (easter.date() - timedelta(days=3)).month) and (now.day == (easter.date() - timedelta(days=3)).day) ) -%} Skärtorsdag
{%- elif ( (now.month == (easter.date() + timedelta(days=1)).month) and (now.day == (easter.date() + timedelta(days=1)).day) ) -%} Annadag Påsk
{%- elif ( (now.month == (easter.date() + timedelta(days=39)).month) and (now.day == (easter.date() + timedelta(days=39)).day) ) -%} Kristi himmelsfärdsdag
{%- elif ( (now.month == (easter.date() + timedelta(days=48)).month) and (now.day == (easter.date() + timedelta(days=48)).day) ) -%} Pingstafton
{%- elif ( (now.month == (easter.date() + timedelta(days=49)).month) and (now.day == (easter.date() + timedelta(days=49)).day) ) -%} Pingstdagen
{%- elif ( now.month == 6 and now.day >= 19 and now.day <= 25 and now.weekday() == 4 ) -%} Midsommarafton
{%- elif ( now.month == 6 and now.day >= 20 and now.day <= 26 and now.weekday() == 5 ) -%} Midsommardagen
{%- elif ( now.weekday() == 4 and ( ( now.month == 10 and now.day >= 30 ) or ( now.month == 11 and now.day <= 5 ) ) ) -%} Allhelgonaafton
{%- elif ( now.weekday() == 5 and ( ( now.month == 10 and now.day == 31 ) or ( now.month == 11 and now.day <= 6 ) ) ) -%} Alla helgons dag
{%- elif ( now.month == 4 and now.day == 30 ) -%} Valborgsmässoafton
{%- elif ( now.month == 5 and now.day == 1 ) -%} Första Maj
{%- elif ( now.month == 1 and now.day == 1 ) -%} Nyårsdagen
{%- elif ( now.month == 1 and now.day == 5 ) -%} Trettondagsafton
{%- elif ( now.month == 1 and now.day == 6 ) -%} Trettondedag Jul
{%- elif ( now.month == 2 and now.day == 14 ) -%} Alla Hjärtans Dag
{%- elif ( now.month == 6 and now.day == 6 ) -%} Sveriges Nationaldag
{%- elif ( now.month == 12 and now.day == 24 ) -%} Julafton
{%- elif ( now.month == 12 and now.day == 25 ) -%} Juldagen
{%- elif ( now.month == 12 and now.day == 26 ) -%} Annadag jul
{%- elif ( now.month == 12 and now.day == 31 ) -%} Nyårsafton
{%- elif ( now.date() == advent4.date() ) -%} Fjärde advent
{%- elif ( now.date() == advent4.date() - timedelta(days=7) ) -%} Tredje advent
{%- elif ( now.date() == advent4.date() - timedelta(days=14) ) -%} Andra advent
{%- elif ( now.date() == advent4.date() - timedelta(days=21) ) -%} Första advent
{%- elif ( now.weekday() == 0 ) -%} Måndag
{%- elif ( now.weekday() == 1 ) -%} Tisdag
{%- elif ( now.weekday() == 2 ) -%} Onsdag
{%- elif ( now.weekday() == 3 ) -%} Torsdag
{%- elif ( now.weekday() == 4 ) -%} Fredag
{%- elif ( now.weekday() == 5 ) -%} Lördag
{%- elif ( now.weekday() == 6 ) -%} Söndag
{% else %} Något är nog fel...
{%- endif -%}