Any good ideas are welcome. Nordpool Energy Price per hour

I failed with porting that one over so I took the example 5 code and brute forced my day and night numbers into that and added together other tariffs into the “hourly fixed cost” value.
It can be made prettier but I think I’ll leave it here like that for anyone who also wants true total cost values and maybe has summer-winter differences that they want to use. Also changed hours.
Fairly good starting point for anyone I think who meddles with config on that level.
image

here’s the additional cost value to have nordpool graph with tarrifs:

  additional_costs: '{% set s = {
  "hourly_fixed_cost": 0.0226,
  "winter_night": 0.021,
  "winter_day": 0.0369,
  "summer_day": 0.0369,
  "summer_night": 0.021,
  "cert": 0.001
  }
  %}
    {% if now().month >= 5 and now().month < 11 %}
        {% if now().hour >= 7 and now().hour < 22 %}
            {{ s.summer_day + s.hourly_fixed_cost + s.cert | float }}
        {% else %}
            {{ s.summer_night + s.hourly_fixed_cost + s.cert|float }}
        {% endif %}
    {% else %}
        {% if now().hour >= 7 and now().hour < 22 %}
            {{ s.winter_day + s.hourly_fixed_cost + s.cert | float }}
        {% else %}
            {{ s.winter_night + s.hourly_fixed_cost + s.cert | float }}
        {% endif %}
    {% endif %}'
1 Like

Thanks i’ll check the prices. Haven’t done it in a while.

And yes, this makes sense that it uses the current value for all hours, because nordpool integration does not know anything about the helper logic.

Try to port the template code into the nordpool configuration like in example 5, and let us know how it went.

okay here’s prettified code version to generate graph with hourly price differences. If you dont have seasonal differences, just put same number to both periods.
if you dont have something in the list, just use value 0.

  # VAT 1.2 means additional costs get 20% vat added after adding together. Not sure how nordpool VAT: True manages additional costs.
  additional_costs: '{% set s = {
  "operator_margin": 0.0102,
  "electricity_excise": 0.001,
  "renewable_tariff": 0.0124,
  "winter_day": 0.0369,
  "winter_night": 0.021,
  "summer_night": 0.021,
  "summer_day": 0.0369,
  "electricity_excise": 0.001,
  "VAT": 1.2 
  }
  %}
    {% if now().month >= 5 and now().month < 11 %}
      {% if now().weekday() in (5,6) %}
          {{ (s.summer_night + s.operator_margin + s.renewable_tariff + s.electricity_excise) * s.VAT | float }}
      {% else %}
        {% if now().hour >= 7 and now().hour < 22 %}
            {{ (s.summer_day + s.operator_margin + s.renewable_tariff + s.electricity_excise) * s.VAT | float }}
        {% else %}
            {{ (s.summer_night + s.operator_margin + s.renewable_tariff + s.electricity_excise) * s.VAT | float }}
        {% endif %}
      {% endif %}
    {% else %}
      {% if now().weekday() in (5,6) %}
          {{ (s.summer_night + s.operator_margin + s.renewable_tariff + s.electricity_excise) * s.VAT | float }}
      {% else %}
        {% if now().hour >= 7 and now().hour < 22 %}
            {{ (s.winter_day + s.operator_margin + s.renewable_tariff + s.electricity_excise) * s.VAT | float }}
        {% else %}
            {{ (s.winter_night + s.operator_margin + s.renewable_tariff + s.electricity_excise) * s.VAT | float }}
        {% endif %}
      {% endif %}
    {% endif %}'

edit: forgot the weekends. Added weekend if’s to use summer night rates.

1 Like

Please apologise for the delay. I had to re-install my Raspberry due to stupidness of myself.

Here you go. I also tried to format it as “0,25” instead “0.25” but have the same result.



"

The problem is on your sensor id missing the sensor. in the beginning:


It should be sensor.nordpool_kwh_dk1_dkk_3_10_025.

By the way, you will make my life easier if you share your YAML instead of screenshots. :wink:

