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) }}