-
Notifications
You must be signed in to change notification settings - Fork 6
Luzboa SPOT BTN Bi horário
Luis Miranda edited this page May 29, 2024
·
16 revisions
template:
sensor:
- unique_id: luzboa_spot_btn_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 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 bi-horário)"
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_vazio: "{{ 9.2 if now().date().isoformat() < '2024-06-01' else 15.7 }}"
TAR_fora_vazio: "{{ 50.2 if now().date().isoformat() < '2024-06-01' else 86 }}"
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 FA = state_attr(this.entity_id, 'FA') -%}
{% 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_vazio = 9.2 if h.date().isoformat() < '2024-06-01' else 15.7 %}
{% set TAR_fora_vazio = 50.2 if h.date().isoformat() < '2024-06-01' else 86 %}
{% set TAR = TAR_vazio if h.hour < 8 or h.hour > 21 else TAR_fora_vazio -%}
{% 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 ns = namespace(hourly_data=[]) %}
{% for h in state_attr('sensor.omie_spot_price_pt', 'tomorrow_hours') -%}
{% set TAR_vazio = 9.2 if h.date().isoformat() < '2024-06-01' else 15.7 %}
{% set TAR_fora_vazio = 50.2 if h.date().isoformat() < '2024-06-01' else 86 %}
{% set TAR = TAR_vazio if h.hour < 8 or h.hour > 21 else TAR_fora_vazio -%}
{% 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) }}