When looking at Developer Tools > Status, don’t copy the screen from the “Set State” box. That one if for changing the state, not to see the current state, which is in the big table bellow this box.

Is it now the right box?

Haha. Okay, fair enough.
Still same error though.

# Loads default set of integrations. Do not remove.

default_config:

# Load frontend themes from the themes folder

frontend:

themes: !include_dir_merge_named themes

# Text to speech

tts:

- platform: google_translate

automation: !include automations.yaml

script: !include scripts.yaml

scene: !include scenes.yaml

powercalc:

template:

- sensor:

- name: Electricity selling price

unique_id: electricity_selling_price

unit_of_measurement: "DKK/kWh"

device_class: monetary

availability: "{{ is_number('sensor.nordpool_kwh_dk1_dkk_3_10_025') }}"

state: "{{ states('sensor.nordpool_kwh_dk1_dkk_3_10_025') | float(0) - 0.25 }}"

sensor:

- platform: template

sensors:

# Template sensor for values of power import (active_power > 0)

power_import:

friendly_name: "Power Import"

unit_of_measurement: 'W'

value_template: >-

{% if (states('sensor.shelly3em_channel_a_power')|float + states('sensor.shelly3em_channel_b_power')|float + states('sensor.shelly3em_channel_c_power')|float) > 0 %}

{{ states('sensor.shelly3em_channel_a_power')|float + states('sensor.shelly3em_channel_b_power')|float + states('sensor.shelly3em_channel_c_power')|float }}

{% else %}

{{ 0 }}

{% endif %}

availability_template: "{{

[ states('sensor.shelly3em_channel_a_power'),

states('sensor.shelly3em_channel_b_power'),

states('sensor.shelly3em_channel_c_power')

] | map('is_number') | min

}}"

# Template sensor for values of power export (active_power < 0)

power_export:

friendly_name: "Power Export"

unit_of_measurement: 'W'

value_template: >-

{% if (states('sensor.shelly3em_channel_a_power')|float + states('sensor.shelly3em_channel_b_power')|float + states('sensor.shelly3em_channel_c_power')|float) < 0 %}

{{ (states('sensor.shelly3em_channel_a_power')|float + states('sensor.shelly3em_channel_b_power')|float + states('sensor.shelly3em_channel_c_power')|float) * -1 }}

{% else %}

{{ 0 }}

{% endif %}

availability_template: "{{

[ states('sensor.shelly3em_channel_a_power'),

states('sensor.shelly3em_channel_b_power'),

states('sensor.shelly3em_channel_c_power')

] | map('is_number') | min

}}"

# Template sensor for values of power consumption

power_consumption:

friendly_name: "Power Consumption"

unit_of_measurement: 'W'

value_template: >-

{% if (states('sensor.power_export')|float(0)) > 0 and (states('sensor.power_solargen')|float(0) - states('sensor.power_export')|float(0)) < 0 %}

{% elif (states('sensor.power_export')|float(0)) > 0 and (states('sensor.power_solargen')|float(0) - states('sensor.power_export')|float(0)) > 0 %}

{{ (states('sensor.power_solargen')|float(0)) - states('sensor.power_export')|float(0) }}

{% else %}

{{ states('sensor.power_import')|float(0) + states('sensor.power_solargen')|float(0) }}

{% endif %}

# Sensor for Riemann sum of energy import (W -> Wh)

- platform: integration

source: sensor.power_import

name: energy_import_sum

unit_prefix: k

round: 2

method: left

# Sensor for Riemann sum of energy export (W -> Wh)

- platform: integration

source: sensor.power_export

name: energy_export_sum

unit_prefix: k

round: 2

method: left

# Sensor for Riemann sum of energy consumption (W -> Wh)

- platform: integration

source: sensor.power_consumption

name: energy_consumption_sum

unit_prefix: k

round: 2

method: left

utility_meter:

energy_import_daily:

source: sensor.energy_import_sum

name: Energy Import Daily

cycle: daily

energy_import_monthly:

