Any good ideas are welcome. Nordpool Energy Price per hour

Maybe not suitable for your user case @vilhelm.carlsson but I plan to use sjabby’s logic posted above to turn on the water heater during the cheapest hours and then I modified the same logic from him to get the most expensive hours (i.e the daily peaks) and turn off the house heating (electric radiators) during the peaks.
This is still in the planing phase but I hope to get din rail contactors installed during the fall connected with Shelly’s to control all heating.

2 Likes

I’m a newbie at these stuff with automation
i want to check each hour if is above a certain value lets say 2.2 sek/kWh then the plug is off
but if its under 2.2 sek/kWh plug is on

got the nordpool intergration and have the sensor for current price setup

next would be to have something intergrated with growatt solar, but thats another project later

I would do it like this:

alias: above a certain value
description: ''
trigger:
  - platform: state
    entity_id:
      - sensor.nordpool_spot
condition: []
action:
  - choose:
      - conditions:
          - condition: numeric_state
            entity_id: sensor.nordpool_spot
            above: '220'
        sequence:
          - type: turn_off
            device_id: yaddayadda
            entity_id: switch.something
            domain: switch
      - conditions:
          - condition: numeric_state
            entity_id: sensor.nordpool_spot
            below: '220'
        sequence:
          - type: turn_on
            device_id: yaddayadda
            entity_id: switch.something
            domain: switch
    default:
      - type: turn_off
        device_id: yaddayadda
        entity_id: switch.something
        domain: switch

Create a new automation, press the three dots in the upper right corner, tap “Edit in YAML”, paste over with the code above, go back to “Edit in visual editor” and change to the entities you have, the switch etc. and what numbers you have for the price (mine is in Swedish “öre”, that’s 1/100 SEK). There are other ways but this is how I normally do it.

Thanks nice one!

I tried make my own based on others ideas! Came up with this one. I like it.

poolprice
But how can I make it not round up the values in the chart?
0.248 turns into 0.25,
0,206 turns into 0.21
How come? Can I somehow make the chart says what the actual value is? Easier to find errors etc also.

2 Likes

You have set float_precision and decimalsInFloat options to 2. Try 3 instead

2 Likes

Ah thanks!

How would the code look like if I would like it to show the averange price each week and month?

How would I do if I want to display my hourly energy usage from a energy sensor that is total_increasing ?
Guess I somehow need to display the diffrence between the hours, right?

See: Create template sensor for changes in the current hour only - #5 by MichaelSidenius

1 Like

Can you hide the dot and “Dagens timpris” some how?

Yes, just remove “title: Dagens timpris” from the code.
About the dots… that is a good question, I have no idea!

Hi!
I have solar panels and want to know how much I get every day when selling to my electricity company.
This would be simple, but we use the “spotprice” so it changes every hour, and we know every hour for 24 hours what the price is.
I have a Huawei inverter and the sensor I want to use is “sensor.grid_export_solar_daily_energy”
So i guess it would be possible to code it so my exported energy would match the nordpool prices.
Can someone explain or show me an example? Or explain how to do this.

This is what i have made so far, just want the exported prices then i should be finished…at least for a day or 2 :slight_smile:

Is it possible to make a sensor that shows the next hour’s electricity price?

I use the Nordpool HACS integration as a current price entity.

I get the Solar production from the Huawei Solar integration, the Grid consumption from an MQTT configured Tibber Pulse meter, as well as the Return to grid values.

As I have a fixed price for consumption, I’ve added a manual price/static rate (including net transfer fees and taxes), and the Nordpool spot prices (including VAT/moms, enabled) for the surplus being sold.

I’ve also made a template sensor that calculates live data for house power draw.

  - platform: template
    sensors:
      template_active_power_consumption:
        friendly_name: "Power consumption"
        device_class: energy
        unit_of_measurement: 'W'
        value_template: '{{ states ("sensor.inverter_active_power")|int(0) + states ("sensor.lgf_active_power_import") | int(0) - states ("sensor.lgf_active_power_export")|int(0) }}'

I used the solution from this thread and switched out the entity with mine and removed the *100 get kr instead of ore.

type: custom:apexcharts-card
hours_12: false
header:
  show: true
  title: Nordpool Prize -> 48 hours
  show_states: true
now:
  show: true
  color: '#ff0000'
  label: Now
graph_span: 2d
span:
  start: day
series:
  - entity: sensor.nordpool_kwh_oslo_nok_2_10_025
    name: Today
    unit: øre/kWh
    data_generator: |
      return entity.attributes.raw_today.map((entry) => {
        return [new Date(entry.start), entry.value * 100];
      });
    type: column
    show:
      legend_value: false
      in_header: false
    extend_to: end
  - entity: sensor.nordpool_kwh_oslo_nok_2_10_025
    name: Tomorrow
    unit: øre/kWh
    data_generator: |
      return entity.attributes.raw_tomorrow.map((entry) => {
        return [new Date(entry.start), entry.value * 100];
      });
    type: column
    show:
      legend_value: false
      in_header: false

hi maybe i misunderstood you but isn’t this a graph?
What I mean is that jas would like to have a sensor that shows the next hour like below.

That is a built-in graph, yes. The Apexcharts integration is a bit more powerful, however.

I cannot figure out how to extract the price for the next hour and make it into a sensor/an entity.

You could probably do it with a template, but my scripting skills are lacking/non-existent :roll_eyes:.

1 Like

I’ve tried all the great examples above of how to determine “low” prices, but I wanted to improve the algorithm without having to go stateful. To be truly optimal, each consumer would have to register when a need arises, and register how much energy is needed as well as maximum power. Determining needed energy might be quite tricky. For instance a hot water boiler, you would need to know the volume and have multiple temperature sensors to accurately determine at what level the hot water level is at. This is more than I wanted to tackle.

Instead I came up with this algorithm which does a pretty good job. It takes all available future prices into account, groups them by value proximity into 3 groups: low, medium and high. There are no hard coded limits so even if night prices are high, it will find the lowest hours.

To make automations and conditions easy I have three template sensors:

  • Upper limit for low prices
  • Lower limit for high prices
  • A bracket number where 1=low, 2=medium and 3=high

If you need a condition it’s easy to compare current price <= low price or >= high price
If you want different consumers enabled in different brackets, create automations on the bracket value which will be evaluated everytime current price moves to a different bracket. Then have 3 scenes (low, medium and high) where you set what consumers should be enabled.

This also avoids the shortcoming in HA where numeric action triggers only subscribes to 1 entity even if you use multiple entities.

I share my code for comments and for anyone to use. You need to adjust all “sensor.nordpool_kwh_se3_sek_3_10_025” for your own region, and it relies on the NordPool integration through HACS.

