Skip to content

Repsol Leve sem Mais simples

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

Screenshot - Repsol Sem Leve Mais (indexado, tarifário simples)

template:
  sensor:
    - unique_id: repsol_spot_price_simples
      unit_of_measurement: '€/MWh'
      availability: "{{ has_value('sensor.omie_spot_price_pt') }}"
      state_class: measurement
      state: >
        {% set OMIE = states('sensor.omie_spot_price_pt')|float -%}
        {% set Perdas = 0.15 -%}
        {% set FA = 1.03 -%}
        {% set QTarifa = 14.79 -%}
        {% set TAR = 36.5 if now().date().isoformat() < '2024-06-01' else 62.5 -%}
        
        {{ ((OMIE)*(1 + Perdas)*FA + QTarifa + TAR) | round(2) }}
      attributes:
        friendly_name: "Repsol Indexado (tarifário simples)"
        formula: "(OMIE)*(1 + Perdas)*FA + QTarifa + TAR"
        OMIE: "{{ states('sensor.omie_spot_price_pt')|float }}"
        Perdas: "{{ 0.15 }}"
        FA: "{{ 1.03 }}"
        QTarifa: "{{ 14.79 }}"
        TAR: "{{ 36.5 if now().date().isoformat() < '2024-06-01' else 62.5 }}"
        today_hours: >
            {% set Perdas = 0.15 -%}
            {% set FA = 1.03 -%}
            {% set QTarifa = 14.79 -%}
            
            {% set ns = namespace(hourly_data=[]) %}
            {% for h, OMIE in state_attr('sensor.omie_spot_price_pt', 'today_hours').items() -%}
              {% set TAR = 36.5 if h.date().isoformat() < '2024-06-01' else 62.50 -%}
          
              {% if OMIE == None %}
                {% set price=OMIE %}
              {% else %}
                {% set price=((OMIE)*(1 + Perdas)*FA + QTarifa + TAR) | round(2) %}
              {% endif %}
              {% set ns.hourly_data=ns.hourly_data + [(h.isoformat(), price)] %}
            {% endfor -%}
            {{ dict(ns.hourly_data) }}
        tomorrow_hours: >
            {% set Perdas = 0.15 -%}
            {% set FA = 1.03 -%}
            {% set QTarifa = 14.79 -%}

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