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

Refresh of calculation methods #197

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
089f9f2
Refresh of calculation methods
Pluimvee Oct 7, 2024
fd9156b
Some small adjustements
Pluimvee Oct 7, 2024
0d07dcc
Some Todo's added
Pluimvee Oct 8, 2024
c4ca4f2
Merge pull request #1 from Pluimvee/Adding-comments-and-reschuffle-co…
Pluimvee Oct 8, 2024
139449d
Apply the formatting again
Pluimvee Oct 8, 2024
7fce573
renamed some analysis windows
Pluimvee Oct 8, 2024
2873cbe
Merge branch 'main' into Change-Calculation-Modes
Pluimvee Oct 8, 2024
9ceda93
Introducting Analysis Windows
Pluimvee Oct 8, 2024
1d15d7a
Readme updates
Pluimvee Oct 8, 2024
716ea8b
Added analysis window picture
Pluimvee Oct 8, 2024
8d02fc3
Data fetch needs to call refresh_analysis
Pluimvee Oct 8, 2024
30f2374
Merge branch 'Change-Calculation-Modes' of https://github.com/Pluimve…
Pluimvee Oct 8, 2024
5f8a116
As long as we do not have data for tommorrow, we return yesterday and…
Pluimvee Oct 8, 2024
71f47db
Change comment
Pluimvee Oct 8, 2024
2569b33
Code Format
Pluimvee Oct 9, 2024
cdd2a95
Update README.md
Pluimvee Oct 9, 2024
e604e67
Merge pull request #204 from Pluimvee/Adding-comments-and-reschuffle-…
Roeland54 Oct 10, 2024
0df5db6
Refresh of calculation methods
Pluimvee Oct 7, 2024
a204bf5
Some small adjustements
Pluimvee Oct 7, 2024
06fbeae
renamed some analysis windows
Pluimvee Oct 8, 2024
b5cec20
Introducting Analysis Windows
Pluimvee Oct 8, 2024
fd7d178
Readme updates
Pluimvee Oct 8, 2024
abc8554
Data fetch needs to call refresh_analysis
Pluimvee Oct 8, 2024
ccab378
Added analysis window picture
Pluimvee Oct 8, 2024
4162d75
As long as we do not have data for tommorrow, we return yesterday and…
Pluimvee Oct 8, 2024
5d56da6
Change comment
Pluimvee Oct 8, 2024
ad90cf5
Update README.md
Pluimvee Oct 9, 2024
a85173d
Merge branch
Pluimvee Oct 10, 2024
940726a
Some additional code comments
Pluimvee Oct 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 49 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ email address you entered during registration in the email body.

### Sensors
The integration adds the following sensors:
- Average Day-Ahead Electricity Price Today (This integration carries attributes with all prices)
- Highest Day-Ahead Electricity Price Today
- Lowest Day-Ahead Electricity Price Today
- Current Day-Ahead Electricity Price
- Current Percentage Relative To Highest Electricity Price Of The Day
- Next Hour Day-Ahead Electricity Price
- Current Electricity Price
- Next Hour Electricity Price

And some price analysis sensors:
- Average Day-Ahead Electricity Price (This integration carries attributes with all prices)
- Current Percentage Relative To Highest Electricity Price
- Current Percentage Relative To Spread Electricity Price
- Highest Day-Ahead Electricity Price
- Lowest Day-Ahead Electricity Price
- Time Of Highest Energy Price Today
- Time Of Lowest Energy Price Today

