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

Feature request: Get 24h forecast of prices #3

Closed
blowk opened this issue Sep 29, 2022 · 32 comments
Closed

Feature request: Get 24h forecast of prices #3

blowk opened this issue Sep 29, 2022 · 32 comments
Labels
enhancement New feature or request

Comments

@blowk
Copy link
Contributor

blowk commented Sep 29, 2022

Maybe it should be interested if we could get a price range for 24h, so you can create an chart with for example ApexCharts card

I see in the readme of https://github.com/EnergieID/entsoe-py, there is query_imbalance_prices
client.query_imbalance_prices(country_code, start, end, psr_type=None)

@JaccoR JaccoR added the help wanted Extra attention is needed label Sep 29, 2022
@JaccoR
Copy link
Owner

JaccoR commented Sep 30, 2022

Why do you need the imbalance prices for this and not the day ahead prices? Aren't the imbalance prices only available a couple of seconds before the energy is actually used?

The code is already set up to fetch the day ahead prices of the whole day. However, now it only saves the current price to the database and not the whole day. It's indeed a nice feature to have and when I have time I will look into it.

Does anyone know of an integration that does something similar (adding future data to a sensor) so we can look how its done?

@blowk
Copy link
Contributor Author

blowk commented Sep 30, 2022

Yes, you're right.

The day ahead prices needs only to be loaded just after midnight so we could it use it in HA automations.
Couldn't this be done to store the array data as attributes in the sensor?

Sorry, I'm new to dev HA integrations and python.

@JaccoR JaccoR added the enhancement New feature or request label Sep 30, 2022
@JaccoR JaccoR changed the title Feature request: Get imbalance prices Feature request: Get 24h forecast of prices Oct 1, 2022
@JaccoR
Copy link
Owner

JaccoR commented Oct 1, 2022

@JanLankhorst that would probably work, but it feels more like a work around to make a seperate sensors for every hour. I would argue that, for example, "hour 1" is a current state (or state attribute). Ideally you would want to have one sensor that would have data on the future hours so you can plot these.

Found this issue about forecast states. Apparently there is currently no support for future values in home assistant. So it would be very hard to implement this.

Some extremely powerful automations can be made with future values. I can add some more sensors for a couple of hours, or some time states of the time at which prices are highest or lowest. However, having 24 sensors for every hour is not my preference. What do you think?

@ronaldt80
Copy link

Relative levels would be awesome, or working with attributes? 1 sensor with up-to 24 attributes should be possible I guess?; my use case is a home battery; typically there are two peaks a day; one in the morning and one in the early evening. My intention is to buy cheap twice a day and sell (taking into account expected own usage) at the peak levels; also taking into account expected PV yield and car battery "headroom".

The invertor I intend to buy supports setting up 6 daily timeslots through mod bus.

Next step would be to pre heat the buffer supply of the heat pump (provided I manage to get one!)

@JaccoR
Copy link
Owner

JaccoR commented Oct 2, 2022

@ronaldt80 What do you mean with relative sensors? I added a sensor that shows the current price as a percentage of the maximum price of the day, as I wanted to turn off the heat pump at the peaks above 70% of the max. Is that what you mean as well?

Attributes may indeed be a good option I think. However making graphs with this is not very user friendly. How would you use these 24 attributes in your system?

Btw, what battery do you use? I am looking for such a system myself as well.

@ronaldt80
Copy link

I'm looking into a 3 phase 8/10/12kw deye inverter combined with 3 5kwh battery units. Challenge is finding an electrician.

Advantage of deye is that the modbus can be used to plot a charge/discharge pattern - raspberry pi and esphome both possible.

@stigvi
Copy link

stigvi commented Oct 2, 2022

Does anyone know of an integration that does something similar (adding future data to a sensor) so we can look how its done?

The Nordpool integration has this, but it splits the prices in "today" and "tomorrow" with 24 different prices in each. That makes it difficult to use in HA because one night prices is in two different lists. The format is something like this