template:
  - sensor:
      - name: "Electricity Band Low now today+tomorrow"
        unique_id: "sensor.electricity_band_low"
        unit_of_measurement: "SEK/kWh"
        state: "{% if states('sensor.nordpool_kwh_se3_sek_3_10_025') -%}
                {% if state_attr('sensor.nordpool_kwh_se3_sek_3_10_025', 'tomorrow_valid') == true and state_attr('sensor.nordpool_kwh_se3_sek_3_10_025', 'tomorrow')|string|length > 24  -%}
                   {% set prices=states.sensor.nordpool_kwh_se3_sek_3_10_025.attributes.raw_today|list + states.sensor.nordpool_kwh_se3_sek_3_10_025.attributes.raw_tomorrow|list -%}
                {% else -%}
                   {% set prices=states.sensor.nordpool_kwh_se3_sek_3_10_025.attributes.raw_today -%}
                {% endif -%}
                {% set cheapest = prices|selectattr('end','>',now()) | sort(attribute='value') -%}
                {% set deltas = namespace(deltas=[]) -%}
                {% set previous = namespace(value=0.0) -%}
                {% for cheap in cheapest -%}
                  {% if loop.index > 1 -%}
                    {% set delta = [({'value':cheap.value, 'delta':cheap.value - previous.value})] -%}
                    {% set deltas.deltas = deltas.deltas + delta -%}
                  {% endif -%}
                  {% set previous.value = cheap.value -%}
                {% endfor -%}
                {% set bands = deltas.deltas | sort(reverse=true,attribute='delta') -%}
                {{ cheapest|selectattr('value','<',min(bands[0].value,bands[1].value))|map(attribute='value')|list|last }}
                {% else -%}
                   {{  unknown }}               
                {% endif -%}"
  - sensor:
      - name: "Electricity Band High now today+tomorrow"
        unique_id: "sensor.electricity_band_high"
        unit_of_measurement: "SEK/kWh"
        state: "{% if states('sensor.nordpool_kwh_se3_sek_3_10_025') -%}
                {% if state_attr('sensor.nordpool_kwh_se3_sek_3_10_025', 'tomorrow_valid') == true and state_attr('sensor.nordpool_kwh_se3_sek_3_10_025', 'tomorrow')|string|length > 24  -%}
                   {% set prices=states.sensor.nordpool_kwh_se3_sek_3_10_025.attributes.raw_today|list + states.sensor.nordpool_kwh_se3_sek_3_10_025.attributes.raw_tomorrow|list -%}
                {% else -%}
                   {% set prices=states.sensor.nordpool_kwh_se3_sek_3_10_025.attributes.raw_today -%}
                {% endif -%}
                {% set cheapest = prices|selectattr('end','>',now()) | sort(attribute='value') -%}
                {% set deltas = namespace(deltas=[]) -%}
                {% set previous = namespace(value=0.0) -%}
                {% for cheap in cheapest -%}
                  {% if loop.index > 1 -%}
                    {% set delta = [({'value':cheap.value, 'delta':cheap.value - previous.value})] -%}
                    {% set deltas.deltas = deltas.deltas + delta -%}
                  {% endif -%}
                  {% set previous.value = cheap.value -%}
                {% endfor -%}
                {% set bands = deltas.deltas | sort(reverse=true,attribute='delta') -%}
                {{ max(bands[0].value,bands[1].value) }}
                {% else -%}
                   {{  unknown }}               
                {% endif -%}"
  - sensor:
      - name: "Electricity Price Bracket"
        unique_id: "sensor.electricity_bracket"
        state_class: "measurement"
        state: "{% if states('sensor.nordpool_kwh_se3_sek_3_10_025') and states('sensor.electricity_band_low') and states('sensor.electricity_band_high') -%}
                  {% set current_price = states('sensor.nordpool_kwh_se3_sek_3_10_025') -%}
                  {% set low = states('sensor.electricity_band_low_now_today_tomorrow') -%}
                  {% set high = states('sensor.electricity_band_high_now_today_tomorrow') -%}
                  {% if current_price <= low -%}
                    {% set bracket = 1 -%}
                  {% elif current_price >= high -%}
                    {% set bracket = 3 -%}
                  {% else -%}
                    {% set bracket = 2 -%}
                  {% endif -%}
                  {{ bracket }}
                {% endif -%}"

4 Likes

Hey! I got this from another forum. It will show true if the current hour is one of 5 cheapest hour during the day. That way you could turn on something you want to be on during the cheapest hour.

        {% set x = states("sensor.time") %}
        {% set l=state_attr('sensor.nordpool_kwh_se3_sek_3_10_025_med_moms', 'raw_today')|sort(attribute='value') %}
        {{ (now() >= l[0].start and now() <= l[0].end)
        or (now() >= l[1].start and now() <= l[1].end)
        or (now() >= l[2].start and now() <= l[2].end)
        or (now() >= l[3].start and now() <= l[3].end)
        or (now() >= l[4].start and now() <= l[4].end) }}

But I would also like to display the cheapest 5 hours somehow so I clearly see what hours that is. How would I do that in a good visual way?

Thanks!

1 Like

Thanks for good input!

However, could you open up what this helper actually does? What is the effect of choosing 2 or 4 in helper and how should the effect be seen?