É só pegar no da luzboz da wiki e mudar a formula para ser identica à da MEO
Baseado no bi-horário coopérnico na Wiki e, desenvolvi o template para Tri-horário Semanal - Verão.
https://coopernico.org/ciclos_horarios
Deixo-o aqui para se quiserem adicioná-lo. Está a funcionar há uns dias e parece tudo ok.
Adicionei CS - Custos de Sistema e CR - Custos de regulação, conforme tarifário Coopérnico.
No “state” tive dificuldades a inserir a condição de minutos (Ponta das 9:15 às 12:15), porque sou nabo, então fui à volta e configurei a integração “Data & Hora” no modo “Hora” para usá-lo neste template. Já para os gráficos, ignoro os 15 minutos.
template:
- sensor
- unique_id: coopernico_spot_price_trihorario_semanal
unit_of_measurement: '€/MWh'
availability: "{{ has_value('sensor.omie_spot_price_pt') }}"
state_class: measurement
state: >
{% set PM = states('sensor.omie_spot_price_pt')|float -%}
{% set k = 9 -%}
{% set FP = 0.16 -%}
{% set TAR_ponta = 246.9 -%}
{% set TAR_cheia = 38.8 -%}
{% set TAR_vazio = 14.9 -%}
{% set TAR | float -%}
{% if now().weekday() >= 0 and now().weekday() < 5 -%}
{% if '09:15' < states('sensor.time') < '12:15' -%}
{{ TAR_ponta }}
{% elif '00:00' <= states('sensor.time') < '07:00' -%}
{{ TAR_vazio }}
{% else -%}
{{ TAR_cheia }}
{% endif -%}
{% elif now().weekday() == 5 -%}
{% if ('09:00' <= states('sensor.time') < '14:00') or ('20:00' <= states('sensor.time') < '22:00') -%}
{{ TAR_cheia }}
{% else -%}
{{ TAR_vazio }}
{% endif -%}
{% else -%}
{{ TAR_vazio }}
{% endif -%}
{% endset -%}
{% set CS = 2 -%}
{% set CR = 8 -%}
{{ ((PM + CGS + CS + CR + k)*(1 + FP) + TAR) | round(2) }}
attributes:
friendly_name: "Coopérnico Base (tarifário tri-horário semanal)"
formula: "((PM + CGS + CS + CR + k)*(1 + FP) + TAR)"
PM: "{{ states('sensor.omie_spot_price_pt')|float }}"
k: "{{ 9 }}"
FP: "{{ 0.16 }}"
TAR_Ponta: "{{ 246.9 }}"
TAR_Cheia: "{{ 38.8 }}"
TAR_Vazio: "{{ 14.9 }}"
CS: "{{ 2 }}"
CR: "{{ 8 }}"
today_hours: >
{% set k = 9 -%}
{% set FP = 0.16 -%}
{% set CS = 2 -%}
{% set CR = 8 -%}
{% set ns = namespace(hourly_data=[]) %}
{% for h, PM in state_attr('sensor.omie_spot_price_pt', 'today_hours').items() -%}
{% set TAR_ponta = 246.9 -%}
{% set TAR_cheia = 38.8 -%}
{% set TAR_vazio = 14.9 -%}
{% set TAR | float -%}
{% if now().weekday() >= 0 and now().weekday() < 5 -%}
{% if h.hour >= 9 and h.hour < 12 -%}
{{ TAR_ponta }}
{% elif h.hour >= 0 and h.hour < 7 -%}
{{ TAR_vazio }}
{% else -%}
{{ TAR_cheia }}
{% endif -%}
{% elif now().weekday() == 5 -%}
{% if (h.hour >= 9 and h.hour <14) or (h.hour >= 20 and h.hour <22) -%}
{{ TAR_cheia }}
{% else -%}
{{ TAR_vazio }}
{% endif -%}
{% else -%}
{{ TAR_vazio }}
{% endif -%}
{% endset -%}
{% if PM == None %}
{% set price=PM %}
{% else %}
{% set price=((PM + CGS + CS + CR + k)*(1 + FP) + TAR) | round(2) %}
{% endif %}
{% set ns.hourly_data=ns.hourly_data + [(h.isoformat(), price)] %}
{% endfor -%}
{{ dict(ns.hourly_data) }}
tomorrow_hours: >
{% set k = 9 -%}
{% set FP = 0.16 -%}
{% set CS = 2 -%}
{% set CR = 8 -%}
{% set ns = namespace(hourly_data=[]) %}
{% for h, PM in state_attr('sensor.omie_spot_price_pt', 'tomorrow_hours').items() -%}
{% set TAR_ponta = 246.9 -%}
{% set TAR_cheia = 38.8 -%}
{% set TAR_vazio = 14.9 -%}
{% set TAR | float -%}
{% if now().weekday() == 6 or now().weekday() < 4 -%}
{% if h.hour >= 9 and h.hour < 12 -%}
{{ TAR_ponta }}
{% elif h.hour >= 0 and h.hour < 7 -%}
{{ TAR_vazio }}
{% else -%}
{{ TAR_cheia }}
{% endif -%}
{% elif now().weekday() == 4 -%}
{% if (h.hour >= 9 and h.hour <14) or (h.hour >= 20 and h.hour <22) -%}
{{ TAR_cheia }}
{% else -%}
{{ TAR_vazio }}
{% endif -%}
{% else -%}
{{ TAR_vazio }}
{% endif -%}
{% endset -%}
{% if PM == None %}
{% set price=PM %}
{% else %}
{% set price=((PM + CGS + CS + CR + k)*(1 + FP) + TAR) | round(2) %}
{% endif %}
{% set ns.hourly_data=ns.hourly_data + [(h.isoformat(), price)] %}
{% endfor -%}
{{ dict(ns.hourly_data) }}
Consegues indicar algum bom tutorial de como posso usar o command_line para o efeito?
Obrigado
AL
Consigo mostrar o código que tenho:
command_line:
- sensor:
name: "Fator de Perdas"
command: "tail -n +2 /config/fperdas.csv"
scan_interval: 60 # Atualiza a cada minuto
command_timeout: 10
value_template: >-
{% set csv = value.split('\n') %}
{% set hoje = now().strftime('%Y-%m-%d') %}
{% set hora_atual = now().strftime('%H:%M') %}
{% for linha in csv if linha.startswith(hoje) %}
{% set dados = linha.split(';') %}
{% set intervalo = dados[1].split('-') %}
{% set inicio = intervalo[0] %}
{% set fim = intervalo[1] %}
{% if inicio <= hora_atual < fim %}
{{ dados[2] | replace(',', '.') | float }}
{% endif %}
{% endfor %}
Excelente!
O meu excel estava com outros formatos, o que me fez ter de aprender mais umas coisas.
Mas já está a funcionar!
Muito Obrigado,
AL