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

Export price per hour as array for easier graph creation in Home Assistant #838

Open
MrAdam opened this issue Sep 2, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@MrAdam
Copy link

MrAdam commented Sep 2, 2024

Is your feature request related to a problem? Please describe.
It's really hard to create a good graph of future prices in Home Assistant at the moment, as it is exported as one device per hour, which none of the graph extensions in Home Assistant has a good way of plotting.

Describe the solution you'd like
I'd like to have an additional entity exported with an attribute containing an array of the current and future prices.

Describe alternatives you've considered
I've tried overcoming this by hardcoding each price entity in a graph

type: custom:plotly-graph
title: Electricity Price
hours_to_show: 24h
time_offset: 24h
entities:
  - entity: ''
    name: Now
    yaxis: y3
    showlegend: false
    line:
      width: 2
      dash: dot
      color: blue
    x: $ex [Date.now(), Date.now()]
    'y':
      - 0
      - 1
  - entity: ''
    name: Price
    fill: tozeroy
    line:
      width: 0
      color: yellow
    showlegend: false
    x:
      - $ex new Date(Date.now()).setMinutes(0, 0, 0)
      - $ex new Date(Date.now()).setMinutes(0, 0, 0) + 1000 * 60 * 60 * 1
      - $ex new Date(Date.now()).setMinutes(0, 0, 0) + 1000 * 60 * 60 * 2
      - $ex new Date(Date.now()).setMinutes(0, 0, 0) + 1000 * 60 * 60 * 3
      - $ex new Date(Date.now()).setMinutes(0, 0, 0) + 1000 * 60 * 60 * 4
      - $ex new Date(Date.now()).setMinutes(0, 0, 0) + 1000 * 60 * 60 * 5
      - $ex new Date(Date.now()).setMinutes(0, 0, 0) + 1000 * 60 * 60 * 6
      - $ex new Date(Date.now()).setMinutes(0, 0, 0) + 1000 * 60 * 60 * 7
      - $ex new Date(Date.now()).setMinutes(0, 0, 0) + 1000 * 60 * 60 * 8
      - $ex new Date(Date.now()).setMinutes(0, 0, 0) + 1000 * 60 * 60 * 9
      - $ex new Date(Date.now()).setMinutes(0, 0, 0) + 1000 * 60 * 60 * 10
      - $ex new Date(Date.now()).setMinutes(0, 0, 0) + 1000 * 60 * 60 * 11
      - $ex new Date(Date.now()).setMinutes(0, 0, 0) + 1000 * 60 * 60 * 12
      - $ex new Date(Date.now()).setMinutes(0, 0, 0) + 1000 * 60 * 60 * 13
      - $ex new Date(Date.now()).setMinutes(0, 0, 0) + 1000 * 60 * 60 * 14
      - $ex new Date(Date.now()).setMinutes(0, 0, 0) + 1000 * 60 * 60 * 15
      - $ex new Date(Date.now()).setMinutes(0, 0, 0) + 1000 * 60 * 60 * 16
      - $ex new Date(Date.now()).setMinutes(0, 0, 0) + 1000 * 60 * 60 * 17
      - $ex new Date(Date.now()).setMinutes(0, 0, 0) + 1000 * 60 * 60 * 18
      - $ex new Date(Date.now()).setMinutes(0, 0, 0) + 1000 * 60 * 60 * 19
      - $ex new Date(Date.now()).setMinutes(0, 0, 0) + 1000 * 60 * 60 * 20
      - $ex new Date(Date.now()).setMinutes(0, 0, 0) + 1000 * 60 * 60 * 21
      - $ex new Date(Date.now()).setMinutes(0, 0, 0) + 1000 * 60 * 60 * 22
      - $ex new Date(Date.now()).setMinutes(0, 0, 0) + 1000 * 60 * 60 * 23
      - $ex new Date(Date.now()).setMinutes(0, 0, 0) + 1000 * 60 * 60 * 24
      - $ex new Date(Date.now()).setMinutes(0, 0, 0) + 1000 * 60 * 60 * 25
      - $ex new Date(Date.now()).setMinutes(0, 0, 0) + 1000 * 60 * 60 * 26
      - $ex new Date(Date.now()).setMinutes(0, 0, 0) + 1000 * 60 * 60 * 27
      - $ex new Date(Date.now()).setMinutes(0, 0, 0) + 1000 * 60 * 60 * 28
      - $ex new Date(Date.now()).setMinutes(0, 0, 0) + 1000 * 60 * 60 * 29
      - $ex new Date(Date.now()).setMinutes(0, 0, 0) + 1000 * 60 * 60 * 30
      - $ex new Date(Date.now()).setMinutes(0, 0, 0) + 1000 * 60 * 60 * 31
      - $ex new Date(Date.now()).setMinutes(0, 0, 0) + 1000 * 60 * 60 * 32
      - $ex new Date(Date.now()).setMinutes(0, 0, 0) + 1000 * 60 * 60 * 33
      - $ex new Date(Date.now()).setMinutes(0, 0, 0) + 1000 * 60 * 60 * 34
      - $ex new Date(Date.now()).setMinutes(0, 0, 0) + 1000 * 60 * 60 * 35
      - $ex new Date(Date.now()).setMinutes(0, 0, 0) + 1000 * 60 * 60 * 36
      - $ex new Date(Date.now()).setMinutes(0, 0, 0) + 1000 * 60 * 60 * 37
    'y':
      - $fn ({ hass }) => hass.states["sensor.amsreader_prices0"].state
      - $fn ({ hass }) => hass.states["sensor.amsreader_prices1"].state
      - $fn ({ hass }) => hass.states["sensor.amsreader_prices2"].state
      - $fn ({ hass }) => hass.states["sensor.amsreader_prices3"].state
      - $fn ({ hass }) => hass.states["sensor.amsreader_prices4"].state
      - $fn ({ hass }) => hass.states["sensor.amsreader_prices5"].state
      - $fn ({ hass }) => hass.states["sensor.amsreader_prices6"].state
      - $fn ({ hass }) => hass.states["sensor.amsreader_prices7"].state
      - $fn ({ hass }) => hass.states["sensor.amsreader_prices8"].state
      - $fn ({ hass }) => hass.states["sensor.amsreader_prices9"].state
      - $fn ({ hass }) => hass.states["sensor.amsreader_prices10"].state
      - $fn ({ hass }) => hass.states["sensor.amsreader_prices11"].state
      - $fn ({ hass }) => hass.states["sensor.amsreader_prices12"].state
      - $fn ({ hass }) => hass.states["sensor.amsreader_prices13"].state
      - $fn ({ hass }) => hass.states["sensor.amsreader_prices14"].state
      - $fn ({ hass }) => hass.states["sensor.amsreader_prices15"].state
      - $fn ({ hass }) => hass.states["sensor.amsreader_prices16"].state
      - $fn ({ hass }) => hass.states["sensor.amsreader_prices17"].state
      - $fn ({ hass }) => hass.states["sensor.amsreader_prices18"].state
      - $fn ({ hass }) => hass.states["sensor.amsreader_prices19"].state
      - $fn ({ hass }) => hass.states["sensor.amsreader_prices20"].state
      - $fn ({ hass }) => hass.states["sensor.amsreader_prices21"].state
      - $fn ({ hass }) => hass.states["sensor.amsreader_prices22"].state
      - $fn ({ hass }) => hass.states["sensor.amsreader_prices23"].state
      - $fn ({ hass }) => hass.states["sensor.amsreader_prices24"].state
      - $fn ({ hass }) => hass.states["sensor.amsreader_prices25"].state
      - $fn ({ hass }) => hass.states["sensor.amsreader_prices26"].state
      - $fn ({ hass }) => hass.states["sensor.amsreader_prices27"].state
      - $fn ({ hass }) => hass.states["sensor.amsreader_prices28"].state
      - $fn ({ hass }) => hass.states["sensor.amsreader_prices29"].state
      - $fn ({ hass }) => hass.states["sensor.amsreader_prices30"].state
      - $fn ({ hass }) => hass.states["sensor.amsreader_prices31"].state
      - $fn ({ hass }) => hass.states["sensor.amsreader_prices32"].state
      - $fn ({ hass }) => hass.states["sensor.amsreader_prices33"].state
      - $fn ({ hass }) => hass.states["sensor.amsreader_prices34"].state
      - $fn ({ hass }) => hass.states["sensor.amsreader_prices35"].state
      - $fn ({ hass }) => hass.states["sensor.amsreader_prices36"].state
      - $fn ({ hass }) => hass.states["sensor.amsreader_prices37"].state

Additional context
An example of a plotting component in Home Assistant that would work nice with a potential price array is ApexCharts.
See the following documentation regarding data generators:
https://github.com/RomRider/apexcharts-card?tab=readme-ov-file#data_generator-option

@MrAdam
Copy link
Author

MrAdam commented Sep 2, 2024

Exporting price as an array is also the case for the following Home Assistant component:
https://github.com/custom-components/nordpool

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

3 participants