Any good ideas are welcome. Nordpool Energy Price per hour

In Nordics the energy-price is set on a stock market the day before. The price is set per hour and are published on multiple places.
Example:
https://www.nordpoolgroup.com/Market-data1/#/nordic/table

Nordpool themselves also have a API for fetching and trading (I assume they don’t give out login to everyone)

So aim trying to come up with a way to update a sensor with the values from the price.
So the sensor displays the current price but also holds history so price for both history hours and the coming hours exist in the system.

I currently only have history and current values from a IFTTT integration (using service called Bright)

If anyone done this before or have a great ide it would be welcome.

//nicklas

Use a scrape sensor. Something like this could work

sensor:
  - platform: scrape
    resource: https://elen.nu/timpriser-pa-el-for-elomrade-se3-stockholm/
    name: Electricity price
    select: ".elspot-content"
    value_template: '{{ value.split(" ")[0] }}'
    unit_of_measurement: "öre/kWh"
3 Likes

Thanks allot fabaff

This works great for pulling the current value. (much better then the current IFTTT i have)

Optimal function i’am trying to get the full content further down on the page that contains all values for the day

										<td>
											2017-12-05 00:00											</td>
										<td class="align-right">28.59 öre/kWh</td>
									</tr>
																			<tr>
										<td>
											2017-12-05 01:00											</td>
										<td class="align-right">28.07 öre/kWh</td>
									</tr>

This then repeats until 24 values

So its both the time and the price that aim trying to get.

Please correct me, but i do not see how that would be possible with scraper.
Hopefully aim wrong, I am hopeless with these strings

Again aim really thankful that you did take the time to look at this.

If i find another solution i will post back here. Must be a few more Swedish people that would like to know the hourly prices in advance, enabling automatstations that prevent energy spikes during expensive hours.

To get the full table you need a sensor as a custom_component that is able to store the past and the future values as attributes or 24 scrape sensors :slight_smile:

ok not used this before. will read up on it and see.

Thanks again Fabaff

Somethings like this could work.

import asyncio
import logging
from datetime import timedelta

import aiohttp
import async_timeout

import voluptuous as vol

from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import CONF_NAME
from homeassistant.helpers.entity import Entity
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.aiohttp_client import async_get_clientsession


_LOGGER = logging.getLogger(__name__)

DEFAULT_NAME = 'Electricity Price'
_RESOURCE = 'https://elen.nu/timpriser-pa-el-for-elomrade-se3-stockholm/'

SCAN_INTERVAL = timedelta(hours=2)

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
})


@asyncio.coroutine
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
    """Set up the Swedish Electricity Price sensor."""
    name = config.get(CONF_NAME)

    async_add_devices([SwedishElectricityPriceSensorSensor(hass, name)], True)


class SwedishElectricityPriceSensorSensor(Entity):
    """Implementation of a Swedish Electricity Price sensor."""

    def __init__(self, hass, name):
        """Initialize the Swedish Electricity Price sensor."""
        self.hass = hass
        self._name = name
        self._state = None
        self.attrs = {}
        self._unit_of_measurement = 'öre/kWh'

    @property
    def name(self):
        """Return the name of the sensor."""
        return self._name

    @property
    def state(self):
        """Return the state of the device."""
        return self._state

    @property
    def unit_of_measurement(self):
        """Return the unit of measurement of this entity, if any."""
        return self._unit_of_measurement

    @property
    def device_state_attributes(self):
        """Return the state attributes of the sensor."""
        return self.attrs

    @asyncio.coroutine
    def async_update(self):
        """Get the latest data from website and update the state."""
        from bs4 import BeautifulSoup

        try:
            session = async_get_clientsession(self.hass)
            with async_timeout.timeout(5, loop=self.hass.loop):
                req = yield from session.get(_RESOURCE)
        except (asyncio.TimeoutError, aiohttp.ClientError):
            _LOGGER.error("Error while accessing: %s", self._url)
            return False

        data = yield from req.text()
        soup = BeautifulSoup(data, 'html.parser')
        keys = ['labels', 'data']
        content = []
        for line in str(soup.find_all('script')[10]).splitlines():
            if line.split(':')[0].strip() in keys:
                content.append(str(line.split(' ')[1].strip().replace('[', '').replace('],', '')))

        self.attrs = dict(zip(content[1].split(','), content[2].split(',')))
        self._state = "The current values"
5 Likes

wow what a answer and time you put into this. Iam blown away
Thanks allot
i will test it out and get report back

You can also use the tibber sensor if you are a Tibber customer.

Sorry not a tibber customer.

I am also interested in this.

There is Entso-e platform where you can get the same energy price data in many countries in Europe:
https://transparency.entsoe.eu
https://transparency.entsoe.eu/transmission-domain/r2/dayAheadPrices/show

You can get API key by signing in and sending mail to address [email protected], Title: Restful API access, Message: your sign in email address.

I also found a python client:

It would be great to have a component in HASS for many countries. I do not have skill (and time) to implement this in HASS so I just leave this here.

1 Like

You might look into this custom component, I am using latest development version now and it proved to work very well so far:
https://bitbucket.org/OlavAndre/nordpool/wiki/Home

2 Likes

great, thanks will have a look

Thanks, works great!

Thanks! Works great also here.

Wishlist would include a graph for day-ahead-prices (the future hours). :slight_smile:

2 Likes

As for the data source - I’ve been using http://datafeed.expektra.se/datafeed.svc/spotprice since 2014. Gives you the prices from current hour to the last hour of the next day. You can set the bidding area and currency and choose between XML and JSON output.

Here is a Tibber energy price screenshot
20

Gage card

14

This custom component is working pretty nicely, but how i could make today and tomorrow as graph? And best if i could make some colors, like green for below 0,005€ and red beyond?

is your current price shifted for your timezone or you get prices by CEST (Swedish time)?

Actually it is one hour off, so i have to figure out how to fix that too.
And also it would be nice to add that extra 0,003€ fee for electric company.

you might be interested to read through this:
https://github.com/custom-components/nordpool/pull/4#event-2642324775
There is a macro that can help you add fees. Note that there are some brackets missing from tariff formulas, but these are easy to find.
Timezone error still seems to be a bug in code. Hope that this gets solved at some point.

1 Like