amsreader-firmware icon indicating copy to clipboard operation
amsreader-firmware copied to clipboard

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

Open MrAdam opened this issue 1 year ago • 1 comments

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 avatar Sep 02 '24 18:09 MrAdam

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

MrAdam avatar Sep 02 '24 18:09 MrAdam

I have looked into this, and as far as I can tell there is no way to add a sensor with an array. I might be wrong about this though, so if anyone can provide me with the sensor configuration necessary to achieve this (as json to be sent over MQTT), I will take a shot at this. If not, this issue will be closed.

gskjold avatar Oct 01 '25 08:10 gskjold