Any good ideas are welcome. Nordpool Energy Price per hour

Why did you update apexcards ?

Asking because in the last days my apexcharts with Nordpool prices for today and tomorrow has been very spotty.

Today i only have the price from 00-01 and on the card for tomorrow i have no prices at all.

If you experienced something similar and upgraded because of this i am very interested in knowing.

There are some issues with Nordpool, causing the next day not to be visible once in a while (restarting HA will get the correct prices but that is only a work around). This has nothing to do the the apexcards. I updated the apexcards because there was a new release, no other reason.

I have that problem also, did it resolve the issue with not showing the next day prices. ?

Nevermind, it seems there was probably some error in 2022.5, that they fixed in 2202.5.1, all is working again.

After updating to the latest May release Nordpool integration fails here.

Setup failed for custom integration nordpool: Unable to import component: cannot import name ā€˜EVENT_TIME_CHANGEDā€™ from ā€˜homeassistant.constā€™ (/usr/src/homeassistant/homeassistant/const.py)

If anybody interested, I used some code from here and adjusted a bit for a better Apex Chart: [Question] Is it possible to get all 48 price values into one graph? Ā· Issue #19 Ā· custom-components/nordpool Ā· GitHub

type: custom:apexcharts-card
graph_span: 48h
span:
  start: day
  offset: +0H
header:
  title: Electricity Price
  show: true
  show_states: false
  colorize_states: true
hours_12: false
stacked: false
experimental:
  color_threshold: true
all_series_config:
  show:
    legend_value: false
    datalabels: false
    extremas: true
    in_brush: true
  float_precision: 3
  type: area
  invert: false
  fill_raw: last
  color_threshold:
    - value: -1
      color: 1E90FF
    - value: 0.06
      color: '008000'
    - value: 0.19
      color: DAA520
    - value: 0.25
      color: FF0000
now:
  show: true
  label: Now
  color: red
series:
  - entity: sensor.nordpool_kwh_ee_eur_3_05_02
    name: Current day
    opacity: 0.7
    extend_to: false
    data_generator: |
      return entity.attributes.raw_today.map((start, index) => {
        return [new Date(start["start"]).getTime(), entity.attributes.raw_today[index]["value"]];
      });
  - entity: sensor.nordpool_kwh_ee_eur_3_05_02
    name: Tomorrow
    opacity: 0.5
    data_generator: |
      return entity.attributes.raw_tomorrow.map((start, index) => {

        return [new Date(start["start"]).getTime(), entity.attributes.raw_tomorrow[index]["value"]];

      });
apex_config:
  chart:
    height: 400px
    animations:
      enabled: true
      easing: easeinout
      speed: 800
      animateGradually:
        enabled: true
        delay: 150
  zoom:
    enabled: true
    type: x
    autoScaleYaxis: true
    zoomedArea:
      fill:
        color: '#90CAF9'
        opacity: 0.4
      stroke:
        color: '#0D47A1'
        opacity: 0.4
        width: 1
  legend:
    show: false
    floating: true
    offsetY: 25
  yaxis:
    opposite: false
    reversed: false
    logarithmic: false
    decimalsInFloat: 2
    labels:
      show: true
    tooltip:
      enabled: true
    crosshairs:
      show: true
  xaxis:
    labels:
      show: true
      rotate: -45
      rotateAlways: true
    logarithmic: true
  stroke:
    show: true
    curve: stepline
    lineCap: butt
    colors: undefined
  plotOptions:
    candlestick:
      colors:
        upward: '#00B746'
        downward: '#EF403C'
      wick:
        useFillColor: true
  markers:
    size: 1
  grid:
    show: true
    strokeDashArray: 1
    position: front
    xaxis:
      lines:
        show: true

Change the entity and play with color threshhold values to suit you.

19 Likes

thanks for this!

1 Like

Taking now a closer look on costs side of things.

From the component description:

   # The price result of the additional_costs template expects this additional cost to be in kWh and not cents as a float

Can someone please clarify, what this sentence means?

