mampfes / ha_epex_spot

Adds EPEX Spot data to Home Assistant.
MIT License
130 stars 19 forks source link

Show past Spot prices in HASS #17

Closed Robert-Riedl closed 1 year ago

Robert-Riedl commented 1 year ago

I'm aware of the history function, but I'd like to have a graph in apex charts, like the one you have on the README, for the past two days until tomorrow (if available).

I do this whith offset: '-2d' but that still doesn't show yesterday or the day before.

I've figured out it has to do with the data_generator portion

    data_generator: >
      return entity.attributes.data.map((entry, index) => { return [new
      Date(entry.start_time).getTime(), entry.price_eur_per_mwh]; });

i'm using this one for the awattar prices

    data_generator: >
      return entity.attributes.data.map((entry, index) => { return [new
      Date(entry.start_time).getTime(), entry.price_ct_per_kwh  * 1.03 * 1.2 ];
      });

If I remove this block, It does show me data from the past - but only the past.

Any idea how to fix this ?

mampfes commented 1 year ago

This integration only fetches data for the current and the next day - and discards older data automatically. If you want to have more data from the past, you could either fetch more data or keep the already fetched data.

Fetching more data should be easy with the Awattar source: https://github.com/mampfes/ha_epex_spot/blob/601de53eda01465afb9bfa25e6bd04da72c9f5ed/custom_components/epex_spot/EPEXSpot/Awattar/__init__.py#L71 If you modify the calculation of the start point in time you should get more data.

Keeping more data is more effort. Not sure yet if I want to add this as a general feature.

Robert-Riedl commented 1 year ago

@mampfes I don't think its necessary to modify the code of the integration though ? if i do

type: custom:apexcharts-card
header:
  show: true
  title: Aktueller Spot Strompreis drei tage
graph_span: 72h
hours_12: false
span:
  start: day
  offset: '-2d'
now:
  show: true
  label: Now
yaxis:
  - min: 0
series:
  - entity: sensor.epex_spot_price_ct_per_kwh
    name: Aktueller Strompreis ct/kWh
    type: column
    extend_to: end
    unit: ct/kWh

then I get some data from the past, since HA stores 10 days of data per default.

image

Its just a matter of getting the java script correct to display past, present and future data (with * 1.03 * 1.2 to get the true price) with data_generator

But I can't seem to figure it out

mampfes commented 1 year ago

There is an example configuration for ApexCharts in the FAQ which shows previous, current and future data in one chart. And I'm working on a configurable net price sensor so that you don't have to adjusted the values in the data generator any more.

mampfes commented 1 year ago

25