-
Notifications
You must be signed in to change notification settings - Fork 13
Luzboa SPOT BTN Simples
Luis Miranda edited this page Dec 31, 2023
·
18 revisions

template:
sensor:
- unique_id: luzboa_spot_btn_simples
unit_of_measurement: '€/MWh'
availability: "{{ state_attr('sensor.omie_spot_price_pt', 'today_average') != None and state_attr('sensor.omie_adjustment_price_pt', 'today_average') != None }}"
state_class: measurement
state: >
{% set PMD = state_attr(this.entity_id, 'PMD') -%}
{% set MIBEL = state_attr(this.entity_id, 'MIBEL') -%}
{% set Desvios = state_attr(this.entity_id, 'Desvios') -%}
{% set SAJ = state_attr(this.entity_id, 'SAJ') -%}
{% set FA = state_attr(this.entity_id, 'FA') -%}
{% set PT = state_attr(this.entity_id, 'PT') -%}
{% set CG = state_attr(this.entity_id, 'CG') -%}
{% set TEPAi = state_attr(this.entity_id, 'TEPAi') -%}
{% if None in [PMD, MIBEL, Desvios, SAJ, FA, PT, CG, TEPAi] %}
{{ None }}
{% else %}
{% set PFC = PMD + MIBEL + Desvios + SAJ -%}
{{ ((PFC*(1+PT))*FA+(CG)+(TEPAi)) | round(2) }}
{% endif %}
attributes:
friendly_name: "Luzboa SPOT BTN (tarifário simples)"
formula: (ER*PFC*(1+PT)*FA)+(ER*CG)+(ER*TEPAi)
PMD: "{{ state_attr('sensor.omie_spot_price_pt', 'today_average') | float(default=0) }}"
MIBEL: "{{ state_attr('sensor.omie_adjustment_price_pt', 'today_average') | float(default=0) }}"
Desvios: "{{ 0 }}"
SAJ: "{{ 4 }}"
FA: "{{ 1.02 }}"
PT: "{{ 0.1507 }}"
CG: "{{ 5 }}"
TEPAi: "{{ -12.1 if now().date().isoformat() < '2024-01-01' else 36.50 }}"
today_hours: >
{% set PMD = state_attr('sensor.omie_spot_price_pt', 'today_average') -%}
{% set MIBEL = state_attr('sensor.omie_adjustment_price_pt', 'today_average') -%}
{% set Desvios = state_attr(this.entity_id, 'Desvios') -%}
{% set SAJ = state_attr(this.entity_id, 'SAJ') -%}
{% set FA = state_attr(this.entity_id, 'FA')-%}
{% set PT = state_attr(this.entity_id, 'PT') -%}
{% set CG = state_attr(this.entity_id, 'CG') -%}
{% set TEPAi = state_attr(this.entity_id, 'TEPAi') -%}
{% set ns = namespace(hourly_data=[]) %}
{% for h in state_attr('sensor.omie_spot_price_pt', 'today_hours') -%}
{% if None in [PMD, MIBEL, Desvios, SAJ, FA, PT, CG, TEPAi] %}
{% set price = None %}
{% else %}
{% set PFC = PMD + MIBEL + Desvios + SAJ -%}
{% set price=((PFC*(1+PT))*FA+(CG)+(TEPAi)) | round(2) %}
{% endif %}
{% set ns.hourly_data=ns.hourly_data + [(h.isoformat(), price)] %}
{% endfor -%}
{{ dict(ns.hourly_data) }}
tomorrow_hours: >
{% set PMD = state_attr('sensor.omie_spot_price_pt', 'tomorrow_average') -%}
{% set MIBEL = state_attr('sensor.omie_adjustment_price_pt', 'tomorrow_average') -%}
{% set Desvios = state_attr(this.entity_id, 'Desvios') -%}
{% set SAJ = state_attr(this.entity_id, 'SAJ') -%}
{% set FA = state_attr(this.entity_id, 'FA')-%}
{% set PT = state_attr(this.entity_id, 'PT') -%}
{% set CG = state_attr(this.entity_id, 'CG') -%}
{% set TEPAi = state_attr(this.entity_id, 'TEPAi') -%}
{% set ns = namespace(hourly_data=[]) %}
{% for h in state_attr('sensor.omie_spot_price_pt', 'tomorrow_hours') -%}
{% if None in [PMD, MIBEL, Desvios, SAJ, FA, PT, CG, TEPAi] %}
{% set price = None %}
{% else %}
{% set PFC = PMD + MIBEL + Desvios + SAJ -%}
{% set price=((PFC*(1+PT))*FA+(CG)+(TEPAi)) | round(2) %}
{% endif %}
{% set ns.hourly_data=ns.hourly_data + [(h.isoformat(), price)] %}
{% endfor -%}
{{ dict(ns.hourly_data) }}