ā€œā€¦additional costs to be in kWhā€ means in other words that the units of currency and energy are the same (ā€œcurrency = kWhā€), which of course cannot be.

ā€œā€¦and not cents as a floatā€ ???

Basically I need to to know, whether additionals costs are per kWhs or are they per hour type of things? The senttence above probably takes some position in that, but I donā€™t undestand the sentence at all.

I also need to insert both kWh -based and hour -based fixed costs, so how is this done?

nordpool integration has some nasty bug - it cannot do properly dynamic delivery cost calculation for future use. It will add only currently active price.

Thus I made external proper calculation:

input_number:
  sadales_tikls_day:
    name: "Sadales tīkls dienas tarifs (Eur/kWh)"
    initial: 0.051
    min: 0
    max: 10.00
    step: 0.001
    mode: box
  sadales_tikls_night:
    name: "Sadales tīkls brivdienu un nakts tarifs (Eur/kWh)"
    initial: 0.027
    min: 0
    max: 10.00
    step: 0.001
    mode: box

  - platform: template
    sensors:
      electricity_price:
        friendly_name: "Nordpool + Sadales TÄ«kls"
        icon_template: mdi:currency-eur
        unit_of_measurement: "EUR/kWh"
        value_template: '{% if now().weekday() < 5 and ("07" | int <=  now().hour | int < "23" | int) %}{{state_attr("sensor.nordpool_kwh_lv_eur_4_08_0", "current_price") + states("input_number.sadales_tikls_day")|float }}{% else %}{{state_attr("sensor.nordpool_kwh_lv_eur_4_08_0", "current_price") + states("input_number.sadales_tikls_night")|float }}{% endif %}'
        attribute_templates:
          today: >
            {%- set y = states.sensor.nordpool_kwh_lv_eur_4_08_0.attributes.today -%}
            {%- set ns = namespace (z=[]) -%}
            {%- for i in states.sensor.nordpool_kwh_lv_eur_4_08_0.attributes.today -%}
              {%- if loop.index0 >= 7 and loop.index0 < 23 and now().weekday() < 5 -%}
                {%- set ns.z = ns.z + [(y[loop.index0]|float+ states('input_number.sadales_tikls_day')|float)|round(4)] -%}
              {%- else -%}
                {%- set ns.z = ns.z + [(y[loop.index0]|float+ states('input_number.sadales_tikls_night')|float)|round(4)] -%}
              {%- endif -%}
            {%- endfor -%}
            {{ ns.z }}
            
      electricity_price_today_low_1h:
        friendly_name: "Lowest 1h price today"
        value_template: >
          {%- set sorted_prices = state_attr('sensor.electricity_price','today')|sort %}
          {{ states('sensor.electricity_price')|float <= sorted_prices[0]|float }}

      electricity_price_today_low_2h:
        friendly_name: "Lowest 2h price today"
        value_template: >
          {%- set sorted_prices = state_attr('sensor.electricity_price','today')|sort %}
          {{ states('sensor.electricity_price')|float <= sorted_prices[1]|float }}

      electricity_price_today_low_3h:
        friendly_name: "Lowest 3h price today"
        value_template: >
          {%- set sorted_prices = state_attr('sensor.electricity_price','today')|sort %}
          {{ states('sensor.electricity_price')|float <= sorted_prices[2]|float }}
.......

Then it is a matter to craft and automation based on those lowest x hour True or False status.

1 Like

Okā€¦ Brand new home assistant user here. With the current energy prices I realized I had to do something about the energy consumption scheduling in my house (I have some humidity control equpiment in the basement which use a LOT of powerā€¦), and found home assistant. Im not yet very familiar with stuff you veterans think is obvious, so hope I donā€™t ask too silly questions :wink:
Iā€™ve setup a home assistant and installed HACS, then I installed the nordpool integration. Then I installed a sensor (nordpool_kwh_se4_sek_3_10_025) and now I think Iā€™m good to go to actually start to use it (?).
My goal is to know the X number of cheapest hours today/tomorrow, and only allow the equpiment to run those cheap hours. I donā€™t yet know X, since that depends on the humidity in the basement (which I also already monitor via home assistant actually).
My next step is to create aā€¦ what? (Where I can do some calculation and output if the current hour is among the cheapest known)
I havenā€™t yet understood the work flow for these things, so if someone is kind enough to just describe the overall concept what the steps are it would help a lot :slight_smile:
In the end I conceptually think I want multiple inputs for the basement equipment, like ā€œcurrent price is okā€ (itā€™s amont the lowest X), ā€œhumidity is not okā€ (overrides price check so it runs anyway) and so on.

