Skip to content

Nordpool (Home Assistant)

Jonas Karlsson edited this page Jan 12, 2025 · 5 revisions

To use the Home Assistant built-in Nordpool integration, as of Home Assistant 2025.1, the following template sensor can be used to create the price input.

Replace the value for config_entry with your config entry id. To find the config entry id, go to Developer Tools->Actions. Select the action "Nord Pool: Get prices for date". If in UI MODE, click on "GO TO YAML MODE", and your config entry id will be shown.

Replace the value for unit_of_measurement with your unit.

If the price should be in cents, replace the /1000 with /10 in three places.

template:
  - trigger:
      - trigger: time_pattern
        hours: "/1"
      - trigger: homeassistant
        event: start
    action:
      - action: nordpool.get_prices_for_date
        data:
          config_entry: 01JH61YFRGBCXRYEG0S9Q9F8AA_replace_with_your_config_entry
          date: "{{ now().date() }}"
        response_variable: today_prices
      - condition: template
        value_template: "{{ now().hour >= 14 }}"
      - action: nordpool.get_prices_for_date
        data:
          config_entry: 01JH61YFRGBCXRYEG0S9Q9F8AA_replace_with_your_config_entry
          date: "{{ now().date() + timedelta(days=1) }}"
        response_variable: tomorrow_prices
    sensor:
      - name: Nordpool prices
        unique_id: nordpool_prices
        unit_of_measurement: "EUR/kWh"
        state: "{{ today_prices[today_prices.keys()| list | first] | selectattr('start', '<=', utcnow().strftime('%Y-%m-%dT%H:%M:%S+00:00')) | map(attribute='price') | list | last | float/1000}}"
        attributes:
          prices_today: >
            {% if not today_prices %}
              []
            {% else %}
              {%- set forecast = today_prices[today_prices.keys()| list | first] %}
              {%- set time_key = 'start' %}
              {%- set price_key = 'price' %}
              {%- set ns = namespace(data=[]) %}
              {%- for i in forecast | default([], true) if as_local(as_datetime(i[time_key])).date() == now().date() %}
                {%- set ns.data = ns.data + [dict(time= as_local(as_datetime(i[time_key])).isoformat(), price = i[price_key]/1000 )] %}
              {%- endfor %}
              {{ ns.data }}
            {% endif %}
          prices_tomorrow: >
            {% if tomorrow_prices is not defined %}
              []
            {% else %}
              {% if not tomorrow_prices %}
                []
              {% else %}
                {%- set forecast = tomorrow_prices[tomorrow_prices.keys()| list | first] %}
                {%- set time_key = 'start' %}
                {%- set price_key = 'price' %}
                {%- set ns = namespace(data=[]) %}
                {%- for i in forecast | default([], true) if as_local(as_datetime(i[time_key])).date() == (now()+timedelta(days=1)).date() %}
                  {%- set ns.data = ns.data + [dict(time= as_local(as_datetime(i[time_key])).isoformat(), price = i[price_key]/1000 )] %}
                {%- endfor %}
                {{ ns.data }}
              {% endif %}
            {% endif %}