diff --git a/CHANGELOG.md b/CHANGELOG.md index cfe46ab..7cc5a40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [1.3.1](https://github.com/MindFreeze/ha-sankey-chart/compare/v1.3.0...v1.3.1) (2022-11-25) + + +### Bug Fixes + +* fixed rendering order of connections ([e5eb1c1](https://github.com/MindFreeze/ha-sankey-chart/commit/e5eb1c11ec08d104cc1c2a3093f4f8fb3b516eab)) + ## [1.3.0](https://github.com/MindFreeze/ha-sankey-chart/compare/v1.2.0...v1.3.0) (2022-11-16) diff --git a/README.md b/README.md index a41de3f..8cc2aa4 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,6 @@ A Home Assistant lovelace card to display a sankey chart. For example for power This card is intended to display connections between entities with numeric state. It is not a general graph card. -Supports partial Energy dashboard integration. You still need to specify the entities and connections for now. See `energy_date_selection` option. - ![Example card](img/example.png) ## Options @@ -112,7 +110,7 @@ Supports partial Energy dashboard integration. You still need to specify the ent - sensor.other_power ``` -### Daily energy use +### Energy use ![Energy example card](img/example-energy.png) @@ -127,16 +125,16 @@ Supports partial Energy dashboard integration. You still need to specify the ent - entity_id: sensor.solar color: var(--warning-color) children: - - sensor.daily_energy + - sensor.total_energy - entity_id: sensor.grid children: - - sensor.daily_energy + - sensor.total_energy - entity_id: sensor.battery color: var(--success-color) children: - - sensor.daily_energy + - sensor.total_energy - entities: - - entity_id: sensor.daily_energy + - entity_id: sensor.total_energy children: - sensor.floor1 - sensor.floor2 @@ -163,6 +161,16 @@ Supports partial Energy dashboard integration. You still need to specify the ent You can find more examples and help in the HA forum +## Energy Dashboard + +This card supports partial Energy dashboard integration. You still need to specify the entities and connections for now. See `energy_date_selection` option. + +Currently this chart just shows historical data based on a energy-date-selection card. It doesn’t know/care if your entities are in the default energy dashboard. + +### Total [daily] energy + +There isn’t a general Consumed Energy sensor in the HA Energy dashboard AFAIK. HA calculates it based on all the in/out kWh values. I can’t tell you exactly how to calculate it because it depends on what values you can monitor. Some people already have a Total Consumption sensor, others have a Current Consumption and create an integration sensor from that, etc. + ## Development 1. `npm i` diff --git a/package-lock.json b/package-lock.json index f876b04..247cd80 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "ha-sankey-chart", - "version": "1.3.0", + "version": "1.3.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "ha-sankey-chart", - "version": "1.3.0", + "version": "1.3.1", "license": "MIT", "dependencies": { "custom-card-helpers": "^1.7.2", diff --git a/package.json b/package.json index 434eecc..4700aaa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ha-sankey-chart", - "version": "1.3.0", + "version": "1.3.1", "description": "Lovelace sankey diagram card", "keywords": [ "home-assistant", diff --git a/src/utils.ts b/src/utils.ts index 3414662..15a4dbe 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -43,17 +43,20 @@ export function getEntityId(entity: EntityConfigOrStr): string { } export function getChildConnections(parent: Box, children: Box[], connections?: ConnectionState[]): Connection[] { + // @NOTE don't take prevParentState from connection because it is different + let prevParentState = 0; return children.map(child => { const connection = connections?.find(c => c.child.entity_id === child.entity_id); if (!connection) { throw new Error(`Missing connection: ${parent.entity_id} - ${child.entity_id}`); } - const {state, prevParentState, prevChildState} = connection; + const {state, prevChildState} = connection; if (state <= 0) { // only continue if this connection will be rendered return {state} as Connection; } const startY = prevParentState / parent.state * parent.size + parent.top; + prevParentState += state; const startSize = Math.max(state / parent.state * parent.size, 0); const endY = prevChildState / child.state * child.size + child.top; const endSize = Math.max(state / child.state * child.size, 0);