Thanks is advance!

Hi Daffy951
Controling based on Nordpool price can be hard based on the need.
Say example that you are expecting to have car fully charged in the morning and that takes say 3 houres. Then you know that you need to find the 3 lowest houres.

If doing the same for say a heating system or in youre case humidity there will be more varibels. Maby some critical upper limmit that the equipment should run no mater the cost. Say that its raining outside you might need to run the controller 8h that day, and some othere days just 1 houre.

If you like to start with somthing less complicated you should be able to use the attribute ā€œaverageā€ to compare the current price with the average. Supplie energy if current is lower then average.
This would give that the controller atlest have power during several of houres a day and avoiding the most expensive houres.

I know that this is not really what you asked about. You might be able to build what you are asking about, however I think you need to do logic to first find out how many houres a day that the equipent needs to run and what varibles is effect that amount of houres from day to day.

To do above you need to look into allot of template and logic (Templating - Home Assistant), you can test this out in under ā€œdevelopment toolsā€ ā†’ ā€œtemplateā€

//Nicklas

Hi @Daffy951,

I have a similar need for which I created a template sensor for. I want to run my pool pump on the cheap hours, and I want it to run for 12 hrs a day with no longer pauses that 10 hrs.

For this I created a template sensor which state contains the median, and have a few attributes that can be used for automations: tomorrow, tomorrow_valid, below_median_now, unit_of_measurement: friendly_name

This sensor I use in my automations to turn on/off the pool pump. I use a ā€œprotectionā€ automation that ensures that the pump are not off for too long, simply by checking ā€œfor 10 hoursā€

You can likely build upon this sensor for your needs:

sensor:
  - platform: template
    sensors:
      nordpool_eo4_median:
        friendly_name: "Nordpool EO4 Median"
        unit_of_measurement: 'SEK/kWh'
        value_template: >
          {{average((state_attr('sensor.nordpool_kwh_se4_sek_3_095_025', 'today') | sort())[11],
                    (state_attr('sensor.nordpool_kwh_se4_sek_3_095_025', 'today') | sort())[12]) | 
            round(3) }}
        attribute_templates:
          tomorrow: >
            {% if state_attr('sensor.nordpool_kwh_se4_sek_3_095_025', 'tomorrow_valid') %}
            {{average((state_attr('sensor.nordpool_kwh_se4_sek_3_095_025', 'tomorrow') | sort())[11],
                      (state_attr('sensor.nordpool_kwh_se4_sek_3_095_025', 'tomorrow') | sort())[12]) | 
              round(3) }}
            {% endif %}
          tomorrow_valid: >
            {% if state_attr('sensor.nordpool_kwh_se4_sek_3_095_025', 'tomorrow_valid') %}
            True
            {% endif %}
          below_median_now: >
            {% if state_attr('sensor.nordpool_kwh_se4_sek_3_095_025', 'current_price') <= 
                  average((state_attr('sensor.nordpool_kwh_se4_sek_3_095_025', 'today') | sort())[11],
                          (state_attr('sensor.nordpool_kwh_se4_sek_3_095_025', 'today') | sort())[12]) | 
                  round(3) %}
            True
            {% else %}
            False
            {% endif %}

Come to think of if, this template will likely fulfill your needs. Change HRS_ON to how may hours you need your system to run.

{% set HRS_ON = 11 %}
{% set M1 = HRS_ON - 1 %}
{% set M2 = M1+1 %}
{{average((state_attr('sensor.nordpool_kwh_se4_sek_3_095_025', 'today') | sort())[M1],
          (state_attr('sensor.nordpool_kwh_se4_sek_3_095_025', 'today') | sort())[M2]) | 
   round(3) }}

/Marcus

4 Likes

I have made an attempt to control my pool heating to use the cheapest hours. Based on the weather forecast and old heating data, i made a forecast how much heating needed to keep the pool temperature on the desired level. Then I used the Nordpol price info for the next day to figure out exactly which hours to heat my pool.

This system worked quite well. However, I couldnā€™t see any real advantage compared to a much simpler algorithm where I just avoid to heat during expensive hours. This control system is a implemented as a Phyton script. I plan to implement this in Home Assistant as well and I will definitely go for the simple solution. I have already implemented this algorithm to control floor heating in my house, so I will just extend this to include the pool heating as well.

So keep it simple. This is.my best advice!

I started to very complicated algorithms but eventually i ended up using 36h price if tomorrows prices are released.
Because nordpool sensor sometimes gives tomorrow valid due timezone differnece im checking if tomorrow 5th price is validā€¦

36h
if todays prices are cheaper then tomorrows, il using more today, and when tomorrow is cheaper, then stop using today

{% if state_attr('sensor.nordpool_mwh_ee_eur_3_099_0','tomorrow')[5] %}
{{(state_attr('sensor.nordpool_mwh_ee_eur_3_099_0','tomorrow') | sort)[6]>= state_attr('sensor.nordpool_mwh_ee_eur_3_099_0','current_price') }}
{%- else -%}
{{ (state_attr('sensor.nordpool_mwh_ee_eur_3_099_0','today') | sort)[6] >= state_attr('sensor.nordpool_mwh_ee_eur_3_099_0','current_price') }}
{%- endif %}

24h

{{ (state_attr('sensor.nordpool_mwh_ee_eur_3_099_0','today') | sort)[6] >= state_attr('sensor.nordpool_mwh_ee_eur_3_099_0','curr
ent_price') }}
1 Like

It would be nice to have an average, min and max for today, tomorrow and total (today and tomorrow if it is available).
I would think it is not too difficult to implement in the integration.
Or are there good reasons why not to do this?

2 Likes

Hi Marcus. This seems to fit my needs exactly. Can you please show me the protection automation as well?
Iā€™m a newbie and struggling to find out how to do things
I just tried your template above and it works like a charm
//Magnus

You can do this quite easily in the Ui, but this is how my automation looks in Yaml.
/Marcus

- id: 'xxxxxxxxxx'
  alias: Pool off too long
  trigger:
  - platform: device
    type: turned_off
    device_id: yyyyyyyy
    entity_id: switch.poolpump
    domain: switch
    for:
      hours: 10
      minutes: 0
      seconds: 0
  condition: []
  action:
  - type: turn_on
    device_id: zzzzzzz
    entity_id: switch.poolpump
    domain: switch
  mode: single

Guys, been reading through this thread - what you do with templating are amazing!

I could need some assistance.

Iā€™ve made 4 sensors based on utility_meter for energy used last hour, so far today, so far this week and so far this month.

Now I would like to create 4 new sonsors telling me the total cost based on my Nordpool tariff for the same; total cost spent last hour, so far today, so far this week and so far this month.

Could somebody please help me on this?

1 Like

Use built in Energy Dashboard for this.

I know I have it there, but want this split in different sensors I can use in any view/card.

1 Like

Thank you very much for sharing! This works perfectly as well.
I hope you can help me some moreā€¦
My next question is, how do you deal with starting/stopping in your automation based on the values mentioned earlier, nordpool_e04_median etc. I do not really understand what you mean with this and where (configuration.yaml?) you enter it

{% set HRS_ON = 11 %}
{% set M1 = HRS_ON - 1 %}
{% set M2 = M1+1 %}
{{average((state_attr('sensor.nordpool_kwh_se4_sek_3_095_025', 'today') | sort())[M1],
          (state_attr('sensor.nordpool_kwh_se4_sek_3_095_025', 'today') | sort())[M2]) | 
   round(3)

//Magnus