kalkih / mini-graph-card

Minimalistic graph card for Home Assistant Lovelace UI
MIT License
3.01k stars 233 forks source link

Feature request: Render future graph #459

Closed cibernox closed 3 years ago

cibernox commented 4 years ago

I use this component for almost all my graphs and it's great. I've however identified a feature that would be useful, but perhaps too niche: Render not only past values but also future values.

For instance, I'm on an electric tariff with two time periods and I've created this beautiful bar graph with the electric prices:

Screen Shot 2020-10-04 at 00 22 40

Price is different every hour. And every day at 8PM the prices for the next day are published. So I know in advance what the graph for the next day will be. And in fact it's more useful to me to display what the prices will be than what the price was.

I'd like to be able to render a graph that instead of the last 24h, it shows me the last 12h and the future 12h (probably styled slightly different).

For completion, this is the HA sensor I have for the prices:

attribution: Data retrieved from api.esios.ree.es by REE
tariff: discrimination
min_price: 0.01558
min_price_at: 4
next_best_at:
  - 4
  - 5
  - 6
  - 3
  - 12
  - 7
  - 8
  - 11
  - 9
  - 2
  - 10
  - 1
  - 23
  - 0
  - 15
  - 14
  - 16
  - 17
  - 13
  - 18
  - 19
  - 22
  - 21
  - 20
price_00h: 0.0387
price_01h: 0.02893
price_02h: 0.02531
price_03h: 0.01784
price_04h: 0.01558
price_05h: 0.0159
price_06h: 0.01691
price_07h: 0.02029
price_08h: 0.02084
price_09h: 0.02514
price_10h: 0.02602
price_11h: 0.02148
price_12h: 0.01954
price_13h: 0.08203
price_14h: 0.07873
price_15h: 0.07639
price_16h: 0.08001
price_17h: 0.08043
price_18h: 0.08714
price_19h: 0.09637
price_20h: 0.11291
price_21h: 0.1089
price_22h: 0.10805
price_23h: 0.03844
unit_of_measurement: €/kWh
friendly_name: Precio Electricidad
icon: 'mdi:currency-eur'

Is there any feature that allows this already?

I considered that I could create some sort of virtual sensor in HA but that displays the value 4h in the future, and make the graph card track that sensor instead, but I don't know how would I display the current price in the top-left corner if I did that, or how I'd display the past hours and the future hours with different colors (perhaps with a slight transparency)

thejonesyboy commented 4 years ago

I completely agree and this would be HUGE feature for minimal effort.

Another additional feature would be to set a fixed time window (e.g. 'today', which is a fixed 24 hour window), so that the axis is fixed and data is plotted from left to right as time progresses, rather than showing a fixed length of time in the past. This would then be able to show future data (if it exists). It would also be great to be able to create daily power generation graphs such as this:

image

RomRider commented 3 years ago

Home assistant doesn't provide data from the future so that is unfortunately not possible. The data comes from the history component of home assistant (and as its name states it, it stores only historical data 😊)

As for your other request the @thejonesyboy, it is a duplicate of some other requests already, like #486.

I'm closing this.

cibernox commented 3 years ago

@RomRider that's not accurate. It's true that this components only renders values at a certain time, but that time doesn't have to be NOW. For the electricity for instance I know in advance all the values the graph, past, present and future (to a certain extent, prices of the next day are published at 7pm). For instance I could have a sensor that gives the the price of electricity 4 hours into the future and if I plotted that sensor using this component I'd be rendering data from the future, right? 😄

What would be missing tho is a way of style the last 4 bars of the graph a bit different (because I know they are in the future) from all the previous bars (because they are in the past), or maybe all but the one of the current time range (the present price of the electricity).

The real missing feature here is a way of style the bars (or the line if using a chart) differently starting at one point in the X axis.

thejonesyboy commented 3 years ago

My point exactly! Yet far better expressed, thank you.

On Wed, 20 Jan 2021, 8:19 am Miguel Camba, notifications@github.com wrote:

@RomRider https://github.com/RomRider that's not accurate. It's true that this components only renders values at a certain time, but that time doesn't have to be NOW. For the electricity for instance I know in advance all the values the graph, past, present and future. For instance I could have a sensor that gives the the price of electricity 4 hours into the future and if I plotted that sensor using this component I'd be rendering data from the future, right? 😄

What would be missing tho is a way of style the last 4 bars of the graph a bid different (because I know they are in the future) from all the previous bar (because they are in the past), or maybe all but the one of the current time range (the present price of the electricity).

The real missing feature here is a way of style the bars (or the line if using a chart) differently starting at one point in the X axis.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/kalkih/mini-graph-card/issues/459#issuecomment-763236123, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGYGQYT3A7UWRL6IGVTQSDS2YORFANCNFSM4SDJNFJA .

RomRider commented 3 years ago

I think I am accurate ;)

You have to understand how home assistant works:

Since we rely on what homeassistant provides, we can't graph future data. That's how it is :shrug: and is very unlikely to change in home assistant.

For the sake of being complete in my answer:

thejonesyboy commented 3 years ago

Ok, thanks for clarifying.

On Wed, 20 Jan 2021, 8:45 am Jérôme W., notifications@github.com wrote:

I think I am accurate ;)

You have to understand how home assistant works:

  • Your sensor, even though it has the future data in its attributes (because that's how the dev decided to develop it), only generates a new state (probably) every hour.
  • when a new state is generated (every hour), that value is stored in homeassistant's history of states in the database
  • the only data which is provided by home assistant is the past data even with a time in the future. You can't retrieve the data from the future because they don't exist yet in homeassistant since those future states have not yet been generated by the sensor.

Since we rely on what homeassistant provides, we can't graph future data. That's how it is 🤷 and is very unlikely to change in home assistant.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/kalkih/mini-graph-card/issues/459#issuecomment-763245907, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGYGQZCMYNNHDLZNODQSVDS2YRUBANCNFSM4SDJNFJA .

RomRider commented 3 years ago

If you want to trick the system you could however create a template sensor consuming the attributes of this sensor where the value_template would be equal to YOUR_ENTITY.attributes.price_(now + 4h). You'd have to account for overflow over 24h obviously.

This would generate a state a the current time of your system but with the data of now + 4h. It's ugly, your graph would show the wrong time for the data but you'd manage to display your graph with a fake 4h ahead data. I'll let you figure out the template though if this is something you'd consider.

cibernox commented 3 years ago

@RomRider that virtual sensor YOUR_ENTITY.attributes.price_(now + 4h) is exactly what I had in mind and why I said that the real requested feature here wasn't really to read values from the future but to be able to style graphs starting at one point in the X axis differently.

Well, for completeness I'd also be nice to be able for the graph to use this price-in-4-hours sensor but the text displayed next to it to use the current-price sensor, which I haven't even checked if it's possible. Probably can be hacked by rendering two graphs but making one of them transparent.

RomRider commented 3 years ago

@thejonesyboy @cibernox, I've published a new card to display graphs and it supports to generate data out of attributes in a generic way and display the future also 🔮 I've tested with the PVPC integration and it works amazingly well :)

==> Card: https://github.com/RomRider/apexcharts-card ==> Feature request: https://github.com/RomRider/apexcharts-card/issues/6 where you'll also find links to the PR with some explanation!

mpredfearn commented 3 years ago

@RomRider Thanks for this! I've added your card https://github.com/RomRider/apexcharts-card to my home assistant and it now shows the future electricity prices as provided by the Agile Octopus integration https://github.com/markgdev/home-assistant_OctopusAgile Great work! Thanks, Matt