Created
April 12, 2024 14:13
-
-
Save nosuchuser/29f2d5672636b9d0c46f70a08153ab6d to your computer and use it in GitHub Desktop.
Home Assistant / Template para sensores com valores de tarifário Repsol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# add "template: !include repsol_template.yaml" to configuration.yaml to include this | |
sensor: | |
- unique_id: repsol_spot_price_simples | |
unit_of_measurement: 'Cent/KWh' | |
availability: "{{ has_value('sensor.omie_spot_price_pt') }}" | |
state_class: measurement | |
state: > | |
{% set OMIE = states('sensor.omie_spot_price_pt')|float -%} | |
{% set Perdas = 0.15 -%} | |
{% set FA = 1.03 -%} | |
{% set QTarifa = 14.79 -%} | |
{% set TAR = 36.5 -%} | |
{{ ((OMIE)*(1 + Perdas)*FA + QTarifa + TAR) | round(2) }} | |
attributes: | |
friendly_name: "Repsol Indexado (tarifário simples)" | |
formula: "(OMIE)*(1 + Perdas)*FA + QTarifa + TAR" | |
OMIE: "{{ states('sensor.omie_spot_price_pt')|float }}" | |
Perdas: "{{ 0.15 }}" | |
FA: "{{ 1.03 }}" | |
QTarifa: "{{ 14.79 }}" | |
TAR: "{{ 36.5 }}" | |
today_hours: > | |
{% set Perdas = 0.15 -%} | |
{% set FA = 1.03 -%} | |
{% set QTarifa = 14.79 -%} | |
{% set TAR = 36.5 -%} | |
{% set ns = namespace(hourly_data=[]) %} | |
{% for h, OMIE in state_attr('sensor.omie_spot_price_pt', 'today_hours').items() -%} | |
{% if OMIE == None %} | |
{% set price=OMIE %} | |
{% else %} | |
{% set price=((OMIE)*(1 + Perdas)*FA + QTarifa + TAR) /10 | round(2) %} | |
{% endif %} | |
{% set ns.hourly_data=ns.hourly_data + [(h.isoformat(), price)] %} | |
{% endfor -%} | |
{{ dict(ns.hourly_data) }} | |
tomorrow_hours: > | |
{% set Perdas = 0.15 -%} | |
{% set FA = 1.03 -%} | |
{% set QTarifa = 14.79 -%} | |
{% set TAR = 36.5 -%} | |
{% set ns = namespace(hourly_data=[]) %} | |
{% for h, OMIE in state_attr('sensor.omie_spot_price_pt', 'tomorrow_hours').items() -%} | |
{% if OMIE == None %} | |
{% set price=OMIE %} | |
{% else %} | |
{% set price=((OMIE)*(1 + Perdas)*FA + QTarifa + TAR) /10 | round(2) %} | |
{% endif %} | |
{% set ns.hourly_data=ns.hourly_data + [(h.isoformat(), price)] %} | |
{% endfor -%} | |
{{ dict(ns.hourly_data) }} | |
- unique_id: repsol_spot_price_bihorario | |
unit_of_measurement: 'Cent/KWh' | |
availability: "{{ has_value('sensor.omie_spot_price_pt') }}" | |
state_class: measurement | |
state: > | |
{% set OMIE = states('sensor.omie_spot_price_pt')|float -%} | |
{% set Perdas = 0.15 -%} | |
{% set FA = 1.03 -%} | |
{% set QTarifa = 14.79 -%} | |
{% set TAR_vazio = 9.2 -%} | |
{% set TAR_fora_vazio = 50.2 -%} | |
{% set TAR = TAR_vazio if now().hour < 8 or now().hour > 21 else TAR_fora_vazio -%} | |
{{ ((OMIE)*(1 + Perdas)*FA + QTarifa + TAR) | round(2) }} | |
attributes: | |
friendly_name: "Repsol Indexado (tarifário bi-horário)" | |
formula: "(OMIE)*(1 + Perdas)*FA + QTarifa + TAR" | |
OMIE: "{{ states('sensor.omie_spot_price_pt')|float }}" | |
Perdas: "{{ 0.15 }}" | |
FA: "{{ 1.03 }}" | |
QTarifa: "{{ 14.79 }}" | |
TAR_vazio: "{{ 9.2 }}" | |
TAR_fora_vazio: "{{ 50.2 }}" | |
today_hours: > | |
{% set Perdas = 0.15 -%} | |
{% set FA = 1.03 -%} | |
{% set QTarifa = 14.79 -%} | |
{% set TAR_vazio = 9.2 -%} | |
{% set TAR_fora_vazio = 50.2 -%} | |
{% set ns = namespace(hourly_data=[]) %} | |
{% for h, OMIE in state_attr('sensor.omie_spot_price_pt', 'today_hours').items() -%} | |
{% set TAR = TAR_vazio if h.hour < 8 or h.hour > 21 else TAR_fora_vazio -%} | |
{% if OMIE == None %} | |
{% set price=OMIE %} | |
{% else %} | |
{% set price=((OMIE)*(1 + Perdas)*FA + QTarifa + TAR) /10 | round(2) %} | |
{% endif %} | |
{% set ns.hourly_data=ns.hourly_data + [(h.isoformat(), price)] %} | |
{% endfor -%} | |
{{ dict(ns.hourly_data) }} | |
tomorrow_hours: > | |
{% set Perdas = 0.15 -%} | |
{% set FA = 1.03 -%} | |
{% set QTarifa = 14.79 -%} | |
{% set TAR_vazio = 9.2 -%} | |
{% set TAR_fora_vazio = 50.2 -%} | |
{% set ns = namespace(hourly_data=[]) %} | |
{% for h, OMIE in state_attr('sensor.omie_spot_price_pt', 'tomorrow_hours').items() -%} | |
{% set TAR = TAR_vazio if h.hour < 8 or h.hour > 21 else TAR_fora_vazio -%} | |
{% if OMIE == None %} | |
{% set price=OMIE %} | |
{% else %} | |
{% set price=((OMIE)*(1 + Perdas)*FA + QTarifa + TAR) /10 | round(2) %} | |
{% endif %} | |
{% set ns.hourly_data=ns.hourly_data + [(h.isoformat(), price)] %} | |
{% endfor -%} | |
{{ dict(ns.hourly_data) }} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment