Any good ideas are welcome. Nordpool Energy Price per hour

Not sure it would be the best way, but you can make sensors for those, i.e.

        value_template: "{{(state_attr('sensor.nordpool_kwh_se3_sek_3_10_0', 'average') * 0.9) | round(2) }}"
        unit_of_measurement: Öre/kWh
    nordpool_average_high:
        value_template: "{{(state_attr('sensor.nordpool_kwh_se3_sek_3_10_0', 'average') * 1.1) | round(2) }}"
        unit_of_measurement: Öre/kWh 
1 Like

I am convinced You have better understanding of the code than I, but here is someone elses code i found and modified to suit my needs. Maybe it can give You some ideas?

{% set nordpoolSensor = "sensor.nordpool_kwh_se3_sek_3_10_0" %}
{% set priceData = namespace(numbers=[]) %}
{% for i in state_attr(nordpoolSensor,'raw_tomorrow') %}
  {% set priceData.numbers = priceData.numbers + [i.value] %}
{% endfor %}

{% set three_consecutive_hours = namespace(numbers=[]) %}
{% for n in range(7,21) %}
    {% set three_hour_sum = (priceData.numbers[n]+priceData.numbers[n+1]+priceData.numbers[n+2])|round(2) %}
    {% set three_consecutive_hours.numbers = three_consecutive_hours.numbers + [three_hour_sum] %}
{% endfor %}
{% set max_three_hour = min(three_consecutive_hours.numbers) %}
{% set most_expensive_hours = three_consecutive_hours.numbers.index(max_three_hour) %}
Sum of three consecutive hours:
{{three_consecutive_hours.numbers}}

cheapest 3 hours are from {{ most_expensive_hours+7 }} to {{ most_expensive_hours+10 }} o'clock
1 Like

I might misunderstand but the two sensors, lav and høy do not work. Why not?

template:

  - sensor:

      - name: "Nordpool gjennomstnittspris"

        state: "{{state_attr('sensor.nordpool_kwh_krsand_nok_2_09_025', 'average')}}"

  - sensor:

      - name: "Nordpool lav"

        state: "{{state_attr('sensor.nordpool_kwh_krsand_nok_2_09_025', 'average') * 0.9) | round(2) }}"

  - sensor:

      - name: "Nordpool høy"

        state: "{{state_attr('sensor.nordpool_kwh_krsand_nok_2_09_025', 'average') * 1.1) | round(2) }}"

remove the )

0.9 instead of 0.9)

Thank you! It works!

1 Like

Version 0.0.8 is out :partying_face:

Hi, has anyone experienced this problem - np shows price as 0, when it is very low.

np configuration is

sensor:
  - platform: nordpool

    # Should the prices include vat? Default True
    VAT: True

    # What currency the api fetches the prices in
    # this is only need if you want a sensor in a non local currecy
    currency: "EUR"

    # Helper so you can set your "low" price
    # low_price = hour_price < average * low_price_cutoff
    low_price_cutoff: 0.95

    # What power regions your are interested in.
    # Possible values: "DK1", "DK2", "FI", "LT", "LV", "Oslo", "Kr.sand", "Bergen", "Molde", "Tr.heim", "Tromsø", "SE1", "SE2", "SE3","SE4", "SYS", "EE"
    region: "EE"

    # How many decimals to use in the display of the price
    precision: 4

    # What the price should be displayed in default
    # Possible values: MWh, kWh and Wh
    # default: kWh
    price_type: kWh

    # This option allows the usage of a template to add a tariff.
    # now() always refers start of the hour of that price.
    # this way we can calculate the correct costs add that to graphs etc.
    # The price result of the additional_costs template expects this additional cost to be in kWh and not cents as a float
    # default {{0.0|float}}
    additional_costs: "{{0.0|float}}"

with tonights prices (as also in the raw_today list), the very low prices in bold:

today:

  • 0.1285
  • 0.1218
  • 0.0003
  • 0.0001
  • 0.0001
  • 0.0001
  • 0.116

Sensor norpool value shows as 0.0. Either it cannot take into account the precision 4 or something else wrong? Or am I missing something?

1 Like

Why isn’t items like current_price etc, following the precision specification? When trying to use current_price as a comparison with something it only has 2 decimals which actually makes everything wrong if you set your precision to 3 or 4 decimals, like in my case in Sweden when I use SEK and the prices are in 10th of SEK/kWh.
Edit: When using it in developer I get the decimals. but when looking at attributes in Entity, I don’t?

Is there some simple way to find x cheapest hour between now and 7:00 morning?

This would be useful for EV charging. I have entity for EV battery, and charging rate is 10%/h. So when battery is at 65%, needed charging time would be 3h30min, not necessarily consecutive hours…

Check this solution: https://www.creatingsmarthome.com/

will your code check the cheapest hour ex. from 21.00 to the next day at 21.00 ? so it uses today and tomorrow prices?

This looks for cheapest sequential hours? It would be even better if i somehow could charge ev at absolutely cheapest hours. For example charging 4 hours could be at 22-23, 01-03 and 04-05.

1 Like

‘’’
Hi,

It is actually not my code…so no credits, nor questions, to me :wink:
You will have to analyse the code yourself.

greetz,

Jan
‘’’

"
Hi,

It is actually not my code…so no credits, nor questions, to me :wink:
You will have to analyse the code yourself.

greetz,

Jan

"

Hi! I have moved to mariadb and lost all the history, that’s not too bad but I was wondering, is there a way to get a 30 day history of the nordpool price in a graph? As of now it started from today but like to get 29 previous days in the graph also.

You can use a markdown card for that.
Just change the nordpool sensor and the time.

(cheapest hour today)

{% set priceList = state_attr('sensor.nordpool_kwh_fi_eur_3_10_024', 'today')[8:22] %}
{% set dateList = state_attr('sensor.nordpool_kwh_fi_eur_3_10_024', 'raw_today')[8:22] %}
{% set minPrice = min(priceList) %}
{% set minIndex = priceList.index(minPrice) %}
{% set minDateTimeStr= dateList[minIndex].start | string %}
{% set minDateTime= strptime(minDateTimeStr[0:19], '%Y-%m-%d %H:%M:%S') %}

Billigaste priset idag mellan 07-22 och är {{ minPrice }} EUR/kWh och startar kl {{ minDateTime.hour }}:00

(cheapest hour tomorrow)



{% set priceList = state_attr('sensor.nordpool_kwh_fi_eur_3_10_024', 'tomorrow')[8:22] %}
{% set dateList = state_attr('sensor.nordpool_kwh_fi_eur_3_10_024', 'raw_tomorrow')[8:22] %}
{% set minPrice = min(priceList) %}
{% set minIndex = priceList.index(minPrice) %}
{% set minDateTimeStr= dateList[minIndex].start | string %}
{% set minDateTime= strptime(minDateTimeStr[0:19], '%Y-%m-%d %H:%M:%S') %}

Billigaste priset mellan 07-22 imorgon är {{ minPrice }} EUR/kWh och startar kl {{ minDateTime.hour }}:00

image