`unit_of_measurement: NOK
raw_price:

  • start: '2022-10-02T00:00:00+02:00'
    end: '2022-10-02T01:00:00+02:00'
    value: 1.424787

  • start: '2022-10-02T01:00:00+02:00'
    end: '2022-10-02T02:00:00+02:00'
    value: 1.4179

  • start: '2022-10-02T02:00:00+02:00'
    end: '2022-10-02T03:00:00+02:00'
    value: 1.338575

  • start: '2022-10-02T03:00:00+02:00'
    end: '2022-10-02T04:00:00+02:00'
    value: 1.389425

  • start: '2022-10-02T04:00:00+02:00'
    end: '2022-10-02T05:00:00+02:00'
    value: 1.35155

  • start: '2022-10-02T05:00:00+02:00'
    end: '2022-10-02T06:00:00+02:00'
    value: 1.356188

  • start: '2022-10-02T06:00:00+02:00'
    end: '2022-10-02T07:00:00+02:00'
    value: 1.3542`

    This format makes it easy to make template sensors for X cheapest hours for a day

    • unique_id: cheapest_hours_1_4
      name: cheapest_hours_1_4
      state: >-
      {% set l=state_attr('sensor.nordpool', 'raw_today')|sort(attribute='value') %}
      {% set t = now() %}
      {{ (t >= l[0].start and t <= l[0].end)
      or (t >= l[1].start and t <= l[1].end)
      or (t >= l[2].start and t <= l[2].end)
      or (t >= l[3].start and t <= l[3].end) }}

Skjermbilde 2022-10-02 185901

@blowk
Copy link
Contributor Author

blowk commented Oct 2, 2022

Only add attribute data per 24h after midnight so you can use this data in HA automation.
In this way, there is no split and you use the tomorrow data for the current day.
The tomorrow energy data can only fetched after a specific hour I think.

@JanLankhorst
Copy link

@blowk That would be my suggestion also. This approach makes it useful for calculation in HA.

@JaccoR
Copy link
Owner

JaccoR commented Oct 3, 2022

Alright, i managed to get the attributes into this format in the new commit:
image

To also get the times is a bit more work, but it can be possible.

This can be done in the format @stigvi mentioned. Another approach would be having separate attributes per hour. I am not sure which one would be more convenient.

@blowk
Copy link
Contributor Author

blowk commented Oct 4, 2022

The format @stigvi mentioned should be ok.

today_prices: 0.223, 0.197, 0.206, 0.169, 0.188, 0.197, 0.33, 0.427, 0.497, 0.209, 0.185, 0.154, 0.148, 0.149, 0.135, 0.14, 0.165, 0.184, 0.377, 0.252, 0.252, 0.169, 0.165, 0.147

would be like this, no?

today_prices:

  • price: 0.223
    datetime: '2022-10-04T09:00:00+00:00'
  • price: 0.197
    datetime: '2022-10-04T10:00:00+00:00'
  • price: 0.206
    datetime: '2022-10-04T11:00:00+00:00'
  • price: 0.169
    datetime: '2022-10-04T12:00:00+00:00'
  • price: 0.188
    datetime: '2022-10-04T13:00:00+00:00'
  • price: 0.197
    datetime: '2022-10-04T14:00:00+00:00'

@JaccoR
Copy link
Owner

JaccoR commented Oct 4, 2022

In your example: 0.223 will correspond with 00:00-01:00, 0.197 with 01:00-02:00 etc.

When I have time this week I will look into getting the times in there as well. The format will probably look something like this:

  • price: 0.223
    hour: '2022-10-04T00:00:00+02:00'
  • price: 0.197
    hour: '2022-10-04T01:00:00+02:00'
    etc.

@stigvi
Copy link

stigvi commented Oct 4, 2022

In your example: 0.223 will correspond with 00:00-01:00, 0.197 with 01:00-02:00 etc.

When I have time this week I will look into getting the times in there as well. The format will probably look something like this:

  • price: 0.223
    hour: '2022-10-04T00:00:00+02:00'
  • price: 0.197
    hour: '2022-10-04T01:00:00+02:00'
    etc.

That would be great. With timestamps, it is possible to sort this list based on price and it would be easy to find the cheapest or most expensive N hours.

@JaccoR
Copy link
Owner

JaccoR commented Oct 6, 2022

Managed to get the timestamped prices in the attributes in the new commit. Let me know if you have any issues.

@mmoerdijk
Copy link

mmoerdijk commented Oct 6, 2022

Thanks!. Seems to work for me:

type: custom:apexcharts-card
experimental:
  color_threshold: true
graph_span: 24h
span:
  start: day
now:
  show: true
  label: Now
header:
  show: true
  title: Day ahead prices (€/kwh)
series:
  - entity: sensor.average_electricity_price_today
    name: Gemiddelde prijs
    opacity: 0.7
  - entity: sensor.average_electricity_price_today
    name: Prijs per uur
    stroke_width: 2
    type: column
    opacity: 1
    color_threshold:
      - value: -10
        color: green
        opacity: 1
      - value: 0
        color: blue
      - value: 0.3
        color: orange
      - value: 0.5
        color: red
    data_generator: |
      return entity.attributes.timestamped_prices.map((record, index) => {
              return [record.time, record.price];
            });

image

@stigvi
Copy link

stigvi commented Oct 6, 2022

Looks good. But I have only today's prices in my HA. Should tomorrows prices be in that list, also?

@mmoerdijk
Copy link

The prices are only published one day ahead

@stigvi
Copy link

stigvi commented Oct 6, 2022

Thats is unfortunate. It makes planning car charging from 22:00 to 06:00 not so easy. And a little bit strange because prices for friday is available mid day on thursday in Norway.

Edit: When I look at transparency.entsoe, I see that prices for tomorrow is indeed available

@mmoerdijk
Copy link

Oh that is interesting, it would probably be possible to make a sensor with the data for as far ahead as the data goes

@stigvi
Copy link

stigvi commented Oct 6, 2022

I hope so. If I can have a list with today and tomorrows prices, it is easy to select the elements from 22:00 to 06:00 next day, sort it on price and then select the 4 cheapest hours.

@JaccoR
Copy link
Owner

JaccoR commented Oct 6, 2022

Prices of the day after come available some time in the afternoon I think (my guess is at 15:00). Can't find anything about it online though. We'll have to watch at what time prices of the following day are available. Extending the forecast would be nice indeed.

The code is setup to fetch from 00:00 till 23:00 and all sensors are based on that, so this would mean a fairly big overhaul of how the integration fetches prices and calculates max, min and avg.

@blowk
Copy link
Contributor Author

blowk commented Oct 7, 2022

Thanks!. Seems to work for me:

type: custom:apexcharts-card
experimental:
  color_threshold: true
graph_span: 24h
span:
  start: day
now:
  show: true
  label: Now
header:
  show: true
  title: Day ahead prices (€/kwh)
series:
  - entity: sensor.average_electricity_price_today
    name: Gemiddelde prijs
    opacity: 0.7
  - entity: sensor.average_electricity_price_today
    name: Prijs per uur
    stroke_width: 2
    type: column
    opacity: 1
    color_threshold:
      - value: -10
        color: green
        opacity: 1
      - value: 0
        color: blue
      - value: 0.3
        color: orange
      - value: 0.5
        color: red
    data_generator: |
      return entity.attributes.timestamped_prices.map((record, index) => {
              return [record.time, record.price];
            });

image

Thanks for the input.
Made an update because the price will be rounded to one decimals.
Just adding float_precision: 3 to your entitty serie will do the job.

type: custom:apexcharts-card
experimental:
  color_threshold: true
graph_span: 24h
span:
  start: day
now:
  show: true
  label: Now
header:
  show: true
  title: Day ahead prices (€/kwh)
series:
  - entity: sensor.average_electricity_price_today
    name: Gemiddelde prijs
    opacity: 0.7
    loat_precision: 3
  - entity: sensor.average_electricity_price_today
    name: Prijs per uur
    stroke_width: 2
    type: column
    opacity: 1
    float_precision: 3
    color_threshold:
      - value: -10
        color: green
        opacity: 1
      - value: 0
        color: blue
      - value: 0.3
        color: orange
      - value: 0.5
        color: red
    data_generator: |
      return entity.attributes.timestamped_prices.map((record, index) => {
              return [record.time, record.price];
            });

@JaccoR
Copy link
Owner

JaccoR commented Oct 7, 2022

I will make some small changes to the attributes to fetch the prices of the day after. I deleted the non timestamped price list, as i don't think it is necessary. Let me know if I am wrong on this.

