Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
BrainDra1n opened this issue May 24, 2024 · 4 comments
Closed

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

BrainDra1n opened this issue May 24, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@BrainDra1n
Copy link

BrainDra1n commented May 24, 2024

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:

  • a time_zone is used and thus could be off by -1 or+1 hours.
  • a distinction is made in processing logic between today and tomorrow

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

  • The TimeZone used by HA is used to query the ENTSO-e API.
  • The HA TimeZone is 'local' to me: UTC+02:00
  • The ENTSO-e TimeZone is UTC.
  • This could explain a mismatch of a couple of hours. And probably different for summer and winter because of daylight savings time.
    But my search then ends in a call to EntsoePandasClient in module enstoe. This module I can not find the source code for.

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
Copy link
Author

BrainDra1n commented Jun 6, 2024

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
Copy link
Collaborator

Roeland54 commented Sep 12, 2024

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
Copy link
Collaborator

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

@Roeland54
Copy link
Collaborator

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.

Repository owner locked and limited conversation to collaborators Sep 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants