diff --git a/docs/configuration.md b/docs/configuration.md index 4944585..0cc4bac 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -249,30 +249,31 @@ To display battery power and current as absolute values set `show_absolute: true will return your sensor value. The animated dot will change direction depending on the charging or discharging state. The `invert_power` attribute can be used to reverse direction if needed by your sensor. -| Editor name (en) | Attribute | Default | Description | -|-------------------------|----------------------------------------|---------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| Energy | energy: | `0` | **Required** Total battery energy in Wh (e.g. 3 x 5.32kWh = 15960). If set to `0` the remaining battery runtime will be hidden. Numeric value or sensor i.e. `sensor.sunsynk_battery_energy` | -| Shutdown SOC | shutdown_soc: | `20` | **Required** The battery shutdown percentage used to calculate remaining runtime. Numeric value or sensor i.e. `sensor.sunsynk_battery_capacity_shutdown` | -| Shutdown SOC (Off Grid) | shutdown_soc_offgrid: | | The offgrid battery shutdown percentage used to calculate remaining runtime. Numeric value or sensor i.e. `sensor.offgrid_battery_capacity_shutdown` | -| Soc End Of Charge | soc_end_of_charge: | `100` | Set the charge cut-off capacity. The minimum value is `50`. The maximum value is `100`. Numeric value or sensor i.e. `sensor.soc_end_of_charge` | -| Show Daily | show_daily: | `false` | Toggles the daily total | -| Auto Scale | auto_scale: | `true` | If set to `true` the card will use the entities `unit_of_measurement` attribute to perform the correct scaling (i,e, power values greater than 999W will be displayed as kW e.g. 1.23kW) and display the correct unit. The number of decimal places can be changed using the `decimal_places` card attribute apart from the daily energy values which are set using the `decimal_places_energy` attribute | -| Invert Power | invert_power: | `false` | Set to `true` if your sensor provides a positive number for battery charge and negative number for battery discharge. See also `invert_flow:` below. | -| Show Absolute | show_absolute: | `false` | set to `true` to display power and current as absolute values | -| Colour | colour: | `pink` | Sets the colour of all the battery card objects. Hex codes (`'#66ff00'` etc) or names (`red`, `green`, `blue` etc) | -| Navigation Path | navigate: | | Sets the navigation path when clicking on the battery icon. Can be used to link to other dashboards and views e.g. `/lovelace/1` | -| Invert Flow | invert_flow: | `false` | Inverts the animated flow. Expects a positive number for battery charging and a negative number for battery discharging | -| Charge Colour | charge_colour: | | Sets the colour of all the battery card objects when charging. Hex codes (`'#66ff00'` etc) or names (`red`, `green`, `blue` etc) | -| Dynamic Colour | dynamic_colour: | `true` | The battery icon colour will change based on the % contribution of the power source (grid, solar) supplying the battery. Set to `false` to disable. If `priority_load_243: on` solar will prioritise the essential load. If `false` or omitted solar will prioritise the battery. | -| Linear Gradient | linear_gradient: | `true` | The blocks inside the battery icon that represent SOC will be coloured using a linear gradient that ranges from red to green | -| Animate Linear Gradient | animate: | `true` | Animates the linear gradient inside the battery icon | -| Anim. Speed | animation_speed: | `6` | Set slowest animation speed in seconds, depending on power draw | -| Hide SOC | hide_soc: | `false` | If set to `true` the current program capacity (soc), or for `Goodwe` inverters the shutdown soc and offgrid shutdown soc that is shown to the left of the current battery SOC will be hidden. | -| Show Remaining Energy | show_remaining_energy: | `true` | Set to `true` to display the remaining battery energy in kWh based on the current SOC. Only visible on the `lite` and `full` cards | -| Max Power | max_power: | `4500` | Maximum power draw to calculate animation speed. Numeric value or sensor i.e. `number.battery_maximum_discharging_power` | -| Path Threshold | path_threshold: | `100` | Specify threshold to apply dynamic colour to the battery path element. The colour of the path will change to the source colour if the percentage supply by a single source equals or exceeds this value | -| Battery Entities | [Sub-menu](#battery-battery-entities) | | Shows sub-menu with Battery Entities | -| Optional Entities | [Sub-menu](#battery-optional-entities) | | Shows sub-menu with Battery Entities | +| Editor name (en) | Attribute | Default | Description | +|-----------------------------------|----------------------------------------|---------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| Energy | energy: | `0` | **Required** Total battery energy in Wh (e.g. 3 x 5.32kWh = 15960). If set to `0` the remaining battery runtime will be hidden. Numeric value or sensor i.e. `sensor.sunsynk_battery_energy` | +| Shutdown SOC | shutdown_soc: | `20` | **Required** The battery shutdown percentage used to calculate remaining runtime. Numeric value or sensor i.e. `sensor.sunsynk_battery_capacity_shutdown` | +| Shutdown SOC (Off Grid) | shutdown_soc_offgrid: | | The offgrid battery shutdown percentage used to calculate remaining runtime. Numeric value or sensor i.e. `sensor.offgrid_battery_capacity_shutdown` | +| Soc End Of Charge | soc_end_of_charge: | `100` | Set the charge cut-off capacity. The minimum value is `50`. The maximum value is `100`. Numeric value or sensor i.e. `sensor.soc_end_of_charge` | +| Show Daily | show_daily: | `false` | Toggles the daily total | +| Auto Scale | auto_scale: | `true` | If set to `true` the card will use the entities `unit_of_measurement` attribute to perform the correct scaling (i,e, power values greater than 999W will be displayed as kW e.g. 1.23kW) and display the correct unit. The number of decimal places can be changed using the `decimal_places` card attribute apart from the daily energy values which are set using the `decimal_places_energy` attribute | +| Invert Power | invert_power: | `false` | Set to `true` if your sensor provides a positive number for battery charge and negative number for battery discharge. See also `invert_flow:` below. | +| Show Absolute | show_absolute: | `false` | set to `true` to display power and current as absolute values | +| Colour | colour: | `pink` | Sets the colour of all the battery card objects. Hex codes (`'#66ff00'` etc) or names (`red`, `green`, `blue` etc) | +| Navigation Path | navigate: | | Sets the navigation path when clicking on the battery icon. Can be used to link to other dashboards and views e.g. `/lovelace/1` | +| Invert Flow | invert_flow: | `false` | Inverts the animated flow. Expects a positive number for battery charging and a negative number for battery discharging | +| Charge Colour | charge_colour: | | Sets the colour of all the battery card objects when charging. Hex codes (`'#66ff00'` etc) or names (`red`, `green`, `blue` etc) | +| Dynamic Colour | dynamic_colour: | `true` | The battery icon colour will change based on the % contribution of the power source (grid, solar) supplying the battery. Set to `false` to disable. If `priority_load_243: on` solar will prioritise the essential load. If `false` or omitted solar will prioritise the battery. | +| Linear Gradient | linear_gradient: | `true` | The blocks inside the battery icon that represent SOC will be coloured using a linear gradient that ranges from red to green | +| Animate Linear Gradient | animate: | `true` | Animates the linear gradient inside the battery icon | +| Anim. Speed | animation_speed: | `6` | Set slowest animation speed in seconds, depending on power draw | +| Hide SOC | hide_soc: | `false` | If set to `true` the current program capacity (soc), or for `Goodwe` inverters the shutdown soc and offgrid shutdown soc that is shown to the left of the current battery SOC will be hidden. | +| Show Remaining Energy | show_remaining_energy: | `true` | Set to `true` to display the remaining battery energy in kWh based on the current SOC. | +| Show Remaining Energy to Shutdown | remaining_energy_to_shutdown: | `false` | If set to `true` the displayed remaining battery energy will be the available energy to the shutdown SOC and not to 0%. For battery requires `show_remaining_energy: true`. | +| Max Power | max_power: | `4500` | Maximum power draw to calculate animation speed. Numeric value or sensor i.e. `number.battery_maximum_discharging_power` | +| Path Threshold | path_threshold: | `100` | Specify threshold to apply dynamic colour to the battery path element. The colour of the path will change to the source colour if the percentage supply by a single source equals or exceeds this value | +| Battery Entities | [Sub-menu](#battery-battery-entities) | | Shows sub-menu with Battery Entities | +| Optional Entities | [Sub-menu](#battery-optional-entities) | | Shows sub-menu with Battery Entities | ### Battery: Battery Entities diff --git a/docs/examples/victron.rst b/docs/examples/victron.rst index 8d6d8f5..de2f75c 100644 --- a/docs/examples/victron.rst +++ b/docs/examples/victron.rst @@ -15,7 +15,6 @@ Integration via https://github.com/sfstar/hass-victron :linenos: type: custom:mlk-power-flow-card - panel_mode: false large_font: false title: Victron - Power Monitor title_colour: White diff --git a/src/cards/compact/battery.ts b/src/cards/compact/battery.ts index 69da0ec..120b47b 100644 --- a/src/cards/compact/battery.ts +++ b/src/cards/compact/battery.ts @@ -195,7 +195,6 @@ export class Battery { `; } - static generateCapacity(data: DataDto, config: PowerFlowCardConfig) { const x = Battery.showInnerBatteryBanks(config) ? 202 : (Battery.showOuterBatteryBanks(config) ? 322 : 270); const y = Battery.showInnerBatteryBanks(config) ? 325 : (Battery.showOuterBatteryBanks(config) ? 307 : 338); @@ -212,11 +211,17 @@ export class Battery { `; } + + let shutdown = config.battery.shutdown_soc_offgrid || config.battery.shutdown_soc || 0; + let storage = config.battery.remaining_energy_to_shutdown + ? Utils.toNum((data.batteryEnergy * ((data.stateBatterySoc.toNum(2) - shutdown) / 100) / 1000), 2).toFixed(2) + : Utils.toNum((data.batteryEnergy * (data.stateBatterySoc.toNum(2) / 100) / 1000), 2).toFixed(2); + return svg` - ${Utils.toNum((data.batteryEnergy * (data.stateBatterySoc.toNum(2) / 100) / 1000), 2)} + ${storage} ${UnitOfEnergy.KILO_WATT_HOUR} `; } diff --git a/src/cards/compact/batteryBank.ts b/src/cards/compact/batteryBank.ts index d05ecab..a8827da 100644 --- a/src/cards/compact/batteryBank.ts +++ b/src/cards/compact/batteryBank.ts @@ -11,7 +11,7 @@ export class BatteryBank { return svg``; } let banks = config.battery.battery_banks; - banks = banks > 4?4:banks; + banks = banks > 4 ? 4 : banks; let columns = [281, 312, 343, 374]; let gap = 10, width = 28; if (banks <= 2) { @@ -91,15 +91,9 @@ export class BatteryBank { ) { if (id <= banks) { const textX = column + width / 2 + gap; - const power = config.battery.auto_scale - ? config.battery.show_absolute - ? Utils.convertValueNew(Math.abs(powerEntity.toNum(decimalPlaces)), powerEntity.getUOM(), decimalPlaces, false) - : Utils.convertValueNew(powerEntity.toNum(decimalPlaces), powerEntity.getUOM(), decimalPlaces, false) || '0' - : powerEntity.toStr(config.decimal_places, config.battery?.invert_power, config.battery.show_absolute); + const power = this.getPower(config, powerEntity, decimalPlaces); + const storage = this.getStorage(storageEntity, config, batteryEnergy, socEntity); - const storage = storageEntity?.isValid() - ? storageEntity.toStr(2) - : Utils.toNum((batteryEnergy * (socEntity.toNum(2) / 100) / 1000), 2).toFixed(2); return svg` ${power} @@ -182,17 +176,10 @@ export class BatteryBank { ) { if (id <= banks) { const textX = column + width / 2 - 3; - const power = config.battery.auto_scale - ? config.battery.show_absolute - ? Utils.convertValueNew(Math.abs(powerEntity.toNum(decimalPlaces)), powerEntity.getUOM(), decimalPlaces, false) - : Utils.convertValueNew(powerEntity.toNum(decimalPlaces), powerEntity.getUOM(), decimalPlaces, false) || '0' - : powerEntity.toStr(config.decimal_places, config.battery?.invert_power, config.battery.show_absolute); - + const power = this.getPower(config, powerEntity, decimalPlaces); const x = column - 3 + width / 2; + const storage = this.getStorage(storageEntity, config, batteryEnergy, socEntity); - const storage = storageEntity?.isValid() - ? storageEntity.toStr(2) - : Utils.toNum((batteryEnergy * (socEntity.toNum(2) / 100) / 1000), 2).toFixed(2); return svg` = rule.threshold) { diff --git a/src/localize/languages/en.json b/src/localize/languages/en.json index 1739942..a76298c 100644 --- a/src/localize/languages/en.json +++ b/src/localize/languages/en.json @@ -229,6 +229,7 @@ "energy_cost_decimals": "Energy Cost Decimals", "show_remaining_energy": "Show Remaining Energy", + "remaining_energy_to_shutdown": "Show Remaining Energy to Shutdown", "path_threshold": "Path Threshold", "label_daily_grid_buy": "Daily Grid Buy Label", "label_daily_grid_sell": "Daily Grid Sell Label", diff --git a/src/types.ts b/src/types.ts index 5e5ba58..0a706db 100644 --- a/src/types.ts +++ b/src/types.ts @@ -65,10 +65,10 @@ export interface PowerFlowCardConfig extends LovelaceCardConfig { schema_version: number; dev_mode: boolean; refresh_time?: string; - panel_mode?: boolean; wide_view_mode: boolean, align_grid: boolean; align_load: boolean; + center_sol_inv_bat: boolean; large_font?: boolean; show_solar: boolean; show_battery: boolean; @@ -117,6 +117,7 @@ export interface PowerFlowCardConfig extends LovelaceCardConfig { show_absolute: boolean; auto_scale: boolean; show_remaining_energy: boolean; + remaining_energy_to_shutdown: boolean; dynamic_colour: boolean; linear_gradient: boolean; animate: boolean;