From 3bf892ea83d6f788b6e9f34eb7277c15a180be85 Mon Sep 17 00:00:00 2001 From: Codegnosis Date: Mon, 18 Mar 2024 13:05:19 +0000 Subject: [PATCH 1/5] add simple check to see if configured entity is an invertor --- src/givtcp-battery-card.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/givtcp-battery-card.ts b/src/givtcp-battery-card.ts index 596b99f..d6093f7 100644 --- a/src/givtcp-battery-card.ts +++ b/src/givtcp-battery-card.ts @@ -609,6 +609,19 @@ export class GivTCPBatteryCard extends LitElement implements LovelaceCard { return html``; } + // first check it's actually in invertor. Checking for the invertor_power entity should suffice + // as currently GivTCP only creates this entity for invertors + const invertorExists = this._getInvertorPower + if(invertorExists === undefined) { + return html` + +
+

Could not find invertor ${this.config.entity}. Please check your config and ensure you are adding + the invertor's serial sensor.

+
+
`; + } + let batteryRateData = html``; const displayBatteryRates = (this.config.display_battery_rates !== undefined) ? this.config.display_battery_rates : DISPLAY_BATTERY_RATES; @@ -749,6 +762,10 @@ export class GivTCPBatteryCard extends LitElement implements LovelaceCard { return this.hass.states[`number.${this._getSensorPrefix}battery_discharge_rate`]; } + private get _getInvertorPower(): HassEntity { + return this.hass.states[`sensor.${this._getSensorPrefix}invertor_power`]; + } + private get _getBatteryStatus(): string { const power = parseInt(this._getBatteryPowerEntity.state, 10); From 2dc886c573306455e26c89e808ffa44a4d468094 Mon Sep 17 00:00:00 2001 From: Codegnosis Date: Mon, 18 Mar 2024 13:05:39 +0000 Subject: [PATCH 2/5] fix typo in example yaml --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c88f8ad..d865e16 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ Edit your chosen dashboard and use the "Add Card" button to select the "GivTCP B ```yaml type: custom:givtcp-battery-card -entity: sensor.givetcp_abc123_invertor_serial_number +entity: sensor.givtcp_abc123_invertor_serial_number name: Battery soc_threshold_very_high: 80 soc_threshold_high: 60 From 5fbca58adae455f7e78ba94b4e564d39b10b32e7 Mon Sep 17 00:00:00 2001 From: Codegnosis Date: Mon, 18 Mar 2024 13:20:43 +0000 Subject: [PATCH 3/5] get status info from calculated power --- src/givtcp-battery-card.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/givtcp-battery-card.ts b/src/givtcp-battery-card.ts index d6093f7..19096cc 100644 --- a/src/givtcp-battery-card.ts +++ b/src/givtcp-battery-card.ts @@ -767,7 +767,8 @@ export class GivTCPBatteryCard extends LitElement implements LovelaceCard { } private get _getBatteryStatus(): string { - const power = parseInt(this._getBatteryPowerEntity.state, 10); + + const power = this.calculatedStates.batteryPower.value; let status = ''; if (power > 0) { From f5a42f41e978e81b9bb2bbbf03afbfda6ac3eb17 Mon Sep 17 00:00:00 2001 From: Codegnosis Date: Mon, 18 Mar 2024 13:33:09 +0000 Subject: [PATCH 4/5] add debug output & debug config toggle --- src/config-utils.ts | 3 ++- src/constants.ts | 2 ++ src/givtcp-battery-card.ts | 4 ++++ src/schemas.ts | 8 ++++++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/config-utils.ts b/src/config-utils.ts index b8ec25a..2a27d6c 100644 --- a/src/config-utils.ts +++ b/src/config-utils.ts @@ -19,7 +19,7 @@ import { DISPLAY_BATTERY_RATES, USE_CUSTOM_DOD, CUSTOM_DOD, - CALCULATE_RESERVE_FROM_DOD, DISPLAY_CUSTOM_DOD_STATS, + CALCULATE_RESERVE_FROM_DOD, DISPLAY_CUSTOM_DOD_STATS, ENABLE_DEBUG_OUTPUT, } from "./constants"; export class ConfigUtils { @@ -47,6 +47,7 @@ export class ConfigUtils { custom_dod: CUSTOM_DOD, calculate_reserve_from_dod: CALCULATE_RESERVE_FROM_DOD, display_custom_dod_stats: DISPLAY_CUSTOM_DOD_STATS, + enable_debug_output: ENABLE_DEBUG_OUTPUT, }; } diff --git a/src/constants.ts b/src/constants.ts index d7acd1a..84bb677 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -39,3 +39,5 @@ export const DISPLAY_UNITS = { WH: "Wh", KWH: "kWh", } + +export const ENABLE_DEBUG_OUTPUT = false; diff --git a/src/givtcp-battery-card.ts b/src/givtcp-battery-card.ts index 19096cc..868bc61 100644 --- a/src/givtcp-battery-card.ts +++ b/src/givtcp-battery-card.ts @@ -341,6 +341,10 @@ export class GivTCPBatteryCard extends LitElement implements LovelaceCard { displayUnit: "%", } + if(this.config.enable_debug_output === true) { + console.log(states); + } + this.calculatedStates = states; } diff --git a/src/schemas.ts b/src/schemas.ts index f863a1f..956032f 100644 --- a/src/schemas.ts +++ b/src/schemas.ts @@ -22,6 +22,14 @@ export const GENERAL_SCHEMA = (invertorList: string[], defaults: LovelaceCardCon } }, }, + { + name: 'enable_debug_output', + label: 'Enable debug output to developer console', + default: defaults.enable_debug_output, + selector: { + boolean: {} + } + }, ]; } From 70bc23362352a963349682e8c113a0db323b0502 Mon Sep 17 00:00:00 2001 From: Codegnosis Date: Mon, 18 Mar 2024 13:33:28 +0000 Subject: [PATCH 5/5] bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 79aa242..ac9dfee 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "givtcp-battery-card", - "version": "0.2.2", + "version": "0.2.3", "description": "Lovelace card to display GivTCP battery info", "private": true, "type": "module",