Expand Down Expand Up @@ -79,23 +82,46 @@ An example template is given below. You can find and share other templates [here
{% endif %}
{% endif %}
```
### Calculation method
This changes the calculated (min,max,avg values) entities behaviour to one of:

- Sliding
The min/max/etc entities will get updated every hour with only upcoming data.
This means that the min price returned at 13:00 will be the lowest price in the future (as available from that point in time).
Regardless of past hours that might have had a lower price (this is most useful if you want to be able to schedule loads as soon and cheap as possible)

- Default (on publish)
The min/max/etc entities will get updated once new data becomes available.
This means that the min price will update once the next days pricing becomes available (usually between 12:00 and 15:00)
It also means that until the next days pricing becomes available the latest 48h of available data will be used to calculate a min price

- Rotation
The min/max/etc entities will get updated at midnight.
This means that the min price returned at 23:59 will be based on the day x price while at 00:00 the day x+1 price will be the only one used in the calculations)
day x in this case is a random date like 2022-10-10 and day x+1 2022-10-11
### Analysis Window (previously called Calculation method)
The analysis window defines which period to use for calculating the min,max,avg & perc values.

![image](https://github.com/user-attachments/assets/c7978e26-1fa9-417b-9e2f-830f8b4ccd1f)

The analysis window can be set to:

- Publish (Default)

The min/max/etc entities will get updated once new data becomes available (usualy between 12:00 and 15:00)
It also means that until the next days pricing becomes available the analysis is performed on the latest 48h of available data (yesterday and today)

- Today

The analysis is performed on todays data. Sensor data will be updated at midnight

- Sliding-12

An analysis window of 12 hours which moves along with the changing hour. Meaning the analysis sensors change each hour.
The window starts 6-hours before tha last hour and ends 6 hrs after. So its using a 12 hour window to detect half-day low-/high price periods

- Sliding-24

Same as above but using a 24 hour sliding analysis window

- Forward-12

Same 12 hours sliding window, however starting from the last hour upto 12 hours beyond. Usefull to detect half-day min/max values whih occur in the future.

Note that because the sensors are updated each hour, the values may change just before you would expect a trigger to be fired. For example the timestamp of the minimum price may change to a later date when the analysis window shifts one hour and by this got another lower minimum price, included in the dataset. This situation may continue while lower prices keep on turning up in future hours while shifting the window. It may however help you to charge your EV at the lowest price in the comming days

- Forward-24

Same as above but using a 24 hour window.

Depricated
- Sliding. Please use 'forward-24'

- Rotation. Please use 'Today'



### ApexChart Graph
Expand Down
10 changes: 5 additions & 5 deletions custom_components/entsoe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
from homeassistant.helpers.typing import ConfigType

from .const import (
CALCULATION_MODE,
ANALYSIS_WINDOW,
CONF_API_KEY,
CONF_AREA,
CONF_ENERGY_SCALE,
CONF_CALCULATION_MODE,
CONF_ANALYSIS_WINDOW,
CONF_MODIFYER,
CONF_VAT_VALUE,
DEFAULT_MODIFYER,
Expand Down Expand Up @@ -45,16 +45,16 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
energy_scale = entry.options.get(CONF_ENERGY_SCALE, DEFAULT_ENERGY_SCALE)
modifyer = entry.options.get(CONF_MODIFYER, DEFAULT_MODIFYER)
vat = entry.options.get(CONF_VAT_VALUE, 0)
calculation_mode = entry.options.get(
CONF_CALCULATION_MODE, CALCULATION_MODE["default"]
analysis_window = entry.options.get(
CONF_ANALYSIS_WINDOW, ANALYSIS_WINDOW["default"]
)
entsoe_coordinator = EntsoeCoordinator(
hass,
api_key=api_key,
area=area,
energy_scale=energy_scale,
modifyer=modifyer,
calculation_mode=calculation_mode,
analysis_window=analysis_window,
VAT=vat,
)

Expand Down
22 changes: 11 additions & 11 deletions custom_components/entsoe/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@

from .const import (
AREA_INFO,
CALCULATION_MODE,
ANALYSIS_WINDOW,
COMPONENT_TITLE,
CONF_ADVANCED_OPTIONS,
CONF_API_KEY,
CONF_AREA,
CONF_CALCULATION_MODE,
CONF_ANALYSIS_WINDOW,
CONF_CURRENCY,
CONF_ENERGY_SCALE,
CONF_ENTITY_NAME,
Expand Down Expand Up @@ -94,7 +94,7 @@ async def async_step_user(
user_input[CONF_MODIFYER] = DEFAULT_MODIFYER
user_input[CONF_CURRENCY] = DEFAULT_CURRENCY
user_input[CONF_ENERGY_SCALE] = DEFAULT_ENERGY_SCALE
user_input[CONF_CALCULATION_MODE] = CALCULATION_MODE["default"]
user_input[CONF_ANALYSIS_WINDOW] = ANALYSIS_WINDOW["default"]

return self.async_create_entry(
title=self.name or COMPONENT_TITLE,
Expand All @@ -108,7 +108,7 @@ async def async_step_user(
CONF_ADVANCED_OPTIONS: user_input[CONF_ADVANCED_OPTIONS],
CONF_VAT_VALUE: user_input[CONF_VAT_VALUE],
CONF_ENTITY_NAME: user_input[CONF_ENTITY_NAME],
CONF_CALCULATION_MODE: user_input[CONF_CALCULATION_MODE],
CONF_ANALYSIS_WINDOW: user_input[CONF_ANALYSIS_WINDOW],
},
)

Expand Down Expand Up @@ -185,8 +185,8 @@ async def async_step_extra(self, user_input=None):
CONF_ENERGY_SCALE: user_input[CONF_ENERGY_SCALE],
CONF_VAT_VALUE: user_input[CONF_VAT_VALUE],
CONF_ENTITY_NAME: user_input[CONF_ENTITY_NAME],
CONF_CALCULATION_MODE: user_input[
CONF_CALCULATION_MODE
CONF_ANALYSIS_WINDOW: user_input[
CONF_ANALYSIS_WINDOW
],
},
)
Expand All @@ -212,12 +212,12 @@ async def async_step_extra(self, user_input=None):
CONF_ENERGY_SCALE, default=DEFAULT_ENERGY_SCALE
): vol.In(list(ENERGY_SCALES.keys())),
vol.Optional(
CONF_CALCULATION_MODE, default=CALCULATION_MODE["default"]
CONF_ANALYSIS_WINDOW, default=ANALYSIS_WINDOW["default"]
): SelectSelector(
SelectSelectorConfig(
options=[
SelectOptionDict(value=value, label=key)
for key, value in CALCULATION_MODE.items()
for key, value in ANALYSIS_WINDOW.items()
if key != "default"
]
),
Expand Down Expand Up @@ -286,7 +286,7 @@ async def async_step_init(
errors["base"] = "invalid_template"

calculation_mode_default = self.config_entry.options.get(
CONF_CALCULATION_MODE, CALCULATION_MODE["default"]
CONF_ANALYSIS_WINDOW, ANALYSIS_WINDOW["default"]
)

return self.async_show_form(
Expand Down Expand Up @@ -328,13 +328,13 @@ async def async_step_init(
),
): vol.In(list(ENERGY_SCALES.keys())),
vol.Optional(
CONF_CALCULATION_MODE,
CONF_ANALYSIS_WINDOW,
default=calculation_mode_default,
): SelectSelector(
SelectSelectorConfig(
options=[
SelectOptionDict(value=value, label=key)
for key, value in CALCULATION_MODE.items()
for key, value in ANALYSIS_WINDOW.items()
if key != "default"
]
),
Expand Down
15 changes: 9 additions & 6 deletions custom_components/entsoe/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,22 @@
CONF_CURRENCY = "currency"
CONF_ENERGY_SCALE = "energy_scale"
CONF_ADVANCED_OPTIONS = "advanced_options"
CONF_CALCULATION_MODE = "calculation_mode"
CONF_ANALYSIS_WINDOW = "analysis_window"
CONF_VAT_VALUE = "VAT_value"

DEFAULT_MODIFYER = "{{current_price}}"
DEFAULT_CURRENCY = CURRENCY_EURO
DEFAULT_ENERGY_SCALE = "kWh"

# default is only for internal use / backwards compatibility
CALCULATION_MODE = {
"default": "publish",
"rotation": "rotation",
"sliding": "sliding",
"publish": "publish",
ANALYSIS_WINDOW = {
"default": "publish",
"publish": "publish",
"today": "today",
"sliding-24": "sliding-24",
"sliding-12": "sliding-12", # new half day sliding
"forward-24": "forward-24", # 24hrs forward looking
"forward-12": "forward-12", # 12hrs forward looking
}

ENERGY_SCALES = { "kWh": 1000, "MWh": 1 }
Expand Down
Loading