Skip to content

Coopérnico Base Simples

Luis Miranda edited this page May 29, 2024 · 16 revisions

Coopérnico Base - Tarifário Simples

Screenshot: Coopérnico Base Simples

template:
  sensor:
    - unique_id: coopernico_spot_price_simples
      unit_of_measurement: '€/MWh'
      availability: "{{ has_value('sensor.omie_spot_price_pt') }}"
      state_class: measurement
      state: >
        {% set PM = states('sensor.omie_spot_price_pt')|float -%}
        {% set CGS = 4 -%}
        {% set TSE = 2.893 -%}
        {% set k = 10 -%}
        {% set FP = 0.16 -%}
        {% set TAR = 36.5 if now().date().isoformat() < '2024-06-01' else 62.5 -%}
        
        {{ ((PM + CGS + TSE + k)*(1 + FP) + TAR) | round(2) }}
      attributes:
        friendly_name: "Coopérnico Base (tarifário simples)"
        formula: "(PM+CGS+TSE+K)*(1+FP)+TAR"
        PM: "{{ states('sensor.omie_spot_price_pt')|float }}"
        CGS: "{{ 4 }}"
        TSE: "{{ 2.893 }}"
        k: "{{ 10 }}"
        FP: "{{ 0.16 }}"
        TAR: "{{ 36.5 if now().date().isoformat() < '2024-06-01' else 62.5 }}"
        today_hours: >
          {% set CGS = 4 -%}
          {% set TSE = 2.893 -%}
          {% set k = 10 -%}
          {% set FP = 0.15 -%}
          
          {% set ns = namespace(hourly_data=[]) %}
          {% for h, PM in state_attr('sensor.omie_spot_price_pt', 'today_hours').items() -%}
            {% set TAR = 36.5 if h.date().isoformat() < '2024-06-01' else 62.5 -%}
          
            {% if PM == None %}
              {% set price=PM %}
            {% else %}
              {% set price=((PM + CGS + TSE + k)*(1 + FP) + TAR) | round(2) %}
            {% endif %}
            {% set ns.hourly_data=ns.hourly_data + [(h.isoformat(), price)] %}
          {% endfor -%}
          {{ dict(ns.hourly_data) }}
        tomorrow_hours: >
          {% set CGS = 4 -%}
          {% set TSE = 2.893 -%}
          {% set k = 10 -%}
          {% set FP = 0.15 -%}

          {% set ns = namespace(hourly_data=[]) %}
          {% for h, PM in state_attr('sensor.omie_spot_price_pt', 'tomorrow_hours').items() -%}
            {% set TAR = 36.5 if h.date().isoformat() < '2024-06-01' else 62.5 -%}
          
            {% if PM == None %}
              {% set price=PM %}
            {% else %}
              {% set price=((PM + CGS + TSE + k)*(1 + FP) + TAR) | round(2) %}
            {% endif %}
            {% set ns.hourly_data=ns.hourly_data + [(h.isoformat(), price)] %}
          {% endfor -%}
          {{ dict(ns.hourly_data) }}