Skip to content

Energia Simples excedente indexado

Luis Miranda edited this page Jan 7, 2024 · 4 revisions

Energia Simples Excedente (Indexado)

Screenshot - Energia Simples Excedente (Indexado)

template:
  sensor:
    - unique_id: energia_simples_excedente_indexado
      unit_of_measurement: '€/MWh'
      state_class: measurement
      state: >
          {% set K1 = 10 -%}
          {% set POMIEh = states('sensor.omie_spot_price_pt')|float -%}
          {{ [POMIEh - K1, 0] | max | round(2) }}
      attributes:
        friendly_name: "Energia Simples excedente (indexado)"
        formula: "POMIE(h) - K1"
        POMIEh: "{{ states('sensor.omie_spot_price_pt') }}"
        K1: 10
        today_hours: >
            {% set K1 = 10 -%}

            {% set ns = namespace(hourly_data=[]) %}
            {% for h, POMIEh in state_attr('sensor.omie_spot_price_pt', 'today_hours').items() -%}
              {% if POMIEh == None %}
                {% set price=POMIEh %}
              {% else %}
                {% set price=[(POMIEh - K1), 0] | max | round(2) %}
              {% endif %}
              {% set ns.hourly_data=ns.hourly_data + [(h.isoformat(), price)] %}
            {% endfor -%}
            {{ dict(ns.hourly_data) }}
        tomorrow_hours: >
            {% set K1 = 10 -%}

            {% set ns = namespace(hourly_data=[]) %}
            {% for h, POMIEh in state_attr('sensor.omie_spot_price_pt', 'tomorrow_hours').items() -%}
              {% if POMIEh == None %}
                {% set price=POMIEh %}
              {% else %}
                {% set price=[(POMIEh - K1), 0] | max | round(2) %}
              {% endif %}
              {% set ns.hourly_data=ns.hourly_data + [(h.isoformat(), price)] %}
            {% endfor -%}
            {{ dict(ns.hourly_data) }}