source: sensor.energy_import_sum

name: Energy Import Monthly

cycle: monthly

energy_export_daily:

source: sensor.energy_export_sum

name: Energy Export Daily

cycle: daily

energy_export_monthly:

source: sensor.energy_export_sum

name: Energy Export Monthly

cycle: monthly

energy_consumption_daily:

source: sensor.energy_consumption_sum

name: Energy Consumption Daily

cycle: daily

energy_consumption_monthly:

source: sensor.energy_consumption_sum

name: Energy Consumption Monthly

cycle: monthly

yeap! :slight_smile:
This is the right one.

But what if you filter for the sensor sensor.nordpool_kwh_dk1_dkk_3_10_025 instead?

Ok, change the availability to this:

availability: "{{ is_number(states('sensor.nordpool_kwh_dk1_dkk_3_10_025')) }}"

Wooooohoo. The error message is gone. Now I need to see if the number counts upwards in approximately 14 hours when the sun is doing its thing.

I don’t know why yourself and many others are helping all the noobs like myself but I find it super cool!

1 Like

To see this:

:wink:

2 Likes

Today I don’t see the current value of the consumption in the header anymore, instead it shows the last value. It should be around 1,5 and not 0,7 Why?

Here is my code

type: custom:apexcharts-card
header:
  show: true
  title: Nordpool price 24h
  show_states: true
  colorize_states: true
graph_span: 1d
now:
  show: true
span:
  start: day
series:
  - entity: sensor.nordpool
    data_generator: |
      return entity.attributes.raw_today.map((p) => {
        return [new Date(p.start), p.value];
      });

Hello! Does any one send a notification with average, min, max prices as well as times when nordpool prices get updated? Care to share your code?

Anyone able to help me

I had done a few different versions of a sensor, but only needed one so i wanted to trim my configuration.yaml, and i am a fool so i did not make a copy of the original file, i just deleted and saved, and now this sensor is not working

It says configuration is invalid when i try to restart HA so i have to comment it out and save to be able to reload.

Sensor should just be doing simple math, subtracting one sensor from another to know what surplus i have.

I probably deleted something i should have, when deleting the other sensors.

This is what’s left in the configuration.yaml file.

   sensors:
      delta_t_solar_heating3:
        friendly_name: Surplus solar 3
        unit_of_measurement: W
        value_template: >-
          {{ ( states('sensor.pv_power') | float |
          round(0)) -  ( states('sensor.load_power') | float
          | round(0))}}  

Try remov8ng the “s” at the end of sensors:

It will look like this:

sensor:
      delta_t_solar_heating3:
        friendly_name: Surplus solar 3
        unit_of_measurement: W
        value_template: >-
          {{ ( states('sensor.pv_power') | float |
          round(0)) -  ( states('sensor.load_power') | float
          | round(0))}}

Thank you

Seems i messed up a bit more than i thought

If i do as you say i get another error

Here is the full file, can you spot what is wrong

# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

climate:
  - platform: touchline
    host: http://10.0.0.59

sensor:
      delta_t_solar_heating3:
        friendly_name: Surplus solar 3
        unit_of_measurement: W
        value_template: >-
          {{ ( states('sensor.pv_power') | float |
          round(0)) -  ( states('sensor.load_power') | float
          | round(0))}}  

After changing it to sensor i get this error when checking

Invalid config for [sensor]: required key not provided @ data[‘platform’]. Got None. (See /config/configuration.yaml, line 18).

PS. yes this is the full file, i am not a very advanced user :slight_smile:

you forgot the platform, this is template. And then indeed you can follow with “sensors” (as opposed to sensor).

Template - Home Assistant (home-assistant.io)

platform: template
sensors:
  delta_t_solar_heating:
    friendly_name: Surplus solar 3
    unit_of_measurement: W
    value_template: >-
      {{ ( states('sensor.pv_power') | float | round(0)) -  ( states('sensor.load_power') | float | round(0))}}  
  sensor2:
     etc

might be though mine is the old-fashioned syntax - does work.