Skip to content

Commit

Permalink
Merge pull request #34 from shadow7412/main
Browse files Browse the repository at this point in the history
feat: Added max_expected_flow_w configuration
  • Loading branch information
flixlix authored Mar 31, 2023
2 parents 682b49a + 95bc69c commit 89dfb99
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
43 changes: 25 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,24 @@ Else, if you prefer the graphical editor, use the menu to add the resource:

> ⚠️ This card offers a **LOT** of configuration options. Don't worry, if you want your card's appearance to match the oficial Energy Flow Card, you will only need to setup the entities. The rest of the options only enable further customization. If this is your goal, please go to [Minimal Configuration](#minimal-configuration)


### Options

#### Card options

| Name | Type | Default | Description |
| ------------------ | --------- | :----------: | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| type | `string` | **required** | `custom:power-flow-card-plus`. |
| entities | `object` | **required** | One or more sensor entities, see [entities object](#entities-object) for additional entity options. |
| title | `string` | | Shows a title at the top of the card. |
| dashboard_link | `string` | | Shows a link to an Energy Dashboard. Should be a url path to location of your choice. If you wanted to link to the built-in dashboard you would enter `/energy` for example. |
| inverted_entities | `string` | | Comma seperated list of entities that should be inverted (negative for consumption and positive for production). See [example usage](#inverted-entities-example). |
| kw_decimals | `number` | 1 | Number of decimals rounded to when kilowatts are displayed. |
| w_decimals | `number` | 1 | Number of decimals rounded to when watts are displayed. |
| min_flow_rate | `number` | .75 | Represents the fastest amount of time in seconds for a flow dot to travel from one end to the other, see [flow formula](#flow-formula). |
| max_flow_rate | `number` | 6 | Represents the slowest amount of time in seconds for a flow dot to travel from one end to the other, see [flow formula](#flow-formula). |
| watt_threshold | `number` | 0 | The number of watts to display before converting to and displaying kilowatts. Setting of 0 will always display in kilowatts. |
| clickable_entities | `boolean` | false | If true, clicking on the entity will open the entity's more info dialog. |
| Name | Type | Default | Description |
|---------------------| --------- |:------------:|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| type | `string` | **required** | `custom:power-flow-card-plus`. |
| entities | `object` | **required** | One or more sensor entities, see [entities object](#entities-object) for additional entity options. |
| title | `string` | | Shows a title at the top of the card. |
| dashboard_link | `string` | | Shows a link to an Energy Dashboard. Should be a url path to location of your choice. If you wanted to link to the built-in dashboard you would enter `/energy` for example. |
| inverted_entities | `string` | | Comma seperated list of entities that should be inverted (negative for consumption and positive for production). See [example usage](#inverted-entities-example). |
| kw_decimals | `number` | 1 | Number of decimals rounded to when kilowatts are displayed. |
| w_decimals | `number` | 1 | Number of decimals rounded to when watts are displayed. |
| min_flow_rate | `number` | .75 | Represents the fastest amount of time in seconds for a flow dot to travel from one end to the other, see [flow formula](#flow-formula). |
| max_flow_rate | `number` | 6 | Represents the slowest amount of time in seconds for a flow dot to travel from one end to the other, see [flow formula](#flow-formula). |
| max_expected_flow_w | `number` | 8000 | Represents the maximum amount of power expected to flow through the system at a given moment, see [flow formula](#flow-formula). |
| watt_threshold | `number` | 0 | The number of watts to display before converting to and displaying kilowatts. Setting of 0 will always display in kilowatts. |
| clickable_entities | `boolean` | false | If true, clicking on the entity will open the entity's more info dialog. |

#### Entities object

Expand Down Expand Up @@ -321,18 +321,25 @@ This should give you something like this:

### Flow Formula

This formula is based on the offical formula used by the Energy Distribution card.
This formula is based on the official formula used by the Energy Distribution card.

```js
max - (value / totalLines) * (max - min);
// max = max_flow_rate
// min = min_flow_rate
// value = line value, solar to grid for example
// totalLines = gridConsumption + solarConsumption + solarToBattery +
// solarToGrid + batteryConsumption + batteryFromGrid + batteryToGrid
// totalLines = Math.max(
// gridConsumption + solarConsumption + solarToBattery + solarToGrid + batteryConsumption + batteryFromGrid + batteryToGrid,
// config.max_expected_flow_w
// )
```

I'm not 100% happy with this. I'd prefer to see the dots travel slower when flow is low, but faster when flow is high. For example if the only flow is Grid to Home, I'd like to see the dot move faster if the flow is 15kW, but slower if it's only 2kW. Right now the speed would be the same. If you have a formula you'd like to propose please submit a PR.
The previous version of this lacked the max_expected_flow_w configuration, so when the power across the entire system
was low it would show animations as quickly as when the entire system running hot. This was because it was previously
only relative to the current behaviour.

The animation will not run any faster once this value has been exceeded, so you may wish to tweak max_expected_flow_w
if you expect your system to have a higher total power than 8kw.

#### Credits

Expand Down
1 change: 1 addition & 0 deletions src/power-flow-card-plus-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export interface PowerFlowCardPlusConfig extends LovelaceCardConfig {
kw_decimals: number;
min_flow_rate: number;
max_flow_rate: number;
max_expected_flow_w: number;
w_decimals: number;
watt_threshold: number;
clickable_entities: boolean;
Expand Down
10 changes: 6 additions & 4 deletions src/power-flow-card-plus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const KW_DECIMALS = 1;
const MAX_FLOW_RATE = 6;
const MIN_FLOW_RATE = 0.75;
const W_DECIMALS = 1;
const MAX_EXPECTED_FLOW_W = 5000;

@customElement("power-flow-card-plus")
export class PowerFlowCardPlus extends LitElement {
Expand Down Expand Up @@ -54,6 +55,7 @@ export class PowerFlowCardPlus extends LitElement {
max_flow_rate: coerceNumber(config.max_flow_rate, MAX_FLOW_RATE),
w_decimals: coerceNumber(config.w_decimals, W_DECIMALS),
watt_threshold: coerceNumber(config.watt_threshold),
max_expected_flow_w: coerceNumber(config.max_expected_flow_w, MAX_EXPECTED_FLOW_W)
};
}

Expand All @@ -79,7 +81,7 @@ export class PowerFlowCardPlus extends LitElement {
private circleRate = (value: number, total: number): number => {
const min = this._config?.min_flow_rate!;
const max = this._config?.max_flow_rate!;
return max - (value / total) * (max - min);
return max - (value / Math.max(this._config?.max_expected_flow_w, total)) * (max - min);
};

private getEntityState = (entity: string | undefined): number => {
Expand Down Expand Up @@ -870,7 +872,7 @@ export class PowerFlowCardPlus extends LitElement {
: "1;0"
}
keyTimes="0;1"
>
<mpath xlink:href="#individual1" />
</animateMotion>
Expand Down Expand Up @@ -1241,7 +1243,7 @@ export class PowerFlowCardPlus extends LitElement {
? svg`<circle
r="2.4"
class="individual1"
vector-effect="non-scaling-stroke"
vector-effect="non-scaling-stroke"
>
<animateMotion
dur="1.66s"
Expand All @@ -1252,7 +1254,7 @@ export class PowerFlowCardPlus extends LitElement {
? "0;1"
: "1;0"
}
keyTimes="0;1"
keyTimes="0;1"
>
<mpath xlink:href="#individual1" />
</animateMotion>
Expand Down

0 comments on commit 89dfb99

Please sign in to comment.