Skip to content

Instantly share code, notes, and snippets.

@matthiasnys
Last active January 21, 2025 07:20
Show Gist options
  • Select an option

  • Save matthiasnys/f3689fc29c10593ecaee5a6c188bf218 to your computer and use it in GitHub Desktop.

Select an option

Save matthiasnys/f3689fc29c10593ecaee5a6c188bf218 to your computer and use it in GitHub Desktop.
ELIA Rates
# ELIA electricity rates configuration
sensor:
# REST sensor to fetch ELIA data
- platform: rest
name: elia_spot_prices_raw
resource_template: "https://griddata.elia.be/eliabecontrols.prod/interface/Interconnections/daily/auctionresultsqh/{{ now().strftime('%Y-%m-%d') }}"
scan_interval: 3600
json_attributes:
- dateTime
- price
value_template: >-
{% set current_hour = now().strftime('%Y-%m-%dT%H:00:00Z') %}
{% for item in value_json %}
{% if item.dateTime == current_hour %}
{{ item.price }}
{% endif %}
{% endfor %}
# Template sensors for price calculations
- platform: template
sensors:
elia_current_price:
friendly_name: "Current Electricity Price"
unit_of_measurement: "€/kWh"
device_class: monetary
value_template: >-
{% set constants = namespace(
GREEN_EURO_KWH=0.0109963099630996,
WKK_EURO_KWH=0.00391143911439114,
NETWORK_EURO_KWH=0.05384,
ENERGY_TAX_EURO_KWH=0.00191881918819188,
FEDERAL_TAX_EURO_KWH=0.0142066420664207,
VAT_PERCENTAGE=21
) %}
{% set spot_price = states('sensor.elia_spot_prices_raw') | float %}
{% if spot_price > 0 %}
{# Calculate energy per kWh: (1.100 + (0.1000 * spot_price)) / 100 #}
{% set energy_per_kwh = (1.100 + (0.1000 * spot_price)) / 100 %}
{# Add all components #}
{% set price_per_kwh = energy_per_kwh +
constants.WKK_EURO_KWH +
constants.NETWORK_EURO_KWH +
constants.GREEN_EURO_KWH +
constants.ENERGY_TAX_EURO_KWH +
constants.FEDERAL_TAX_EURO_KWH %}
{# Add VAT #}
{% set final_price = (price_per_kwh * (100 + constants.VAT_PERCENTAGE)) / 100 %}
{{ (final_price | round(4)) }}
{% else %}
{{ 0 | round(4) }}
{% endif %}
elia_return_price:
friendly_name: "Current Return Price"
unit_of_measurement: "€/kWh"
device_class: monetary
value_template: >-
{% set constants = namespace(VAT_PERCENTAGE=21) %}
{% set spot_price = states('sensor.elia_spot_prices_raw') | float %}
{% if spot_price > 0 %}
{# Calculate return energy per kWh: (-0.9050 + (0.1000 * spot_price)) / 100 #}
{% set energy_per_kwh = (-0.9050 + (0.1000 * spot_price)) / 100 %}
{# Add VAT #}
{% set final_price = (energy_per_kwh * (100 + constants.VAT_PERCENTAGE)) / 100 %}
{{ (final_price | round(4)) }}
{% else %}
{{ 0 | round(4) }}
{% endif %}
elia_daily_stats:
friendly_name: "Daily Price Statistics"
value_template: >-
{% set prices = state_attr('sensor.elia_spot_prices_raw', 'price') | default([]) %}
{% if prices %}
{% set converted_prices = [] %}
{% for spot_price in prices %}
{% set constants = namespace(
GREEN_EURO_KWH=0.0109963099630996,
WKK_EURO_KWH=0.00391143911439114,
NETWORK_EURO_KWH=0.05384,
ENERGY_TAX_EURO_KWH=0.00191881918819188,
FEDERAL_TAX_EURO_KWH=0.0142066420664207,
VAT_PERCENTAGE=21
) %}
{% set energy_per_kwh = (1.100 + (0.1000 * spot_price)) / 100 %}
{% set price_per_kwh = energy_per_kwh +
constants.WKK_EURO_KWH +
constants.NETWORK_EURO_KWH +
constants.GREEN_EURO_KWH +
constants.ENERGY_TAX_EURO_KWH +
constants.FEDERAL_TAX_EURO_KWH %}
{% set final_price = (price_per_kwh * (100 + constants.VAT_PERCENTAGE)) / 100 %}
{% set converted_prices = converted_prices.append(final_price) %}
{% endfor %}
Min: {{ (converted_prices | min | round(4)) }} €/kWh,
Max: {{ (converted_prices | max | round(4)) }} €/kWh,
Avg: {{ ((converted_prices | sum) / (converted_prices | length) | round(4)) }} €/kWh
{% else %}
No data available
{% endif %}
# Automation to update prices
automation:
- alias: "Update ELIA Prices"
description: "Updates ELIA prices every hour and at midnight"
trigger:
# Update at midnight
- platform: time
at: "00:00:00"
# Update every hour
- platform: time_pattern
hours: "*"
action:
- service: homeassistant.update_entity
target:
entity_id: sensor.elia_spot_prices_raw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment