Any good ideas are welcome. Nordpool Energy Price per hour

Have you set up Nordpool via the UI or YAML?
I set it up with the UI and defined precision as 3 and to show price in cents, which seem to be “øre”.

This is a bit “hacky”, but if you go into “.storage/core.config_entries” and search for Nordpool you can compare with my details. If you make any changes, make sure that you have your backups sorted.
Please ignore the additional costs entry as the uses some of my own template sensors.

            {
                "entry_id": "06d6f13d2339de15fe6fb831f5fb2275",
                "version": 1,
                "domain": "nordpool",
                "title": "Nordpool",
                "data": {
                    "region": "Tr.heim",
                    "currency": "NOK",
                    "VAT": true,
                    "precision": 3,
                    "low_price_cutoff": 1.0,
                    "price_in_cents": true,
                    "price_type": "kWh",
                    "additional_costs": "{{ ((states('sensor.tariff_price_excl_mva')|float)-(states('input_number.rabatt_pr_kwh')|float) | round(3)) /100 }}"
                },
                "options": {},
                "pref_disable_new_entities": false,
                "pref_disable_polling": false,
                "source": "user",
                "unique_id": null,
                "disabled_by": null
            },

Did you solve this? Would it not help if you used median instead of average?

The median is the middle number in a data set. To find the median, list your data points in ascending order and then find the middle number. The middle number in this set is 28 as there are 4 numbers below it and 4 numbers above:
23, 24, 26, 26, 28, 29, 30, 31, 33

Note*: If you have an even set of numbers, average the middle two to find the median. For example, the median of this set of numbers is 28.5 (28 + 29 / 2).
23, 24, 26, 26, 28, 29, 30, 31, 33, 34

One more question regarding this. How do I do then I want to reduce the decimals to 3?

Using the built in command prompt i can not seem to find the .storage folder.

I do know basic linux commands, but i am unable to find that directory ?

I am trying to create a custom list of hourly prices from nordpool data, but I am stuck with list item updates/creating a custom list.

My air/water heat pump does not accomplish much in an hour, as first priority is always DHW production. And price fluctuations do not make sence for me to look at only 1 hour prices. Also rounding the prices makes sence, as I do not really care if price is 71,73,74 - 70 would do better for average/median price calculations.

The idea is to sum 00-01 and 01-02 hourly prices together, creating a list of bi-hourly items with same start, end and hourly price attribute values like in nordpool sensor raw data. Hourly price value would be average of the two hours’ prices for the bi-hour values.

Then I would mround the prices and take median price - to get a price level eliminating high peaks for allowing normal operation of heat pump or stopping it. Also I would like to set a low price level to boost the air/water pump operation when price is low - most probably “below average” would be sufficient.

{% set l=state_attr('sensor.nordpool_kwh_ee_eur_4_095_02', 'raw_today')|sort(attribute='value') %}

{{ l[(11)].value*100 }} value at 12
{{ l[(12)].value*100 }} value at 13
{% set a=(l[(12)].value + l[(11)].value)/2 %}
Mean 24h is : {{ a }}

{##% set l[(12)].value= l[(13)].value %##}
{{ l[(12)].value*100 }} new value at 12

In the above, the line I have commented out does not work. I cannot set a new value to list at 12 like this. What could be wrong or what do you suggest as a solution?

1 Like

Please be aware that you may destroy things by editing directly in that file. You could consider reinstalling the Integration via UI and try to define accuracy and units there.

If you want to go the “hacky” route, this is what I use:
I am using the “Studio Code Server” add-on to browse and edit files directly in the browser.
You could also use the “File Editor”. It’s a bit crude and frustrating to use on the phone, but OK on a computer.

The “.” in front of the folder name defines this folder as a hidden folder. I am not so familiar with Linux yet, but I guess there should be an option to show hidden files and folders.
Some relevant info may possibly be found here.

Got the graph working, I’ve used the Apex.Graph, looks nice :slight_smile:
But the sensor and graph are showing wrong prices.
Wonder what I have done wrong?

you can change currency and country in configuration.yaml file

I would like to have a calculation based on my own real usage to show how much I would save/loose on either fix or nord-pool market price contract.

Does anyone have a solution for calculating the daily/monthly cost using nordpool data? I know I can enter the NP sensor current price to HA-Energy conf. tab, but this is not suiting my needs as I cannot extract the cost from there (I think). I would like to have a custom “cost-meter” where I can manipulate the price better.

a) For power coming from NP price grid - one calculation with NP price as current price cost entity x my consumed energy.
b) For power coming from a fixed price grid - another calculation with fixed price tariffs (day/night) x my consumed energy
c) and then a third calculation showing the difference (profit/loss) either daily/monthly or similar.

I do not need this to be possible on historical data.

Is there some readymade solution for this? Or can I adapt utility meter or some other solution? I would not want to build a custom solution for NP price calculation using hourly meters and multiplying the hourly usage with previous hour’s price.

1 Like

This seems a little bit off. I’m looking at SE4 and the integration is giving me 0.2 SEK/kWh (15:00-16:00) but if I look at Nordpool on the same time it gives me 15,05 EUR/MWh. 15,05 euro to sek = 159,52 / 1000 (to get kWh) = 0.15952. So I guess that would be 0.16SEK/kWh? Or am I missing something?

I try to change font-size and numbers of decimals for attribute “average” in “Entity”. Shall I do that in config or Card_mod and pleace help me with code.

I am hoping to be able to display the previous, current and the 2 next hours prices in my dashboard.
Is there a way to create sensors for these?

Yes, but needs a bit of coding

  • Current - you have it from NP data
  • For previous - update the sensor or input number value so that it is written to be current price at each hour, 59 minutes 55 seconds for instance, this is easiest.
  • Next 2 hours - you have to access the raw prices list and do calculations there, a bit more tricky. Get current hour, find it from the list, take the next 2 elements from list…

Complety neewbie here, but I’m not the only one I can see :slight_smile:

I want to get this running: https://github.com/custom-components/nordpool

It works fine, but what I cannot get to work is the additional_costs (by using a constant it works fine) But I need to change the value at 17 to 20 clock everydya, and that I cannot get to work, can anybody point me in direction on what I do wrong?

This is my configuration.yaml

########################################
# Configure a default setup of Home Assistant (frontend, api, etc)
########################################
default_config:
########################################
# THEMES SETUP
########################################
frontend:
  themes: !include_dir_merge_named themes
  
########################################
# Text to speech SETUP
########################################
tts:
  - platform: google_translate

########################################
# includes
########################################
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
#sensor: !include sensor.yaml

########################################
# DANFOSS VENTILATION SETUP
########################################
danfoss_air:
  host: 192.168.86.36
  
########################################
# KNX SETUP
########################################
knx:
  light:
    - name: "Kontor"
      address: "0/1/20"
  switch:
    - name: "Cooper_pluged_in"
      address: "15/1/0"     
#sensor:


########################################
# NORDPOOL SETUP
# konstant_net_tariff = 0.17,
# Elselskab_tariff = 0, -- changed to vindstød, they do not charge extra
# Stat_nedsat_tariff = 0.15,
# Stat_ikke_nedsat_tariff = 0.28,
# Konstant_ekstra_tariff_17_20 = 0.18,
########################################
sensor:
  - platform: nordpool
    VAT: True
    currency: "DKK"
    low_price_cutoff: 0.95
    region: "DK1"
    precision: 3 
    price_type: kWh
    friendly_name: "Strøm Priser"
#    additional_costs: "{{0.6|float}}"
    additional_costs: '{% set s = {
      "konstant_net_tariff": 0.17,
      "konstant_rush_hour_17_20": 0.18,
      "elselskab_tariff": 0.0,
      "stat_nedsat_tariff: 0.15,
      "stat_ikke_nedsat_tariff": 0.28}
      %}
      {% if now().hour >= 17 and now().hour <= 19 %} 
        {{s.konstant_net_tariff + s.elselskab_tariff + s.stat_nedsat_tariff + s.stat_ikke_nedsat_tariff + konstant_rush_hour_17_20|float}}
      {% else %}
        {{s.konstant_net_tariff + s.elselskab_tariff + s.stat_nedsat_tariff + s.stat_ikke_nedsat_tariff|float}}
        {% endif %}'
  
########################################
# Ford Mustang Mach - E SETUP
########################################
  - platform: template
    sensors:
      ford_hv_battery_percent:
        friendly_name: "Batteriniveau"
        value_template: "{{ state_attr('sensor.fordpass_elveh', 'Battery Fill Level') }}"
        unit_of_measurement: "%"
        icon_template: mdi:map-marker-distance            
        device_class: battery
        
      ford_12v_battery:
        friendly_name: "12V batteri spænding"
        value_template: "{{ state_attr('sensor.fordpass_battery', 'Battery Voltage') }}"
        unit_of_measurement: "Volt"
        device_class: battery
              
      ford_distance_to_empty_template:
        friendly_name: "Afstand til tom"
        value_template: "{{ (state_attr('sensor.fordpass_elveh', 'elVehDTE')) | round(0) }}"
        unit_of_measurement: "Km"
        icon_template: mdi:map-marker-distance            
        device_class: battery
      
      ford_plug_status:
        friendly_name: "Tilsluttet lader"
        icon_template: mdi:ev-plug-ccs2
        value_template: >-
          {% if is_state_attr('sensor.fordpass_elveh', 'Plug Status', 0) %}
            Unplugged
          {% elif is_state_attr('sensor.fordpass_elveh', 'Plug Status', 1) %}
            Plugged In
          {% else %}
          {% endif %}

Hi Tue!
Experienced the same issue as you until a few minutes ago :slight_smile: THe problem by changing the constants the name also change which will mean that automation’s using the sensor will break… When i was answering your post i realized that you can create several instances of the sensor by just adding several blocks in your config.yaml. It is not as clean as sending parameters but i would guess that it works. I just tried to create one additional sensor with another threshold and it seems to work.
What do you think?

I’ve just added these sensors into template.yaml to test:

  • name: endhour_kwh_nok
    unit_of_measurement: NOK/kWh
    state: ‘{{ states(’‘sensor.nordpool_kwh_krsand_nok_3_095_025’’) if now().minute == 59 else states(’‘sensor.endhour_kwh_nok’’)}}’
  • name: lasthour_kwh_nok
    unit_of_measurement: NOK/kWh
    state: ‘{{ states(’‘sensor.endhour_kwh_nok’’) if now().minute == 0 else states(’‘sensor.lasthour_kwh_nok’’)}}’
  • name: nexthour_kwh_nok
    unit_of_measurement: NOK/kWh
    state: ‘{{ state_attr(’‘sensor.nordpool_kwh_krsand_nok_3_095_025’’,’‘today’’)[now().hour+1] if now().hour < 23 else state_attr(’‘sensor.nordpool_kwh_krsand_nok_3_095_025’’,’‘tomorrow’’)[now().hour+1-24] }}’

In theory, endhour_kwh_nok should be updated at at XX:59, and then lasthour_kwh_nok should be updated at XX:00.
I’ll leave it up to gasolli or anyone else to create a sensor nextsecondhour_kwh_nok.

One problem is after the templates has been reloaded, endhour_kwh_nok and lasthour_kwh_nok will be unknown. This can be helped with an automation that stores endhour_kwh_nok in the helper lasthour_kwh_nok at the beginning of each hour.

I’ve started to work on something not exactly that but it could be built further I believe. Work and family consumes a lot of time… So far its three sensors, past 72h mean, past72h median and today median. In my head it should be easy to add past and today and use it as a value.
Anyway im not sure witch of the three is the best approach for the level calculation any input on that would be nice

    region: "SE3"
  - platform: statistics
    name: "Elpris_medel_past72"
    unique_id: 50371632
    entity_id: sensor.nordpool_kwh_se3_sek_3_10_025
    state_characteristic: mean
    precision: 4
    sampling_size: 144
    max_age:
      hours: 72
  - platform: template
    sensors:
      pricelevel_medel_past72:
        unique_id: 76937444
        friendly_name: "Elprisnivå_medel_past72"
        unit_of_measurement: 'Level'
        value_template: >-
            {% if states('sensor.nordpool_kwh_se3_sek_3_10_025')|float(0.5) >= states('sensor.elpris_medel_past72')|float(0.5) *0.9
                and states('sensor.nordpool_kwh_se3_sek_3_10_025')|float(0.5) < states('sensor.elpris_medel_past72')|float(0.5) *1.15 %}
                {{3}}
            {% elif states('sensor.nordpool_kwh_se3_sek_3_10_025')|float >= states('sensor.elpris_medel_past72')|float *0.6
                and states('sensor.nordpool_kwh_se3_sek_3_10_025')|float < states('sensor.elpris_medel_past72')|float *0.9 %}
                {{2}}
            {% elif states('sensor.nordpool_kwh_se3_sek_3_10_025')|float < states('sensor.elpris_medel_past72')|float *0.6 %}
                {{1}}
            {% elif states('sensor.nordpool_kwh_se3_sek_3_10_025')|float >= states('sensor.elpris_medel_past72')|float *1.15
                and states('sensor.nordpool_kwh_se3_sek_3_10_025')|float < states('sensor.elpris_medel_past72')|float *1.4 %}
                {{4}}
            {% elif states('sensor.nordpool_kwh_se3_sek_3_10_025')|float >= states('sensor.elpris_medel_past72')|float *1.4 %}
                {{5}}
            {% endif %}
  - platform: statistics
    name: "Elpris_median_past72"
    unique_id: 70542100
    entity_id: sensor.nordpool_kwh_se3_sek_3_10_025
    state_characteristic: median
    precision: 4
    sampling_size: 144
    max_age:
      hours: 72
  - platform: template
    sensors:
      pricelevel_median_past72:
        unique_id: 33469883
        friendly_name: "Elprisnivå_median_past72"
        unit_of_measurement: 'Level'
        value_template: >-
            {% if states('sensor.nordpool_kwh_se3_sek_3_10_025')|float(0.5) >= states('sensor.Elpris_median_past72')|float(0.5) *0.9
                and states('sensor.nordpool_kwh_se3_sek_3_10_025')|float(0.5) < states('sensor.Elpris_median_past72')|float(0.5) *1.15 %}
                {{3}}
            {% elif states('sensor.nordpool_kwh_se3_sek_3_10_025')|float >= states('sensor.Elpris_median_past72')|float *0.6
                and states('sensor.nordpool_kwh_se3_sek_3_10_025')|float < states('sensor.Elpris_median_past72')|float *0.9 %}
                {{2}}
            {% elif states('sensor.nordpool_kwh_se3_sek_3_10_025')|float < states('sensor.Elpris_median_past72')|float *0.6 %}
                {{1}}
            {% elif states('sensor.nordpool_kwh_se3_sek_3_10_025')|float >= states('sensor.Elpris_median_past72')|float *1.15
                and states('sensor.nordpool_kwh_se3_sek_3_10_025')|float < states('sensor.Elpris_median_past72')|float *1.4 %}
                {{4}}
            {% elif states('sensor.nordpool_kwh_se3_sek_3_10_025')|float >= states('sensor.Elpris_median_past72')|float *1.4 %}
                {{5}}
            {% endif %}
  - platform: template
    sensors:
      pricelevel_median_today:
        friendly_name: "Elprisnivå_median_today"
        unique_id: 95789542
        unit_of_measurement: 'Level'
        value_template: >-
            {% set today=states.sensor.nordpool_kwh_se3_sek_3_10_025.attributes.raw_today| sort(attribute='value')-%}
            {%set median= (today[11].value+today[12].value)/2%}
            {% if states('sensor.nordpool_kwh_se3_sek_3_10_025')|float(0.5) >= median|float(0.5) *0.9
                and states('sensor.nordpool_kwh_se3_sek_3_10_025')|float(0.5) < median|float(0.5) *1.15 %}
                {{3}}
            {% elif states('sensor.nordpool_kwh_se3_sek_3_10_025')|float >= median|float *0.6
                and states('sensor.nordpool_kwh_se3_sek_3_10_025')|float < median|float *0.9 %}
                {{2}}
            {% elif states('sensor.nordpool_kwh_se3_sek_3_10_025')|float < median|float *0.6 %}
                {{1}}
            {% elif states('sensor.nordpool_kwh_se3_sek_3_10_025')|float >= median|float *1.15
                and states('sensor.nordpool_kwh_se3_sek_3_10_025')|float < median|float *1.4 %}
                {{4}}
            {% elif states('sensor.nordpool_kwh_se3_sek_3_10_025')|float >= median|float *1.4 %}
                {{5}}
            {% endif %}
  - platform: template
    sensors:
      elpris_median_today:
        friendly_name: "Elpris_median_today"
        unique_id: 89574231
        unit_of_measurement: 'SEK/kWh'
        value_template: >-
            {% set today=states.sensor.nordpool_kwh_se3_sek_3_10_025.attributes.raw_today| sort(attribute='value')-%}
            {%set median= (today[11].value+today[12].value)/2%}
            {{median}}
1 Like

Here’s the code I ended up with using for an average of the last 72 hours + tomorrow. Now that I look at it I see that I may not have included the prices of today that have not yet occured.

  - platform: statistics
    name: "elpris_3d_snitt"
    state_characteristic: mean
    entity_id: sensor.nordpool_kwh_se3_sek_5_095_025
    precision: 5
    sampling_size: 144
    max_age:
      hours: 72

template:
  - sensor:
      - name: elpris_long_avg
        unit_of_measurement: 'SEK/kWh'
        state: >- 
          {% set pasthours = 72 %}
          {% set prices=state_attr('sensor.nordpool_kwh_se3_sek_5_095_025', 'raw_today') + state_attr('sensor.nordpool_kwh_se3_sek_5_095_025', 'raw_tomorrow') -%}
          {% set list = namespace(prices=[]) -%}
          {% set pastavg = states('sensor.elpris_3d_snitt')|float(default=0.5) %}
          {% for price in prices -%}
            {%- if price.end > now() -%}{% set list.prices = list.prices + [price] -%}{%- endif -%}
          {% endfor -%}
          {% set futureprices = (list.prices | map(attribute='value')|join(',')).split(',') -%}
          {% set past_count = (state_attr('sensor.elpris_3d_snitt', 'age_coverage_ratio')|float(default=0))*pasthours %}
          {% set pastweighted = pastavg*past_count %}
          {% set futuresum = (list.prices | sum(attribute='value'))-futureprices[0]|float-%}
          {% set future_count = (futureprices | count)-1 %}
          {% set futureavg = futuresum/future_count %}
          {% set futureweighted = futureavg*future_count %}
          {% set longavg = (pastweighted+futureweighted)/(past_count+future_count) %}
          {{ longavg | round(5, default=1) }}

Edit: Updated code to redact current hour from list of future prices. A more elegant way would perhaps be to add an hour to the timezone offset, but I’m not sure how to do that.

1 Like

Hi

For future refererence if someone comes in here with this problem.

I had set the color scheme to show green from 0 to 0,8 in my currency

Suddenly it would not show, but when i looked at Nordpool i saw negative numbers.

So i set the green to be from -2 to 0,8 and now it show correctly again.

So basically today is going to be sunny and windy to the point where i will GET money for getting power.

Sadly, when the price is -0,2 this still means that i have to pay the 1,5 in electricity tax to the state, so the price will still be about 1,3 but if i had an electric car, and no solar cells this would be the time i would charge. :slight_smile:

For them that might need it, I have tweaked a template I found on the net somwhere (can not give the right guy credit, sorry):

{% set today_price = states.sensor.nordpool_kwh_dk1_dkk_2_095_025.attributes.today %}
{% set tomorrow_price = states.sensor.nordpool_kwh_dk1_dkk_2_095_025.attributes.tomorrow %}
{% set ev_car_battery_size =  89 -%}
{% set ev_car_end_charge_level  = 100 -%}
{% set ev_car_battery_charge_speed  = 10 -%}
{% set ev_car_charge_kwh = (ev_car_battery_size / 100 * (ev_car_end_charge_level - states('sensor.ford_hv_battery_percent') | float))  %}
{% set ev_car_charge_time_min = ((ev_car_charge_kwh / ev_car_battery_charge_speed) * 60) | round(0) -%}
{% set ev_car_charge_time_hour = (ev_car_charge_time_min / 60) |  round(0, 'ceil') %}

{% set future_price = today_price[now().hour:] + tomorrow_price -%} 
{% set inteval_start_tomorrow = 0 -%}
{% set interval_start_hour =  now().hour + 1 -%}
{% set interval_end_tomorrow = 1 -%}
{% set interval_end_hour = 23 -%}

{% set low_interval_length = ev_car_charge_time_hour -%}
{% set all_price = today_price + tomorrow_price -%}

{% set interval_price = all_price[interval_start_hour + 24 * inteval_start_tomorrow : interval_end_hour + 24 * interval_end_tomorrow] -%}
{% set last_considered_interval_index = (interval_price | length) - low_interval_length + 1 -%}
{% set ns = namespace(current_best_average=1000, current_best_index=-1) -%}  
{% for price in interval_price[:last_considered_interval_index] -%}
  {% set current_average =  interval_price[loop.index0:loop.index0+low_interval_length] | average -%}
  {% if current_average < ns.current_best_average -%}
    {%-set ns.current_best_average = current_average -%}
    {% set ns.current_best_index = loop.index0 -%}
  {% endif -%}
{% endfor -%}

{%- set start_index = ns.current_best_index %}
{%- set best_interval_price = interval_price[start_index:start_index + low_interval_length] %}
{% set best_interval_start_hour =  24 * inteval_start_tomorrow + interval_start_hour + start_index -%}
{%- set best_interval_price = interval_price[start_index:start_index + low_interval_length] %}

{% set ev_car_start_charge_datetime =  (now() + timedelta(hours=best_interval_start_hour - now().hour)) - timedelta(minutes = now().minute) %}

{% set ev_car_stop_charge_datetime =  ev_car_start_charge_datetime + timedelta(minutes=ev_car_charge_time_min+10) %}

{% if ev_car_end_charge_level > states('sensor.fordhv_battery_percent') | float -%}
  Mustang GT Ladning: {{ states('sensor.ford_hv_battery_percent') | float }}% til {{ ev_car_end_charge_level }}% 
  Beregning udført : {{ now().strftime('%H:%M den %d/%m') }}
  Ladetid          : {{ ev_car_charge_time_hour - 1 }} time(r) og {{ ev_car_charge_time_min  % 60 }} min
  Hvor meget strøm : {{ ev_car_charge_kwh | round(1) }} kWh
  Det koster ca    : {{ (ev_car_charge_kwh * (best_interval_price| average))| round(0, 'ceil') }} kr
  kWh prisen er    : {{ (best_interval_price| average)| round(2) }} kr
  Start lader      : {{ ev_car_start_charge_datetime.strftime('%Y-%m-%dT%H:%M') }}
  Stop lader       : {{ ev_car_stop_charge_datetime.strftime('%Y-%m-%dT%H:%M') }}
{% else -%}
  Mangler ikke ladning
{% endif -%}

It will read my car Skærmbillede 2022-03-20 193230

and give the charge scheame for a easee charger :slight_smile:

7 Likes