-
Notifications
You must be signed in to change notification settings - Fork 7
Coopérnico excedentes UPAC
Luis Miranda edited this page May 29, 2023
·
2 revisions
template:
sensor:
- unique_id: coopernico_excedente_indexado
unit_of_measurement: '€/MWh'
state_class: measurement
state: >
{% set PM = states('sensor.omie_spot_price_pt')|float(default=None) -%}
{% set K = state_attr(this.entity_id, 'K') -%}
{% if None in [PM, K] %}
{{ None }}
{% else %}
{{ (PM*(1-K)) | round(2) }}
{% endif %}
attributes:
friendly_name: "Coopérnico compra de excedentes de UPAC"
formula: "(PM*(1-K))"
PM: "{{ states('sensor.omie_spot_price_pt')|float }}"
K: "{{ 0.2 }}"
today_hours: >
{% set K = state_attr(this.entity_id, 'K') -%}
{% set ns = namespace(hourly_data=[]) %}
{% for h, PM in state_attr('sensor.omie_spot_price_pt', 'today_hours').items() -%}
{% if None in [PM, K] %}
{% set price=None %}
{% else %}
{% set price=(PM*(1-K)) | round(2) %}
{% endif %}
{% set ns.hourly_data=ns.hourly_data + [(h.isoformat(), price)] %}
{% endfor -%}
{{ dict(ns.hourly_data) }}
tomorrow_hours: >
{% set K = state_attr(this.entity_id, 'K') -%}
{% set ns = namespace(hourly_data=[]) %}
{% for h, PM in state_attr('sensor.omie_spot_price_pt', 'tomorrow_hours').items() -%}
{% if None in [PM, K] %}
{% set price=None %}
{% else %}
{% set price=(PM*(1-K)) | round(2) %}
{% endif %}
{% set ns.hourly_data=ns.hourly_data + [(h.isoformat(), price)] %}
{% endfor -%}
{{ dict(ns.hourly_data) }}