Control devices based on Nordpool

Hi! Tere is solution,how to automate devices based on Nordpool hourly prices.Sry about my english,so,if any questions,maybe i dont understood exactly.Please be patient.There is a yaml,where you can control any device,You can set hours,when to wacth prises and how many hours to sort out. I hope you understand what i want to say.

alias: Nordpool per hour
description: ''
trigger:
  - platform: state
    entity_id: sensor.nordpool_kwh_ee_eur_3_10_02
condition: []
action:
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {{ ([(state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[1]
              |
                              float(default=0)),
                              (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[2] |
                              float(default=0)),
                              (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[3] |
                              float(default=0)),
                              (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[4] |
                              float(default=0)),
                              (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[5] |
                              float(default=0)),
                              (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[6] |
                              float(default=0)),
                              (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[7] |
                              float(default=0)),
                              (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[8] |
                              float(default=0))] | sort)[4] >=
                              state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','current_price') | float }}
          - condition: time
            after: '00:00'
            before: '08:00'
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.lumi_lumi_remote_b186acn01_on_off
      - conditions:
          - condition: template
            value_template: |2-
                {{ ([(state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[8] |
                                float(default=0)),
                                (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[9] |
                                float(default=0)),
                                (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[10] |
                                float(default=0)),
                                (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[11] |
                                float(default=0)),
                                (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[12] |
                                float(default=0)),
                                (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[13] |
                                float(default=0)),
                                (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[14] |
                                float(default=0)),
                                (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[15] |
                                float(default=0)),
                                (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[16] |
2 Likes

Hi

Iā€™m trying to do exactly what you describe. But I canā€™t make sense of your example. Is there something missing?

alias: 'Boiler bƶrsihinnaga tunnipƵhiselt '
description: ''
trigger:
  - platform: state
    entity_id: sensor.nordpool_kwh_ee_eur_3_10_02
condition: []
action:
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {{ ([(state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[0]
              |
                              float(default=0)),
                              (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[1] |
                              float(default=0)),
                              (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[2] |
                              float(default=0)),
                              (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[3] |
                              float(default=0)),
                              (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[4] |
                              float(default=0)),
                              (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[5] |
                              float(default=0)),
                              (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[6] |
                              float(default=0)),
                              (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[7] |
                              float(default=0))] | sort)[4] >=
                              state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','current_price') | float }}
          - condition: time
            after: '00:00'
            before: '08:00'
            weekday:
              - mon
              - tue
              - wed
              - thu
              - fri
        sequence:
          - service: switch.turn_on
            target:
              entity_id: switch.boiler
      - conditions:
          - condition: template
            value_template: |2-
                {{ ([
                                (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[14] |
                                float(default=0)),
                                (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[15] |
                                float(default=0)),
                                (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[16] |
                                float(default=0)),
                                (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[17] |
                                float(default=0)),
                                (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[18] |
                                float(default=0)),
                                (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[19] |
                                float(default=0)),
                                (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[20] |
                                float(default=0))] | sort)[1] >=
                                state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','current_price') | float }}
          - condition: time
            after: '15:00'
            before: '21:00'
            weekday:
              - mon
              - tue
              - wed
              - thu
              - fri
        sequence:
          - service: switch.turn_on
            target:
              entity_id: switch.boiler
      - conditions:
          - condition: template
            value_template: |2-
               {{ ([
                                (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[0] |
                                float(default=0)),
                                (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[1] |
                                float(default=0)),
                                (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[2] |
                                float(default=0)),
                                (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[3] |
                                float(default=0)),
                                (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[4] |
                                float(default=0)),
                                (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[5] |
                                float(default=0)),
                                (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[6] |
                                float(default=0)),
                                (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[7] |
                                float(default=0)),
                                (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[8] |
                                float(default=0)),
                                (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[9] |
                                float(default=0)),
                                (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[10] |
                                float(default=0)),
                                (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[11] |
                                float(default=0)),
                                (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[12] |
                                float(default=0)),
                                (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[13] |
                                float(default=0)),
                                (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[14] |
                                float(default=0)),
                                (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[15] |
                                float(default=0)),
                                (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[16] |
                                float(default=0)),
                                (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[17] |
                                float(default=0)),
                                (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[18] |
                                float(default=0)),
                                (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[19] |
                                float(default=0)),
                                (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[20] |
                                float(default=0)),
                                (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[21] |
                                float(default=0)),
                                (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[22] |
                                float(default=0)),
                                (state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','today')[23] |
                                float(default=0))] | sort)[20] >=
                                state_attr('sensor.nordpool_kwh_ee_eur_3_10_02','current_price') | float }}
          - condition: time
            after: '00:01'
            before: '23:59'
            weekday:
              - sat
              - sun
        sequence:
          - service: switch.turn_on
            target:
              entity_id: switch.boiler
    default:
      - service: switch.turn_off
        target:
          entity_id: switch.boiler
mode: single

Your default action is missing

thanks @Pafkas - finally got it working, added transport tarif from the utility services provider, so these are considered as well. testing on a boolean right now, cant wait to install a highpower switch controlle by an ESP ā€‹relay. it will be controlling our heatpump!

What heat pump do you use? Most heat pumps have a ā€œdemand controlā€ input - dry contact to stop the heat pump for instance. I would not suggest just switching power on/off.

On air-water pumps you could also drive demand based on room thermostat contacts or for instance some also have Smart Grid readyness allowing you to boost the heating when price is low, operate normally when price is average and stop the heat pump when price is high.

I have the latter set up for my Mitsubishi air-water pump for a few days now. I also made additional scripts that monitor the DHW and floor temperatures and if these drop below minimum, I override the instruction and let the pump work even during high cost hours - as little as possible still.

Sorry but I am not yet familiar with HA and how I customize The output.
In the edentity card I will change the font size and only have 3 decimals.

Shall I change it in HA Card-mod or in Template, value template, and please help me with some code so I understand. My card is like this today.

Hi @AndersT!

In the setup of your sensor in configuration.yaml you should have one line
# How many decimals to use in the display of the price precision: 3.
Found it?

Yes, my problem was that it was an attribute in the sensor but I solve it. Thanks anyway :slight_smile:

Hi, please advise anyone, looking to build switches which track Nordpool prices and are related to eachother. e.g first switch is ON when NP price is x% below visible forward avg and second switch comes on if NP price is x times above SW1 last activity.

This is to charge battery with low avg price and disharge when set price difference occurs.

Thanks in advance!
Kaupo

ā€¦ solved it in two ways:

a) binary_sensor for input_number - defining hours for charge and discharge (Nordpool daily price countdown normal and reverse).

- platform: template
  sensors:
    charge:
      unique_id: charge
      friendly_name: charge
      value_template: >
        {% set l = state_attr('sensor.nordpool', 'raw_today') | sort(attribute='value') %}
        {% set t = now() %}
        {% for i in range(states('input_number.charge') | int ) %}
        {% if (t >= l [i].start and t <= l [i].end) %}
        {{ true }}
        {% endif %}
        {% endfor %}

- platform: template
  sensors:
    production:
      unique_id: production
      friendly_name: production
      value_template: >
        {% set l = state_attr('sensor.nordpool', 'raw_today') | sort(attribute='value', reverse = true) %}
        {% set t = now() %}
        {% for i in range(states('input_number.production') | int ) %}
        {% if (t >= l [i].start and t <= l [i].end) %}
        {{ true }}
        {% endif %}
        {% endfor %}

b) sensors for below and above NP average, input_number 0,1 to 0,7 (charge) <= avg => (production) 1,1 to 1,8

- platform: template
  sensors:
    charge:
      unique_id: charge
      friendly_name: Charge
      value_template: >
        {% set avgl = state_attr('sensor.nordpool', 'average' ) * states('input_number.chrg') | float %}
        {% set cur = state_attr('sensor.nordpool', 'current_price' ) | float %}
        {% if (cur <= avgl )%}
        {{ 1 }}
        {% else %}
        {{ 0 }}
        {% endif %}

- platform: template
  sensors:
    production:
      unique_id: production
      friendly_name: Production
      value_template: >
        {% set avgt = state_attr('sensor.nordpool', 'average' ) * states('input_number.prod') | float %}
        {% set cur = state_attr('sensor.nordpool', 'current_price' ) | float %}
        {% if (cur >= avgt)%}
        {{ 1 }}
        {% else %}
        {{ 0 }}
        {% endif %}

for both, input_numbers from HA > settings > devices > helpers
and automations also from GUI.

Hi, interested to make sensor for counting values in list with if criteria. I can think of code:

{% set list = state_attr('sensor.nordpool','today') %}
{% set avg = state_attr('sensor.nordpool','average') %}
{{ list [0] - avg,
  list [0] - avg,
# ...
# 24 list entries
 list[23]}}
{% if (list [0] < avg) %}
{% set list1 = 1 %}
{% elif (list [0] > avg) %}
{% set list1 = 0 %}
{% endif %}
# ...
# repeat same 24 times
{% if (list [23] < avg) %}
{% set list9 = 1 %}
{% elif (list [23] > avg) %}
{% set list23 = 0 %}
{% endif %}

# Sensor value should be
# {{ list0 + list1 + ... listn }}
# How to make it compact?

Any advise to compact it.

Thanks in advance!

Hi. Is there an app to use it with basic wifi smartsockets?

Hello!

Total HA newbie here but iā€™m learning.

Iā€™m trying to achieve pretty much the same thing you are, only i would like to use exact value for buy/sell to happen. First iā€™m charging the batteries for the amount of the forecast own usage (which is calculated based on weather forecast) this charging is always made on the cheapest n number of hours. Then i want to calculate if there still is, and how many, hours that for buying electricity, there is more expensive hours to come when i can sell the bought electricity, and what hours they are.
So for every hour i could send modbus messages to my inverters to either buy or sell electricity, or do nothing.

Do you think this is doable?
-Henri

Hi, Iā€™m trying to make this work, but beeing a newbie, Iā€™m not sure where to put this code. Iā€™ve tried making an automaton (edit in yaml, pasting the code you provided), but getting error at 1st line 'platform: ':confused:
So, my guess was that this is not something to put in an automation, then trying to put it in configuration.yaml, but no luck there either :man_shrugging:

Iā€™m sure this is really simple, just needing a tip as to where to put the code :smiley:

I use the YAML files for more complicated programming.

I am a newbie of yaml code. Trying to to calculate a solution based on day current and average price.

Without the time-pattern the action never happens but with the time-pattern the calculation doesnā€™t work.
I thought this should be very easy.

alias: Nordpool switch On
description: Compare average price with actual price
trigger:

  • platform: time_pattern
    minutes: /1
  • platform: template
    value_template: >-
    {{ sensor.nordpool_today_current_price < (sensor.nordpool_today_average *
    0.8) }}
    condition: []
    action:
  • type: turn_on
    device_id: 2ace8d2a719b9ecdec8156a28c8da6e9
    entity_id: switch.sonoff_100144d3ce
    domain: switch
    mode: single

Many thanks in advance
Anders
Sweden

Hello Kaupo,
I have Huawei solar panels and soon 15 kWh battery package.
Your code looks very interesting to integrate in my system.
I have will have an API towards the battery. I have now for the Huawei inverter.
But I am too new in HA coding.
I try to add your code.
I placed in configuration.yaml. !include to own file did not work today.
But I had to remove the -platform template since it looks like HA do not like it and it does nog agree to duplicate ā€œchargeā€ and ā€œproductionā€ sensors.
But as I understand the a) part fills a list with true/false for each hour if it is worth charging.
And b) decides with 0/1 if to charge or produced based on input_number.
But how can I see the value_templates in a UI card? And how to read them for control of my battery?