Integração OMIE: preços horários, diários, mecanismo de ajuste

É só pegar no da luzboz da wiki e mudar a formula para ser identica à da MEO

Baseado no bi-horário coopérnico na Wiki e, desenvolvi o template para Tri-horário Semanal - Verão.
https://coopernico.org/ciclos_horarios
Deixo-o aqui para se quiserem adicioná-lo. Está a funcionar há uns dias e parece tudo ok.

Adicionei CS - Custos de Sistema e CR - Custos de regulação, conforme tarifário Coopérnico.

No “state” tive dificuldades a inserir a condição de minutos (Ponta das 9:15 às 12:15), porque sou nabo, então fui à volta e configurei a integração “Data & Hora” no modo “Hora” para usá-lo neste template. Já para os gráficos, ignoro os 15 minutos.

template:
  - sensor
      - unique_id: coopernico_spot_price_trihorario_semanal
        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 k = 9 -%}
          {% set FP = 0.16 -%}
          {% set TAR_ponta = 246.9 -%}
          {% set TAR_cheia = 38.8 -%}
          {% set TAR_vazio = 14.9 -%}
          {% set TAR | float -%}
            {% if now().weekday() >= 0 and now().weekday() < 5 -%}
              {% if '09:15' < states('sensor.time') < '12:15' -%}
                {{ TAR_ponta }}
              {% elif '00:00' <= states('sensor.time') < '07:00' -%}
                {{ TAR_vazio }}
              {% else -%}
                {{ TAR_cheia }}
              {% endif -%}
            {% elif now().weekday() == 5 -%}
              {% if ('09:00' <= states('sensor.time') < '14:00') or ('20:00' <= states('sensor.time') < '22:00') -%}
                {{ TAR_cheia }}
              {% else -%}
                {{ TAR_vazio }}
              {% endif -%} 
            {% else -%}
              {{ TAR_vazio }}
            {% endif -%}
          {% endset -%}
          {% set CS = 2 -%}
          {% set CR = 8 -%}
        
          {{ ((PM + CGS + CS + CR + k)*(1 + FP) + TAR) | round(2) }}
        attributes:
          friendly_name: "Coopérnico Base (tarifário tri-horário semanal)"
          formula: "((PM + CGS + CS + CR + k)*(1 + FP) + TAR)"
          PM: "{{ states('sensor.omie_spot_price_pt')|float }}"
          k: "{{ 9 }}"
          FP: "{{ 0.16 }}"
          TAR_Ponta: "{{ 246.9 }}"
          TAR_Cheia: "{{ 38.8 }}"
          TAR_Vazio: "{{ 14.9 }}"
          CS: "{{ 2 }}"
          CR: "{{ 8 }}"
          today_hours: >
            {% set k = 9 -%}
            {% set FP = 0.16 -%}
            {% set CS = 2 -%}
            {% set CR = 8 -%}

            {% set ns = namespace(hourly_data=[]) %}
            {% for h, PM in state_attr('sensor.omie_spot_price_pt', 'today_hours').items() -%}
              {% set TAR_ponta = 246.9 -%}
              {% set TAR_cheia = 38.8 -%}
              {% set TAR_vazio = 14.9 -%}
              {% set TAR | float -%}
                {% if now().weekday() >= 0 and now().weekday() < 5 -%}
                  {% if h.hour >= 9 and h.hour < 12 -%}
                    {{ TAR_ponta }}
                  {% elif h.hour >= 0 and h.hour < 7 -%}
                    {{ TAR_vazio }}
                  {% else -%}
                    {{ TAR_cheia }}
                  {% endif -%}
                {% elif now().weekday() == 5 -%}
                  {% if (h.hour >= 9 and h.hour <14) or (h.hour >= 20 and h.hour <22) -%}
                    {{ TAR_cheia }}
                  {% else -%}
                    {{ TAR_vazio }}
                  {% endif -%} 
                {% else -%}
                  {{ TAR_vazio }}
                {% endif -%}
              {% endset -%}
              
              {% if PM == None %}
                {% set price=PM %}
              {% else %}
                {% set price=((PM + CGS + CS + CR + 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 k = 9 -%}
            {% set FP = 0.16 -%}
            {% set CS = 2 -%}
            {% set CR = 8 -%}

            {% set ns = namespace(hourly_data=[]) %}
            {% for h, PM in state_attr('sensor.omie_spot_price_pt', 'tomorrow_hours').items() -%}
              {% set TAR_ponta = 246.9 -%}
              {% set TAR_cheia = 38.8 -%}
              {% set TAR_vazio = 14.9 -%}
              {% set TAR | float -%}
                {% if now().weekday() == 6 or now().weekday() < 4 -%}
                  {% if h.hour >= 9 and h.hour < 12 -%}
                    {{ TAR_ponta }}
                  {% elif h.hour >= 0 and h.hour < 7 -%}
                    {{ TAR_vazio }}
                  {% else -%}
                    {{ TAR_cheia }}
                  {% endif -%}
                {% elif now().weekday() == 4 -%}
                  {% if (h.hour >= 9 and h.hour <14) or (h.hour >= 20 and h.hour <22) -%}
                    {{ TAR_cheia }}
                  {% else -%}
                    {{ TAR_vazio }}
                  {% endif -%} 
                {% else -%}
                  {{ TAR_vazio }}
                {% endif -%}
              {% endset -%}
              
              {% if PM == None %}
                {% set price=PM %}
              {% else %}
                {% set price=((PM + CGS + CS + CR + k)*(1 + FP) + TAR) | round(2) %}
              {% endif %}
              {% set ns.hourly_data=ns.hourly_data + [(h.isoformat(), price)] %}
            {% endfor -%}
            {{ dict(ns.hourly_data) }}

Consegues indicar algum bom tutorial de como posso usar o command_line para o efeito?
Obrigado
AL

Consigo mostrar o código que tenho:

command_line:
  - sensor:
      name: "Fator de Perdas"
      command: "tail -n +2 /config/fperdas.csv"
      scan_interval: 60  # Atualiza a cada minuto
      command_timeout: 10
      value_template: >-
        {% set csv = value.split('\n') %}
        {% set hoje = now().strftime('%Y-%m-%d') %}
        {% set hora_atual = now().strftime('%H:%M') %}
        
        {% for linha in csv if linha.startswith(hoje) %}
          {% set dados = linha.split(';') %}
          {% set intervalo = dados[1].split('-') %}
          {% set inicio = intervalo[0] %}
          {% set fim = intervalo[1] %}

          {% if inicio <= hora_atual < fim %}
            {{ dados[2] | replace(',', '.') | float }}
          {% endif %}
        {% endfor %}
1 Curtiu

Excelente!

O meu excel estava com outros formatos, o que me fez ter de aprender mais umas coisas.
Mas já está a funcionar!

Muito Obrigado,
AL

Bom dia,
Alguém conseguiu criar template para tarifário indexado à hora como o Smartflex da G9?

Obrigado.

1 Curtiu

tambem estou interessado e o que puder ajudar estou cá. já estive a fazer um excel com a formula deles mas o meu objetivo é ter um sensor

edit:

Estive a recriar um template com base no que já existe aqui e fica o meu contributo para o G9 SmartFlex tarifa simples:

usei a formula do site G9 ‘https://g9.pt/perguntasfrequentes/

template:
  - sensor:
    - unique_id: g9_smartflex_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 Fadeq = state_attr(this.entity_id, 'Fadeq') -%}
        {% set Perdas = state_attr(this.entity_id, 'Perdas') -%}
        {% set GGS = state_attr(this.entity_id, 'GGS') -%}
        {% set MC = state_attr(this.entity_id, 'MC') -%}
        {% set TAR = state_attr(this.entity_id, 'TAR') -%}
        {% if None in [OMIE, Fadeq, Perdas, GGS, MC, TAR] %}
          {{ None }}
        {% else %}
          {{ ((OMIE * Fadeq * (1 + Perdas)) + GGS + MC + TAR) | round(2) }}
        {% endif %}
      attributes:
        friendly_name: "G9 SmartFlex (tarifário simples)"
        Formula: "OMIE * Fadeq * (1 + Perdas) + GGS + MC + TAR"
        OMIE: "{{ states('sensor.omie_spot_price_pt')|float }}"
        Fadeq: "{{ 1.02 }}"
        Perdas: "{{ 0.16 }}"
        GGS: "{{ 6.5 }}"
        MC: "{{ 5.0 }}"
        TAR: "{{ 60.0 if now().date().isoformat() < '2025-06-01' else 60.0 }}"
        today_hours: >
          {% set Fadeq = state_attr(this.entity_id, 'Fadeq') -%}
          {% set Perdas = state_attr(this.entity_id, 'Perdas') -%}
          {% set GGS = state_attr(this.entity_id, 'GGS') -%}
          {% set MC = state_attr(this.entity_id, 'MC') -%}
          {% set TAR = state_attr(this.entity_id, 'TAR') -%}

          {% set ns = namespace(hourly_data=[]) %}
          {% for h, OMIE in state_attr('sensor.omie_spot_price_pt', 'today_hours').items() -%}
            {% set TAR = 60.0 if h.date().isoformat() < '2025-06-01' else 60.00 -%}

            {% if None in [OMIE, Fadeq, Perdas, GGS, MC, TAR] %}
              {% set price=None %}
            {% else %}
              {% set price=((OMIE * Fadeq * (1 + Perdas)) + GGS + MC + TAR) | round(2) %}
            {% endif %}
            {% set ns.hourly_data=ns.hourly_data + [(h.isoformat(), price)] %}
          {% endfor -%}
          {{ dict(ns.hourly_data) }}
        tomorrow_hours: >
          {% set Fadeq = state_attr(this.entity_id, 'Fadeq') -%}
          {% set Perdas = state_attr(this.entity_id, 'Perdas') -%}
          {% set GGS = state_attr(this.entity_id, 'GGS') -%}
          {% set MC = state_attr(this.entity_id, 'MC') -%}
          {% set TAR = state_attr(this.entity_id, 'TAR') -%}

          {% set ns = namespace(hourly_data=[]) %}
          {% for h, OMIE in state_attr('sensor.omie_spot_price_pt', 'tomorrow_hours').items() -%}
            {% set TAR = 60.0 if h.date().isoformat() < '2025-06-01' else 60.00 -%}

            {% if None in [OMIE, Fadeq, Perdas, GGS, MC, TAR] %}
              {% set price=None %}
            {% else %}
              {% set price=((OMIE * Fadeq * (1 + Perdas)) + GGS + MC + TAR) | round(2) %}
            {% endif %}
            {% set ns.hourly_data=ns.hourly_data + [(h.isoformat(), price)] %}
          {% endfor -%}
          {{ dict(ns.hourly_data) }}

Se verificarem algum erro digam ou até mesmo melhoria.

Eu vou usar outro para visualizar em kWh c/iva

template:
  - sensor:
    - unique_id: g9_smartflex_simples_kwh_iva
      unit_of_measurement: '€/kWh'
      availability: "{{ has_value('sensor.omie_spot_price_pt') }}"
      state_class: measurement
      state: >
        {% set OMIE = states('sensor.omie_spot_price_pt')|float / 1000 -%}
        {% set Fadeq = state_attr(this.entity_id, 'Fadeq') -%}
        {% set Perdas = state_attr(this.entity_id, 'Perdas') -%}
        {% set GGS = state_attr(this.entity_id, 'GGS') -%}
        {% set MC = state_attr(this.entity_id, 'MC') -%}
        {% set TAR = state_attr(this.entity_id, 'TAR') -%}
        {% set IVA = state_attr(this.entity_id, 'IVA') -%}
        {% if None in [OMIE, Fadeq, Perdas, GGS, MC, TAR, IVA] %}
          {{ None }}
        {% else %}
          {{ (((OMIE * Fadeq * (1 + Perdas)) + GGS + MC + TAR) * (1 + (IVA / 100))) | round(4) }}
        {% endif %}
      attributes:
        friendly_name: "G9 SmartFlex (tarifário simples - €/kWh c/IVA)"
        Formula: "(OMIE * Fadeq * (1 + Perdas) + GGS + MC + TAR) * (1 + (IVA / 100))"
        OMIE: "{{ (states('sensor.omie_spot_price_pt')|float / 1000) | round(5) }}"
        Fadeq: "{{ 1.02 }}"
        Perdas: "{{ 0.16 }}"
        GGS: "{{ 0.0065 }}"
        MC: "{{ 0.005 }}"
        TAR: "{{ 0.06 if now().date().isoformat() < '2025-06-01' else 0.06 }}"
        IVA: "{{ 23 }}"
        today_hours: >
          {% set Fadeq = state_attr(this.entity_id, 'Fadeq') -%}
          {% set Perdas = state_attr(this.entity_id, 'Perdas') -%}
          {% set GGS = state_attr(this.entity_id, 'GGS') -%}
          {% set MC = state_attr(this.entity_id, 'MC') -%}
          {% set IVA = state_attr(this.entity_id, 'IVA') -%}
          {% set ns = namespace(hourly_data=[]) %}

          {% for h, OMIE in state_attr('sensor.omie_spot_price_pt', 'today_hours').items() -%}
            {% set OMIE = OMIE / 1000 if OMIE is not none else none -%}
            {% set TAR = 0.06 if h.date().isoformat() < '2025-06-01' else 0.06 -%}
            {% if None in [OMIE, Fadeq, Perdas, GGS, MC, TAR, IVA] %}
              {% set price = None %}
            {% else %}
              {% set price = (((OMIE * Fadeq * (1 + Perdas)) + GGS + MC + TAR) * (1 + (IVA / 100))) | round(4) %}
            {% endif %}
            {% set ns.hourly_data = ns.hourly_data + [(h.isoformat(), price)] %}
          {% endfor -%}
          {{ dict(ns.hourly_data) }}

        tomorrow_hours: >
          {% set Fadeq = state_attr(this.entity_id, 'Fadeq') -%}
          {% set Perdas = state_attr(this.entity_id, 'Perdas') -%}
          {% set GGS = state_attr(this.entity_id, 'GGS') -%}
          {% set MC = state_attr(this.entity_id, 'MC') -%}
          {% set IVA = state_attr(this.entity_id, 'IVA') -%}
          {% set ns = namespace(hourly_data=[]) %}

          {% for h, OMIE in state_attr('sensor.omie_spot_price_pt', 'tomorrow_hours').items() -%}
            {% set OMIE = OMIE / 1000 if OMIE is not none else none -%}
            {% set TAR = 0.06 if h.date().isoformat() < '2025-06-01' else 0.06 -%}
            {% if None in [OMIE, Fadeq, Perdas, GGS, MC, TAR, IVA] %}
              {% set price = None %}
            {% else %}
              {% set price = (((OMIE * Fadeq * (1 + Perdas)) + GGS + MC + TAR) * (1 + (IVA / 100))) | round(4) %}
            {% endif %}
            {% set ns.hourly_data = ns.hourly_data + [(h.isoformat(), price)] %}
          {% endfor -%}
          {{ dict(ns.hourly_data) }}
1 Curtiu

O Mercado Diário do MIBEL (Mercado Ibérico de Eletricidade) passará a funcionar, em breve (previsivelmente a 12 de junho), com preços em intervalos de 15 minutos (quarto-horários).

Será necessário alterar o código, não?

1 Curtiu

Respondido aqui: https://github.com/luuuis/hass_omie/issues/72

Basicamente não tenho tempo de andar a caçar o novo formato de dados, se é que já se sabe como vai ficar. Entretanto se alguém quiser adiantar serviço e descobrir isso, eu devo conseguir fazer a alteração relativamente depressa.

Caso contrário, quando deixar de funcionar logo se vê.

Obrigado @joaopedros2
Está excelente.

Com base no teu vou tentar fazer o template para bi-horário diário

1 Curtiu

Aqui vão os sensor para G9 smartflex bihorário diário. Espero que esteja ok.
Eu uso o template.yaml

########################################### G9 BiHorário ###################################################
 - name: "G9 SmartFlex (tarifário BiHorário Diário - €/kWh c/IVA)"
   unique_id: "g9_smartflex_bihorario_diario_kwh_iva"
   unit_of_measurement: "€/kWh"
   availability: "{{ has_value('sensor.omie_spot_price_pt') }}"
   state_class: measurement
   state: >
     {% set OMIE = states('sensor.omie_spot_price_pt')|float / 1000 -%}
     {% set Fadeq = state_attr(this.entity_id, 'Fadeq') -%}
     {% set Perdas = state_attr(this.entity_id, 'Perdas') -%}
     {% set GGS = state_attr(this.entity_id, 'GGS') -%}
     {% set MC = state_attr(this.entity_id, 'MC') -%}
     {% set TAR = state_attr(this.entity_id, 'TAR') -%}
     {% set IVA = state_attr(this.entity_id, 'IVA') -%}
     {% if None in [OMIE, Fadeq, Perdas, GGS, MC, TAR, IVA] %}
       {{ None }}
     {% else %}
       {{ (((OMIE * Fadeq * (1 + Perdas)) + GGS + MC + TAR) * (1 + (IVA / 100))) | round(4) }}
     {% endif %}
   attributes:
     friendly_name: "G9 SmartFlex (tarifário BiHorário Diário - €/kWh C/IVA)"
     Formula: "(OMIE * Fadeq * (1 + Perdas) + GGS + MC + TAR) * (1 + (IVA / 100))"
     OMIE: "{{ (states('sensor.omie_spot_price_pt')|float / 1000) | round(5) }}"
     Fadeq: "{{ 1.02 }}"
     Perdas: "{{ 0.16 }}"
     GGS: "{{ 0.0065 }}"
     MC: "{{ 0.005 }}"
     TAR_vazio: "{{ 0.0149 if now().date().isoformat() < '2025-06-01' else 0.0149}}"
     TAR_fora_vazio: "{{ 0.083 if now().date().isoformat() < '2025-06-01' else 0.083 }}"
     TAR: "{{ state_attr(this.entity_id, 'TAR_vazio') if now().hour < 8 or now().hour > 21 else state_attr(this.entity_id, 'TAR_fora_vazio') }}"
     IVA: "{{ 23 }}"
     today_average: >
       {% set OMIE = state_attr('sensor.omie_spot_price_pt', 'today_average') | float / 1000 -%}
       {% set Fadeq = state_attr(this.entity_id, 'Fadeq') -%}
       {% set Perdas = state_attr(this.entity_id, 'Perdas') -%}
       {% set GGS = state_attr(this.entity_id, 'GGS') -%}
       {% set MC = state_attr(this.entity_id, 'MC') -%}
       {% set TAR = state_attr(this.entity_id, 'TAR') -%}
       {% set IVA = state_attr(this.entity_id, 'IVA') -%}
       {% if None in [OMIE, Fadeq, Perdas, GGS, MC, TAR, IVA] %}
         {{ None }}
       {% else %}
         {{ (((OMIE * Fadeq * (1 + Perdas)) + GGS + MC + TAR) * (1 + (IVA / 100))) | round(4) }}
       {% endif %}
     today_hours: >
       {% set Fadeq = state_attr(this.entity_id, 'Fadeq') -%}
       {% set Perdas = state_attr(this.entity_id, 'Perdas') -%}
       {% set GGS = state_attr(this.entity_id, 'GGS') -%}
       {% set MC = state_attr(this.entity_id, 'MC') -%}
       {% set IVA = state_attr(this.entity_id, 'IVA') -%}
       {% set ns = namespace(hourly_data=[]) %}

       {% for h, OMIE in state_attr('sensor.omie_spot_price_pt', 'today_hours').items() -%}
         {% set OMIE = OMIE / 1000 if OMIE is not none else none -%}
         {% set TAR = 0.06 if h.date().isoformat() < '2025-06-01' else 0.06 -%}
         {% if None in [OMIE, Fadeq, Perdas, GGS, MC, TAR, IVA] %}
           {% set price = None %}
         {% else %}
           {% set price = (((OMIE * Fadeq * (1 + Perdas)) + GGS + MC + TAR) * (1 + (IVA / 100))) | round(4) %}
         {% endif %}
         {% set ns.hourly_data = ns.hourly_data + [(h.isoformat(), price)] %}
       {% endfor -%}
       {{ dict(ns.hourly_data) }}

     tomorrow_average: >
       {% set OMIE = state_attr('sensor.omie_spot_price_pt', 'tomorrow_average') | float / 1000 -%}
       {% set Fadeq = state_attr(this.entity_id, 'Fadeq') -%}
       {% set Perdas = state_attr(this.entity_id, 'Perdas') -%}
       {% set GGS = state_attr(this.entity_id, 'GGS') -%}
       {% set MC = state_attr(this.entity_id, 'MC') -%}
       {% set TAR = state_attr(this.entity_id, 'TAR') -%}
       {% set IVA = state_attr(this.entity_id, 'IVA') -%}
       {% if None in [OMIE, Fadeq, Perdas, GGS, MC, TAR, IVA] %}
         {{ None }}
       {% else %}
         {{ (((OMIE * Fadeq * (1 + Perdas)) + GGS + MC + TAR) * (1 + (IVA / 100))) | round(4) }}
       {% endif %}

     tomorrow_hours: >
       {% set Fadeq = state_attr(this.entity_id, 'Fadeq') -%}
       {% set Perdas = state_attr(this.entity_id, 'Perdas') -%}
       {% set GGS = state_attr(this.entity_id, 'GGS') -%}
       {% set MC = state_attr(this.entity_id, 'MC') -%}
       {% set IVA = state_attr(this.entity_id, 'IVA') -%}
       {% set ns = namespace(hourly_data=[]) %}

       {% for h, OMIE in state_attr('sensor.omie_spot_price_pt', 'tomorrow_hours').items() -%}
         {% set OMIE = OMIE / 1000 if OMIE is not none else none -%}
         {% set TAR = 0.06 if h.date().isoformat() < '2025-06-01' else 0.06 -%}
         {% if None in [OMIE, Fadeq, Perdas, GGS, MC, TAR, IVA] %}
           {% set price = None %}
         {% else %}
           {% set price = (((OMIE * Fadeq * (1 + Perdas)) + GGS + MC + TAR) * (1 + (IVA / 100))) | round(4) %}
         {% endif %}
         {% set ns.hourly_data = ns.hourly_data + [(h.isoformat(), price)] %}
       {% endfor -%}
       {{ dict(ns.hourly_data) }}

 - name: "G9 SmartFlex (tarifário BiHorário Diário - €/kWh s/IVA)"
   unique_id: g9_smartflex_bihorario_diario
   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 Fadeq = state_attr(this.entity_id, 'Fadeq') -%}
     {% set Perdas = state_attr(this.entity_id, 'Perdas') -%}
     {% set GGS = state_attr(this.entity_id, 'GGS') -%}
     {% set MC = state_attr(this.entity_id, 'MC') -%}
     {% set TAR = state_attr(this.entity_id, 'TAR') -%}
     {% if None in [OMIE, Fadeq, Perdas, GGS, MC, TAR] %}
       {{ None }}
     {% else %}
       {{ ((OMIE * Fadeq * (1 + Perdas)) + GGS + MC + TAR) | round(2) }}
     {% endif %}
   attributes:
     friendly_name: "G9 SmartFlex (tarifário BiHorário Diário - €/kWh s/IVA)"
     Formula: "OMIE * Fadeq * (1 + Perdas) + GGS + MC + TAR"
     OMIE: "{{ states('sensor.omie_spot_price_pt')|float }}"
     Fadeq: "{{ 1.02 }}"
     Perdas: "{{ 0.16 }}"
     GGS: "{{ 6.5 }}"
     MC: "{{ 5.0 }}"
     TAR_vazio: "{{ 14.90 if now().date().isoformat() < '2025-06-01' else 14.90}}"
     TAR_fora_vazio: "{{ 83.0 if now().date().isoformat() < '2025-06-01' else 83.0 }}"
     TAR: "{{ state_attr(this.entity_id, 'TAR_vazio') if now().hour < 8 or now().hour > 21 else state_attr(this.entity_id, 'TAR_fora_vazio') }}"
     today_hours: >
       {% set Fadeq = state_attr(this.entity_id, 'Fadeq') -%}
       {% set Perdas = state_attr(this.entity_id, 'Perdas') -%}
       {% set GGS = state_attr(this.entity_id, 'GGS') -%}
       {% set MC = state_attr(this.entity_id, 'MC') -%}
       {% set TAR = state_attr(this.entity_id, 'TAR') -%}

       {% set ns = namespace(hourly_data=[]) %}
       {% for h, OMIE in state_attr('sensor.omie_spot_price_pt', 'today_hours').items() -%}
         {% set TAR_vazio = 14.90 if h.date().isoformat() < '2024-06-01' else 14.90 %}
         {% set TAR_fora_vazio = 83.0 if h.date().isoformat() < '2024-06-01' else 83.0 %}
         {% set TAR = TAR_vazio if h.hour < 8 or h.hour > 21 else TAR_fora_vazio -%}

         {% if None in [OMIE, Fadeq, Perdas, GGS, MC, TAR] %}
           {% set price=None %}
         {% else %}
           {% set price=((OMIE * Fadeq * (1 + Perdas)) + GGS + MC + TAR) | round(2) %}
         {% endif %}
         {% set ns.hourly_data=ns.hourly_data + [(h.isoformat(), price)] %}
       {% endfor -%}
       {{ dict(ns.hourly_data) }}
     tomorrow_hours: >
       {% set Fadeq = state_attr(this.entity_id, 'Fadeq') -%}
       {% set Perdas = state_attr(this.entity_id, 'Perdas') -%}
       {% set GGS = state_attr(this.entity_id, 'GGS') -%}
       {% set MC = state_attr(this.entity_id, 'MC') -%}
       {% set TAR = state_attr(this.entity_id, 'TAR') -%}

       {% set ns = namespace(hourly_data=[]) %}
       {% for h, OMIE in state_attr('sensor.omie_spot_price_pt', 'tomorrow_hours').items() -%}
         {% set TAR = 60.0 if h.date().isoformat() < '2025-06-01' else 60.00 -%}

         {% if None in [OMIE, Fadeq, Perdas, GGS, MC, TAR] %}
           {% set price=None %}
         {% else %}
           {% set price=((OMIE * Fadeq * (1 + Perdas)) + GGS + MC + TAR) | round(2) %}
         {% endif %}
         {% set ns.hourly_data=ns.hourly_data + [(h.isoformat(), price)] %}
       {% endfor -%}
       {{ dict(ns.hourly_data) }}
2 Curtiram

Copyright © 2017-. Todos os direitos reservados
CPHA.pt - info@cpha.pt


FAQ | Termos de Serviço/Regras | Política de Privacidade