RomRider / apexcharts-card

📈 A Lovelace card to display advanced graphs and charts based on ApexChartsJS for Home Assistant
MIT License
1.18k stars 79 forks source link

Access other series from transform method #461

Closed michalk-k closed 1 year ago

michalk-k commented 1 year ago

Checklist

Is your feature request related to a problem? Please describe. I'm just starting to play with energy monitoring in my house. I'm facing a problem of inability to display a pie chart, which contains energy consumption from several items as well as item representing all the rest, not included. The latter could be calculated from the difference between the measured total value (I have total consumption of my house available) and sum of listed known values.

Here is an example: image

Describe the solution you'd like Currently, as far as I understand the transform method provides variable x which contains the calculated value intended for graph rendering. For example, if using group_by/diff, the x does contain the value of the difference between the first and last value from the bucket.

I would like to be able to access the values of the other series and use them in the transform formula. It would open a way to draw pie-chart with one part which is calculated from the total value reduced by the sum of other values. Example

type: custom:apexcharts-card
all_series_config:
  group_by:
    func: diff
    duration: 1d
    start_with_last: true
update_interval: 1min
series:
  - entity: sensor.power_consumption1
  - entity: sensor.power_consumption2
  - entity: sensor.power_consumption2
  - entity: sensor.power_consumption_total
    transform: "return x - power_consumption1 - power_consumption2 - power_consumption3"

Obviously, the names of variables in the transform formula above are examples only and will depend on a way of referencing available series.

Describe alternatives you've considered There is an option currently. It involves HA Utility Meter helper. It has two downsides however:

  1. it creates additional sensor which seems to be a waste of resources just for sake of showing the graph. Also considering a user may want to create more charts with different sets of known values against "the rest", it would require multiple helpers for specific cases
  2. the helper doesn't provide a value for a floating time window (ie last 24h). The utility meter sticks to fixed moments like the beginning of the day.

Additional context The main problem lays in the fact, that values of consumption sensors grow to infinity. In order to show consumption for a specific time period, it's needed to make a math: calculate the difference between values valid at the end and beginning of the time period. Referencing sensor (like in available examples) obviously doesn't do the job.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 10 days.

michalk-k commented 1 year ago

I'm not aware of adding this as a new feature.

BTW I found https://github.com/MindFreeze/ha-sankey-chart provides a similar option. The option doesn't give access to other axes, but provides value of remaining power (remaining_parent_state and remaining_child_state)

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 10 days.

michalk-k commented 1 year ago

no interest over here?

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 10 days.

github-actions[bot] commented 1 year ago

This issue was closed because it has been stalled for 10 days with no activity.

MayeulC commented 1 year ago

I would have liked a similar feature to plot the temperature difference with outside.

i00 commented 4 months ago

I want this too