Jeg setter opp Nordpool i GUI, og så bruker jeg denne templaten for å kalkulere reell pris. Det fungerer veldig bra hos meg…
{% set taxes = {
"jan_mar_night": 0.3786,
"jan_mar_day": 0.5025,
"apr_dec_night": 0.4652,
"apr_dec_day": 0.5925,
"holiday_jan_mar": 0.3786,
"holiday_apr_dec": 0.4652
} %}
{# Determine if today is a holiday #}
{% set today = (as_timestamp(now()) | timestamp_custom("%F")) %}
{% set holidays = state_attr('calendar.holidays', 'holidays') | list %}
{% set is_holiday = today in holidays %}
{# Determine if today is a weekend (Saturday=5, Sunday=6) #}
{% set weekday = now().weekday() %}
{% set is_weekend = weekday >= 5 %} {# 5=Saturday, 6=Sunday #}
{# Combine holiday and weekend checks #}
{% set is_holiday_or_weekend = is_holiday or is_weekend %}
{# Determine the current season #}
{% set season = "jan_mar" if now().month <= 3 else "apr_dec" %}
{# Determine the time of day #}
{% set time_of_day = "day" if 6 <= now().hour <= 22 else "night" %}
{# Select the appropriate tax rate #}
{% if is_holiday_or_weekend %}
{% set el_taxes = taxes["holiday_" ~ season] %}
{% else %}
{% set el_taxes = taxes[season ~ "_" ~ time_of_day] %}
{% endif %}
{# Calculate the subsidies #}
{% set subsidy_rate = 0.9 if now().month in [1, 2, 3, 10, 11, 12] else 0.8 %}
{% if current_price > 0.70 %}
{% set subs = (current_price - 0.70) * subsidy_rate %}
{% set additional_cost = el_taxes - subs %}
{% else %}
{% set additional_cost = el_taxes %}
{% endif %}
{{ additional_cost | round(4) }}