Tudo usando as últimas versões, a não ser que tenha algum erro durante o copy & paste, isto é o que tenho configurado e por mais que tenha comparado, side-by-side nao consigo encontrar anda de errado.
- sensor:
- unique_id: ibelectra_familia_simples
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 [CGS, Perdas, k, TAR] %}
{{ None }}
{% else %}
{{ ((OMIE+CGS)*(1+Perdas)+k+TAR) | round(2) }}
{% endif %}
attributes:
friendly_name: "Ibelectra Solução Familia (tarifário simples)"
formula: (OMIE+CGS)*(1+Perdas)+k+TAR
OMIE: "{{ state_attr('sensor.omie_spot_price_pt', 'today_average') }}"
CGS: "{{ 7 }}"
Perdas: "{{ 0.1604 }}"
k: "{{ 3.5 }}"
TAR: "{{ 36.50 }}"
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 TAR = state_attr(this.entity_id, 'TAR') -%}
{% set ns = namespace(hourly_data=[]) %}
{% for h in state_attr('sensor.omie_spot_price_pt', 'today_hours') -%}
{% 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 TAR = state_attr(this.entity_id, 'TAR') -%}
{% set ns = namespace(hourly_data=[]) %}
{% for h in state_attr('sensor.omie_spot_price_pt', 'tomorrow_hours') -%}
{% 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) }}
- sensor:
- unique_id: luzboa_spot_btn_simples
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 FA = state_attr(this.entity_id, 'FA') -%}
{% set k = state_attr(this.entity_id, 'k') -%}
{% set TAR = state_attr(this.entity_id, 'TAR') -%}
{% if None in [OMIE, CGS, Perdas, FA, k, TAR] %}
{{ None }}
{% else %}
{{ ((OMIE+CGS)*Perdas*FA+k+TAR) | round(2) }}
{% endif %}
attributes:
friendly_name: "Luzboa SPOT BTN (tarifário simples)"
formula: (OMIE+CGS)*Perdas*FA+k+TAR
OMIE: "{{ state_attr('sensor.omie_spot_price_pt', 'today_average') }}"
CGS: "{{ 6.5 }}"
Perdas: "{{ 1.1507 }}"
FA: "{{ 1.02 }}"
k: "{{ 5 }}"
TAR: "{{ 36.50 }}"
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 FA = state_attr(this.entity_id, 'FA') -%}
{% set k = state_attr(this.entity_id, 'k') -%}
{% set TAR = state_attr(this.entity_id, 'TAR') -%}
{% set ns = namespace(hourly_data=[]) %}
{% for h in state_attr('sensor.omie_spot_price_pt', 'today_hours') -%}
{% if None in [OMIE, CGS, Perdas, FA, k, TAR] %}
{% set price = None %}
{% else %}
{% set price=((OMIE+CGS)*Perdas*FA+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 FA = state_attr(this.entity_id, 'FA') -%}
{% set k = state_attr(this.entity_id, 'k') -%}
{% set TAR = state_attr(this.entity_id, 'TAR') -%}
{% set ns = namespace(hourly_data=[]) %}
{% for h in state_attr('sensor.omie_spot_price_pt', 'tomorrow_hours') -%}
{% if None in [OMIE, CGS, Perdas, FA, k, TAR] %}
{% set price=None %}
{% else %}
{% set price=((OMIE+CGS)*Perdas*FA+k+TAR) | round(2) %}
{% endif %}
{% set ns.hourly_data=ns.hourly_data + [(h.isoformat(), price)] %}
{% endfor -%}
{{ dict(ns.hourly_data) }}
- sensor:
- unique_id: luzboa_excedente_indexado
unit_of_measurement: "€/MWh"
state_class: measurement
state: >
{% set CG = 0.20 -%}
{% set PM = state_attr('sensor.omie_spot_price_pt', 'today_average') -%}
{{ (PM*(1-CG)) | round(2) }}
attributes:
friendly_name: "Luzboa excedente (indexado)"
formula: "PM * (1 - CG)"
PM: "{{ state_attr('sensor.omie_spot_price_pt', 'today_average') }}"
CG: "{{ 0.20 | float }}"
today_hours: >
{% set CG = 0.20 -%}
{% set PM = state_attr('sensor.omie_spot_price_pt', 'today_average') -%}
{% set ns = namespace(hourly_data=[]) %}
{% for h, _ in state_attr('sensor.omie_spot_price_pt', 'today_hours').items() -%}
{% if PM == None or MAJ == None %}
{% set price=PM %}
{% else %}
{% set price=(PM*(1-CG)) | round(2) %}
{% endif %}
{% set ns.hourly_data=ns.hourly_data + [(h.isoformat(), price)] %}
{% endfor -%}
{{ dict(ns.hourly_data) }}
tomorrow_hours: >
{% set CG = 0.20 -%}
{% set PM = state_attr('sensor.omie_spot_price_pt', 'tomorrow_average') -%}
{% set ns = namespace(hourly_data=[]) %}
{% for h, _ in state_attr('sensor.omie_spot_price_pt', 'tomorrow_hours').items() -%}
{% if PM == None or MAJ == None %}
{% set price=PM %}
{% else %}
{% set price=(PM*(1-CG)) | round(2) %}
{% endif %}
{% set ns.hourly_data=ns.hourly_data + [(h.isoformat(), price)] %}
{% endfor -%}
{{ dict(ns.hourly_data) }}