The timestamped attributes will now ditch the "timestamped" term and be called prices_today, which contains prices of today, prices_tomorrow which contains prices of tomorrow and prices which contains everything that is available on that point in time (today + tomorrow if available).
The max, min and avg still refer to the prices of today.

@blowk in your case it means that if you only want to show the prices of today in the graph you need to change data_generator to:

data_generator: |
      return entity.attributes.prices_today.map((record, index) => {
              return [record.time, record.price];
            });

@stigvi @mmoerdijk I think with this you should be able to have the data for as far ahead as the data goes and select the cheapest hours between 22:00 and 6:00 after the prices of the following day are available by calling the prices attribute.

If everything works I will commit it in a few hours.

@JaccoR JaccoR removed the help wanted Extra attention is needed label Oct 7, 2022
@blowk
Copy link
Contributor Author

blowk commented Oct 7, 2022

@JaccoR Thanks for the changes!
I made a 48h Apex chart for it.

type: custom:apexcharts-card
graph_span: 48h
span:
  start: day
now:
  show: true
  label: Now
header:
  show: true
  title: Day ahead prices (€/kwh)
series:
  - entity: sensor.current_electricity_market_price
    stroke_width: 2
    float_precision: 3
    type: column
    opacity: 0.3
    color: '#1007f0'
    data_generator: |
      return entity.attributes.prices_today.map((record, index) => {
        return [record.time, record.price];
      });
  - entity: sensor.average_electricity_price_today
    stroke_width: 2
    float_precision: 3
    type: column
    opacity: 0.3
    color: '#07bef0'
    data_generator: |
      return entity.attributes.prices_tomorrow.map((record, index) => {
        return [record.time, record.price];
      });

IMG_20221007_172512.jpg

@ronaldt80
Copy link

Tried a bit of templating but get stuck on the format of the time value. Could it be the time is stored as a string where as the nordpool integration records it as a time value?

What I want to do:

  • Compare each value to its two immediate neighbors (-1 and +1 hour); if it's lower to both its a trough, if its higher than both its a peak.

  • determine the 3 consecutive lowest hours (being ideal moment to charge the car, turn on laundry machine etc). Much like this;
    home assistant community forum

Any help would be much appreciated

@ronaldt80
Copy link

And question, does anyone know why the apex card prints the last value of the series in the legend? Eg. in the above example 0.149 and 0.234?

@JaccoR
Copy link
Owner

JaccoR commented Oct 10, 2022

@ronaldt80 Yes the time is a string, I thought converting it to a string was the only way to get it into attributes as timevalues gave some errors. I also thought that the nordpool integration converted it to a string hence the quotation marks. Do you know this?

And question, does anyone know why the apex card prints the last value of the series in the legend? Eg. in the above example 0.149 and 0.234?

That's the way @blowk set it up. Its the value of the sensors used for plotting the attributes (entity: sensor.average_electricity_price_today and entity: sensor.current_electricity_market_price)

@blowk
Copy link
Contributor Author

blowk commented Oct 10, 2022

@ronaldt80 : you can also plot one serie in apex chart and use the prices attribute, so it will plot all price of 48 hours. Before noon, the prices for the next day will not be available, but in the afternoon it will be updated.
This will be the view without footer.

type: custom:apexcharts-card
graph_span: 48h
span:
  start: day
now:
  show: true
  label: Now
header:
  show: true
  title: Day ahead prices (€/kwh)
series:
  - entity: sensor.current_electricity_market_price
    stroke_width: 2
    float_precision: 3
    type: column
    opacity: 0.3
    color: '#1007f0'
    data_generator: |
      return entity.attributes.prices.map((record, index) => {
        return [record.time, record.price];
      });

IMG_20221010_143904.jpg

@blowk
Copy link
Contributor Author

blowk commented Oct 11, 2022

I will close this issue because the feature is now already included in the integration.

@blowk blowk closed this as completed Oct 11, 2022
@ikke-zelf
Copy link

And question, does anyone know why the apex card prints the last value of the series in the legend? Eg. in the above example 0.149 and 0.234?

    show:
      legend_value: false

@ronaldt80
Copy link

Thanks!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants