JaccoR / hass-entso-e

Integration for Home Assistant to fetch day ahead energy prices from European countries via ENTSO-e Transparency Platform
Apache License 2.0
173 stars 28 forks source link

Todays average prices missing from 23:00 to 24:00 #157

Closed BrainDra1n closed 1 week ago

BrainDra1n commented 4 months ago

At 23:00 the sensor.average_electricity_price_today has no today's prices, but still has tomorrow's prices. When it becomes 24:00 all prices are correct again.

I suspect that this is caused by timezone / daylight savings time. But still investigating it. This is what I know now.

My setup: Core 2024.5.4 Supervisor 2024.05.1 Operating System 12.3 Frontend 20240501.1 hass-entso-e 0.0.1 Timezone: GMT+01:00) Amsterdam Current date: 24 may 2024, so no daylight savings time at this moment.

Findings: The sensor.average_electricity_price_today contains the following attributes:

state_class: measurement unit_of_measurement: €/kWh attribution: Data provided by ENTSO-e Transparency Platform device_class: monetary icon: mdi:currency-eur friendly_name: Average electricity price today (Energy Prices) prices_today: see below prices_tomorrow: see below prices: see below

The three price attributes show the issue. At all times 'prices' contain a list of today's and tomorrow's prices, if available. Until 23:00 the 'prices_today' contains a list of today's prices. From 23:00 until 24:00 this list becomes empty. At all times 'prices_tomorrow' contains tomorrow's prices, if available.

In my situation I use the Day Ahead Prices for The Netherlands. The prices for tomorrow are available from ~15:00 today. From that time, the attribute prices_tomorrow is filled. At 24:00 the prices_tomorrow becomes an empty list. This is all normal behaviour.

At 23:00 when 'prices_today' becomes an empty list, the 'prices' list still contains all prices both today and tomorrow. I'm not sure what triggers this effect. It could be the hourly timer event used to update the prices from ENTSO-e.

I have tried to determine where this issue could be caused in the source code. But as I'm new to HA, Python, Jinja2 and all other languages used, this is not so easy.

One possible location is in the file coordinator.py which contains:

class EntsoeCoordinator(DataUpdateCoordinator):
    """Get the latest data and update the states."""

<snip>

async def _async_update_data(self) -> dict:
        """Get the latest data from ENTSO-e"""
        self.logger.debug("Fetching ENTSO-e data")
        self.logger.debug(self.area)

        time_zone = dt.now().tzinfo
        # We request data for yesterday up until tomorrow.
        yesterday = pd.Timestamp.now(tz=str(time_zone)).replace(hour=0, minute=0, second=0) - pd.Timedelta(days = 1)
        tomorrow = yesterday + pd.Timedelta(hours = 71)

        data = await self.fetch_prices(yesterday, tomorrow)

        <snip: functions continues...>

This seems the only place in the source code where:

The 'strange' thing I see happening here, is:

So who could help analyze this behaviour further? If a solution can be found, I'm willing to learn how to use git, update and publish the code.

BrainDra1n commented 3 months ago

I now have an example of this effect happening. The results are for Thursday 06-06-2024. The following picture are from 23:15 and show:

entity sensor.average_electricity_price_today contains attributes: state_class: measurement unit_of_measurement: €/kWh attribution: Data provided by ENTSO-e Transparency Platform device_class: monetary icon: mdi:currency-eur friendly_name: Average electricity price today (Energy Prices) prices_today: list of prices for tomorrow in stead of today prices_tomorrow: list is empty prices: list of prices for today and tomorrow

Which looks like this in the State inspector:

Average_electricity_price_today at 2315h part1 Average_electricity_price_today at 2315h part2

After 24:00 this changes to:

prices_today: list of prices for yesterday. the values of today before 24:00 prices_tomorrow: list of prices for today. the values of tomorrow before 24:00 prices: list of prices for yesterday and today Which is still incorrect.

At 01:00 it changes again and becomes 'normal' as intended:

prices_today: list of prices for today. the values after 24:00 prices_tomorrow: list is empty. which is correct as tomorrow's prices are not available yet. prices: stil the list of prices for yesterday and today. But with correct dates, so no incorrect information.

As I'm using the integration as input for the EV Smart Charging integration. It gets confused when scheduling charging of my car around 23:00.

Roeland54 commented 2 weeks ago

~~The beta version of v0.5.0 contains a complete rework of this logic. Can you test and provide feedback?~~

Just looked at the logic and is seems the issue is still there. Aiming to fix this in the next beta.

Roeland54 commented 2 weeks ago

Should be fixed in the latest beta (v0.5.0-beta2)

Roeland54 commented 1 week ago

v0.5.0 is released. The discussed issues should be solved. Please feel free to open a new issue if you feel this is needed.