@luuuis ,
Tentei fazer um template para a Ibelectra, tarifário Familia: Solução FAMÍLIA, com base no mail recebido: Mail
- unique_id: ibelectra_familia_bihorario
unit_of_measurement: '€/MWh'
availability: "{{ state_attr('sensor.omie_spot_price_pt', 'today_average') != None }}"
state_class: measurement
state: >
{% set OMIE = state_attr('sensor.omie_spot_price_pt', 'today_average') -%}
{% set CGS = state_attr(this.entity_id, 'CGS') -%}
{% set Perdas = state_attr(this.entity_id, 'Perdas') -%}
{% set k = state_attr(this.entity_id, 'k') -%}
{% set TAR = state_attr(this.entity_id, 'TAR') -%}
{% if None in [OMIE, CGS, Perdas, k, TAR] %}
{{ None }}
{% else %}
{{ ((OMIE+CGS)*(1+Perdas)+k+TAR) | round(2) }}
{% endif %}
attributes:
friendly_name: "Ibelectra Solução Familia (tarifário bi-horário)"
formula: (OMIE+CGS)*(1+Perdas)+k+TAR
OMIE: "{{ state_attr('sensor.omie_spot_price_pt', 'today_average') }}"
CGS: "{{ 7 }}"
Perdas: "{{ 1.1604 }}"
k: "{{ 3.5 }}"
TAR_vazio: "{{ 9.2 }}"
TAR_fora_vazio: "{{ 50.2 }}"
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 OMIE = state_attr('sensor.omie_spot_price_pt', 'today_average') -%}
{% set CGS = state_attr(this.entity_id, 'CGS') -%}
{% set Perdas = state_attr(this.entity_id, 'Perdas') -%}
{% set k = state_attr(this.entity_id, 'k') -%}
{% set ns = namespace(hourly_data=[]) %}
{% for h in state_attr('sensor.omie_spot_price_pt', 'today_hours') -%}
{% set TAR = state_attr(this.entity_id, 'TAR_vazio') if h.hour < 8 or h.hour > 21 else state_attr(this.entity_id, 'TAR_fora_vazio') -%}
{% if None in [OMIE, CGS, Perdas, k, TAR] %}
{% set price = None %}
{% else %}
{% set price=((OMIE+CGS)*(1+Perdas)+k+TAR) | round(2) %}
{% endif %}
{% set ns.hourly_data=ns.hourly_data + [(h.isoformat(), price)] %}
{% endfor -%}
{{ dict(ns.hourly_data) }}
tomorrow_hours: >
{% set OMIE = state_attr('sensor.omie_spot_price_pt', 'tomorrow_average') -%}
{% set CGS = state_attr(this.entity_id, 'CGS') -%}
{% set Perdas = state_attr(this.entity_id, 'Perdas') -%}
{% set k = state_attr(this.entity_id, 'k') -%}
{% set ns = namespace(hourly_data=[]) %}
{% for h in state_attr('sensor.omie_spot_price_pt', 'tomorrow_hours') -%}
{% set TAR = state_attr(this.entity_id, 'TAR_vazio') if h.hour < 8 or h.hour > 21 else state_attr(this.entity_id, 'TAR_fora_vazio') -%}
{% if None in [OMIE, CGS, Perdas, k, TAR] %}
{% set price=None %}
{% else %}
{% set price=((OMIE+CGS)*(1+Perdas)+k+TAR) | round(2) %}
{% endif %}
{% set ns.hourly_data=ns.hourly_data + [(h.isoformat(), price)] %}
{% endfor -%}
{{ dict(ns.hourly_data) }}
Não sei se está ok. Podes confirmar?