And here is for tomorrow cheapest 2 hours from 00:00-24:00
Just change {% set num_hours = 2 | int %} to whatever you want.

      {% set iterativesum = namespace(iter=[]) %}

      {% set lowestiter = namespace(kr=2) %}

      {% set timelowest = namespace(hr=2) %}

      {% set highestiter = namespace(kr=0) %}

      {% set timehighest = namespace(hr=0) %}

      {% set num_hours = 2 | int %}

      {% set nordpoolentity = 'sensor.nordpool_kwh_fi_eur_3_10_024' %}

      {% set timemapper = {

      0: '00:00',

      1 : '01:00',

      2 : '02:00',

      3 : '03:00',

      4 : '04:00',

      5 : '05:00',

      6 : '06:00',

      7 : '07:00',

      8 : '08:00',

      9 : '09:00',

      10 : '10:00',

      11 : '11:00',

      12 : '12:00',

      13 : '13:00',

      14 : '14:00',

      15 : '15:00',

      16 : '16:00',

      17 : '17:00',

      18 : '18:00',

      19 : '19:00',

      20 : '20:00',

      21 : '21:00',

      22 : '22:00',

      23 : '23:00',

      24: '00:00',

      25 : '01:00',

      26 : '02:00',

      27 : '03:00',

      28 : '04:00',

      29 : '05:00',

      30 : '06:00',

      31 : '07:00',

      32 : '08:00',

      33 : '09:00',

      34 : '10:00',
      35 : '11:00',

      36 : '12:00',

      37 : '13:00',

      38 : '14:00',

      39 : '15:00',

      40 : '16:00',

      41 : '17:00',

      42 : '18:00',

      43 : '19:00',

      44 : '20:00',

      45 : '21:00',

      46 : '22:00',

      47 : '23:00',

      48 : '0:00',

      } %}

      {% set prices = namespace(price=[]) %}

      {% set prices.price = prices.price + state_attr(nordpoolentity, 'today')
      %}
      {%- if state_attr(nordpoolentity,'tomorrow') | length == 1 -%}
      Morgondagens priser ej släppta

      {% else %}

      {% set prices.price = prices.price + state_attr(nordpoolentity,
      'tomorrow') %}

      {% endif %}

      {%- for n in range(prices.price|length -num_hours +1) -%}

      {%- set tempsum= namespace(temp=0) -%}

      {%- for i in range(num_hours) -%}

      {%- set tempsum.temp = tempsum.temp + prices.price[n+i] -%}

      {% endfor -%}

      {% set iterativesum.iter = iterativesum.iter + [tempsum.temp] -%}

      {% endfor -%}

      {% for iter in iterativesum.iter -%}

      {%- if loop.index > now().hour -%}

      {%- if iter < lowestiter.kr | float -%}

      {%- set lowestiter.kr = iter | float -%}

      {%- set timelowest.hr = loop.index -1 -%}

      {%- endif -%}
      {%- if iter > highestiter.kr | float -%}

      {%- set highestiter.kr = iter | float -%}

      {%- set timehighest.hr = loop.index -1 -%}

      {%- endif -%}

      {%- endif -%}

      {% endfor -%}
      De billigaste {{num_hours}}-timmarna startar {% if (timelowest.hr < 24)
      %}idag{% else %}imorgon{% endif %} kl {{timemapper[timelowest.hr]}}, då
      snittpriset är {{"%.2f"|format(lowestiter.kr/num_hours)}} cent/kWh
      De dyraste {{num_hours}}-timmarna startar {% if (timehighest.hr < 24)
      %}idag{% else %}imorgon{% endif %} kl {{timemapper[timehighest.hr]}}, då
      snittpriset är {{"%.2f"|format(highestiter.kr/num_hours)}} cent/kWh

2 Likes

I have mungled in template editor for hours and got this. Have not yet tested irl, as i am not really experienced with home assistant. Is this ok, or have i gone horribly wrong somewhere?

{% if now().hour < 7 %}
{% set prices = (state_attr('sensor.nordpool_kwh_fi_eur_3_10_024', 'today')[now().hour:7]| sort(false)) %}
{%- else -%}
{% set prices = ((state_attr('sensor.nordpool_kwh_fi_eur_3_10_024', 'today')[now().hour:24]|list + state_attr('sensor.nordpool_kwh_fi_eur_3_10_024', 'tomorrow')[0:7]|list)| sort(false)) %}
{%- endif %}
{{ state_attr('sensor.nordpool_kwh_fi_eur_3_10_024', 'current_price') <= (prices[((states("sensor.kona_target_capacity_of_charge_ac")|float - states("sensor.kona_ev_battery")|float)/10)|round(0,"floor")]) }}

