Add advanced diagram showing flow of electrical energy/power #20766
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The functionality proposed by this closed PR is now available in the HACS custom component:
https://github.com/davet2001/energy-sankey
Proposed change
This PR adds something I've been working on for a while - a Sankey diagram showing flow of electricity. e.g.:
There are two main cards:
Both are live and automatically updating. The cards try to display a coherent representation even if the data set is incomplete or physically impossible (e.g. exporting more than the total generated). This means it is ok for asynchronous updates to be made to any of the entities it is listening for.
The width of the flows represents the amount, and the overall size of everything is automatically scaled so that no one part of the diagram becomes too wide.
The diagram dynamically scales to fit the size of the window it is in (mostly, see below).
I put the main guts of the sankey creation logic into it's own npm library. This is my first proper attempt at adding a component to the frontend, so I would hugely value any feedback/suggestions!
I've added the energy card to the energy dashboard strategy, meaning it is automatically displayed if you have a solar energy source configured, but that's really just to make it easier to experiment with and try it out. Maybe it should be added as an available (but not automatically enabled) card until enough people have put it through its paces.
Outstanding issues to solve:
Sometimes there are thin dark lines between the blocks that make up the shapes, I believe this is caused by antialiasing, but I don't see an easy way of reducing/eliminating it, especially where the shapes are across two divs.
I am not sure how to set the minimum width of the card, or what is the standard practice here. If I shrink the window horizontally, eventually the svg elements start to spill off the card. I'm sure that this is not the desired behaviour, but I don't know how to fix it (suggestions welcome!).
If you stretch the card really wide, it sort of looks a bit silly. Perhaps that's not a major issue though.
There are probably more edge cases to experiment with, such as multiple generation sources, grid configured with only input or output, and either of those being negative to represent flow in the opposite direction.
Battery storage is not supported yet. That could be added in the future.
At this stage I'd like some general feedback/suggestions to see if I'm heading in the right direction.
Type of change
Example configuration
Additional information
Checklist
If user exposed functionality or configuration variables are added/changed: