Skip to content

Commit

Permalink
feat: add battery SOH closes #460
Browse files Browse the repository at this point in the history
  • Loading branch information
slipx06 committed Jun 1, 2024
1 parent bc10823 commit 57c5692
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dist/sunsynk-power-flow-card.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ mappings if using other integration methods.
| battery_soc_184: | **Required** | `sensor.sunsynk_battery_soc` | Battery state of charge (%) |
| battery_power_190: | **Required** | `sensor.sunsynk_battery_power` | Battery power (W). Requires a negative number for battery charging and a positive number for battery discharging. Set the `invert_power:` battery attribute to `yes` if your sensor reports this the other way around |
| battery_current_191: | **Required** | `sensor.sunsynk_battery_current` | Battery current (A) |
| battery_temp_182: | Optional | `sensor.sunsynk_battery_temperature` | Battery temperature (℃) |
| battery_temp_182: | Optional | `sensor.sunsynk_battery_temperature` | Battery temperature (°). Note do not define this sensor if you want to display battery SOH. See below. |
| battery_soh: | Optional | | Battery State of Health (SOH) (%). You can chose to display battery temperature of battery SOH. Not both as they are displayed in the same place on the card. If `battery_temp_182:` is defined it will take priority and this sensor wil not be displayed. |
| battery_rated_capacity: | Optional | | Battery rated capacity (Ah). If provided this sensor will be used to calculate battery energy. The`energy` attribute under the battery card configuration will be ignored.
| essential_power: | Optional | `none` | The card will automatically calculate this sensor based on the formula below if the attribute is set to `none` or the sensor is not defined. You can overide this by supplying a sensor that measures essential power e.g. `Load power Essential` in the case of Solar Assistant (W) |
| essential_load1: | Optional | | Sensor that contains the power of your essential load 1 (W). Can also be used to display any sensor data i.e. temp, energy etc if `auto_scale: false` |
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sunsynk-power-flow-card",
"version": "4.40.2",
"version": "4.41.0",
"description": "A customizable Home Assistant card to emulate the Sunsynk System flow that's displayed on the Inverter screen.",
"main": "sunsynk-power-flow-card.js",
"scripts": {
Expand Down
9 changes: 9 additions & 0 deletions src/cards/compact-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,15 @@ export const compactCard = (config: sunsynkPowerFlowCardConfig, inverterImg: str
${data.stateBatteryTemp.toNum(1)}°
</text>
</a>
<a href="#" @click=${(e) => Utils.handlePopup(e, config.entities.battery_soh)}>
<text id="battery_soh" x="${data.compactMode ? '205' : '250'}"
y="${data.compactMode ? '332' : '324.5'}"
class="${config.entities?.battery_soh ? 'st3 left-align' : 'st12'}"
fill="${data.batteryColour}"
display="${!config.show_battery || !data.stateBatterySOH.isValid() || config.entities?.battery_temp_182 ? 'none' : ''}">
${data.stateBatterySOH.toNum(0)}%
</text>
</a>
<a href="#" @click=${(e) => Utils.handlePopup(e, config.entities.radiator_temp_91)}>
<text id="ac_temp" x="173" y="168.2" class="st3 left-align" fill="${data.inverterColour}"
display="${config.entities?.radiator_temp_91 && data.stateRadiatorTemp.isValid() ? '' : 'none'}">
Expand Down
7 changes: 7 additions & 0 deletions src/cards/full-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2243,6 +2243,13 @@ export const fullCard = (config: sunsynkPowerFlowCardConfig, inverterImg: string
${data.stateBatteryTemp.toNum(1)}°
</text>
</a>
<a href="#" @click=${(e) => Utils.handlePopup(e, config.entities.battery_soh)}>
<text id="battery_soh" x="93.7" y="295"
class="${config.entities?.battery_soh ? 'st3 left-align' : 'st12'}"
fill="${data.batteryColour}" display="${!config.show_battery || !data.stateBatterySOH.isValid() || config.entities?.battery_temp_182 ? 'none' : ''}">
${data.stateBatterySOH.toNum(0)}%
</text>
</a>
<a href="#" @click=${(e) => Utils.handlePopup(e, config.entities.radiator_temp_91)}>
<text id="ac_temp" x="${config.solar?.mppts === 4 ? '110' : '134'}"
y="${config.solar?.mppts === 4 ? '237' : '153'}" class="st3 left-align"
Expand Down
1 change: 1 addition & 0 deletions src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ export class SunSynkCardEditor extends LitElement implements LovelaceCardEditor
selector: {entity: {device_class: SensorDeviceClass.ENERGY}}
},
{name: "battery_rated_capacity", selector: {entity: {}}},
{name: "battery_soh", selector: {entity: {}}},
{name: "battery_current_direction", selector: {entity: {}}},
{name: "battery_status", selector: {entity: {}}},
]
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export class SunsynkPowerFlowCard extends LitElement {
const stateBatteryRatedCapacity = this.getEntity('entities.battery_rated_capacity', {state: ''});
const stateShutdownSOC = this.getEntity('battery.shutdown_soc', {state: config.battery.shutdown_soc?.toString() ?? ''});
const stateShutdownSOCOffGrid = this.getEntity('battery.shutdown_soc_offgrid', {state: config.battery.shutdown_soc_offgrid?.toString() ?? ''});
const stateBatterySOH = this.getEntity('entities.battery_soh', {state: ''});

//Load
const stateEssentialPower = this.getEntity('entities.essential_power');
Expand Down Expand Up @@ -1177,7 +1178,8 @@ export class SunsynkPowerFlowCard extends LitElement {
dynamicColourEssentialLoad4,
dynamicColourNonEssentialLoad1,
dynamicColourNonEssentialLoad2,
dynamicColourNonEssentialLoad3
dynamicColourNonEssentialLoad3,
stateBatterySOH
};

if (this.isFullCard) {
Expand Down
4 changes: 3 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ export interface CardConfigEntities {
battery_power_190: string,
battery_current_191: string,
battery_rated_capacity: string;
battery_soh: string;
grid_power_169: string,
grid_voltage: string,
day_grid_import_76: string,
Expand Down Expand Up @@ -457,5 +458,6 @@ export interface DataDto {
dynamicColourEssentialLoad4,
dynamicColourNonEssentialLoad1,
dynamicColourNonEssentialLoad2,
dynamicColourNonEssentialLoad3
dynamicColourNonEssentialLoad3,
stateBatterySOH: CustomEntity,
}

0 comments on commit 57c5692

Please sign in to comment.