It calculates charging time from ev target charge - ev battery, 10%/hour. For example target is 80%, battery is at 54% → 2.6 hours (rounded up to 3).

This gives out True if now is one of 3 cheapest hour between now and tomorrow 7:00. This i think could be used to turn charger on and off.

1 Like

Do your top Numbers - max, min average - match the graph? Are you using any template for additionel costs?

Have made mine based on yours and i have som issue with the top and graph I cant wrap my head around

Hello.
I have used the code, for calculating cheapest sequencial hours, for morning, afternoon and evening. To turn on/off my air to air heating pump.
And its works for morning and afternoon. But the calculation for the evening, cheapeste hour, is wrong. It’s not chosing the 3 cheapest hours, that i won it to. Its a longer period it choosing. For example 7pm to 7 am, next morning.

image

This is the code i’am using

#Nordpool billigste timer aften

  • platform: template
    sensors:
    cheapest_hours_energy_tomorrow_third:
    device_class: timestamp
    friendly_name: Cheapest sequential electricity hours third
    value_template: >
    {%- set numberOfSequentialHours = 3 -%}
    {%- set lastHour = 23 -%}
    {%- set firstHour = 16 -%}
    {%- if state_attr(‘sensor.nordpool_kwh_dk2_dkk_3_10_025’, ‘tomorrow_valid’) == true -%}
    {%- set ns = namespace(counter=0, list=[], cheapestHour=today_at(“00:00”) + timedelta( hours = (24)), cheapestPrice=999.00) -%}
    {%- for i in range(firstHour + numberOfSequentialHours, lastHour+1) -%}
    {%- set ns.counter = 0.0 -%}
    {%- for j in range(i-numberOfSequentialHours, i) -%}
    {%- set ns.counter = ns.counter + state_attr(‘sensor.nordpool_kwh_dk2_dkk_3_10_025’, ‘tomorrow’)[j] -%}
    {%- endfor -%}
    {%- set ns.list = ns.list + [ns.counter] -%}
    {%- if ns.counter < ns.cheapestPrice -%}
    {%- set ns.cheapestPrice = ns.counter -%}
    {%- set ns.cheapestHour = today_at(“00:00”) + timedelta( hours = (24 + i - numberOfSequentialHours)) -%}
    {%- endif -%}
    {%- endfor -%}
    {{ ns.cheapestHour }}
    {%- set ns.cheapestPrice = ns.cheapestPrice / numberOfSequentialHours -%}
    {%- endif -%}
This is the automation for fetching the nordpool data.

#automation:

  • id: ‘1663398489324’
    alias: ‘Set device/end start time third’
    description: ‘’
    trigger:
    • platform: time
      at: ‘23:15:00’
      condition:
    • condition: not
      conditions:
      • condition: state
        entity_id: sensor.cheapest_hours_energy_tomorrow_third
        state: unknown
        action:
    • service: input_datetime.set_datetime
      data:
      time: ‘{{ as_timestamp(states(’‘sensor.cheapest_hours_energy_tomorrow_third’’)) | timestamp_custom(’’%H:%M’’) }}’
      target:
      entity_id: input_datetime.device_start_time_third
    • service: input_datetime.set_datetime
      data:

      CHANGE-ME: 3 (3600*3) is the number of sequential cheapest hours we are looking for

      time: ‘{{ ((as_timestamp(states(’‘sensor.cheapest_hours_energy_tomorrow’’)) + (3600*3)) | timestamp_custom(’’%H:%M’’)) }}’
      target:
      entity_id: input_datetime.device_end_time_third
      mode: single
Hope that any of you, are able to spot my mistake.

Thanks

Can I sneak in a question there? I added the additional costs to the sensor, but accidentally wrote the value Swedish Öre instead of SEK, so it got a measurement 100 times as large as expected and that one has now polluted my data so I have a huge spike in the graph. I found the “state” row in the database and removed that one, but the spike is still there. Where does apexcharts get the datapoints for this sensor from?