diff --git a/README.cs.md b/README.cs.md
new file mode 100644
index 0000000..1c723d5
--- /dev/null
+++ b/README.cs.md
@@ -0,0 +1,118 @@
+# UltimatePower Card
+
+[English](README.md) · **Česky**
+
+Karta pro Home Assistant, která ukazuje, kudy právě teče energie: výroba z fotovoltaiky, spotřeba domu, baterie a síť. Toky jsou animované a pod schématem je bilance energie, ve které se dá listovat do minulosti. Rozložení vychází z monitoru energie známého z Loxone.
+
+
+
+
+
+
+Na obrázcích jsou ukázková data.
+
+> **Stav:** raný vývoj (v0.x). Volby se před první stabilní verzí mohou změnit.
+
+## Co karta umí
+
+- **Čtyři hlavní uzly kolem středu:** výroba, spotřeba, baterie a síť. Karta se vejde do jednoho sloupce nástěnky.
+- **Libovolný počet stringů, baterií a spotřebičů.** Stringy jsou v řadě nad výrobou, baterie (s kroužkem stavu nabití) a spotřebiče visí pod svým uzlem.
+- **Barvy s jedním významem:** zelená je vlastní energie (výroba, baterie, dodávka do sítě), oranžová je spotřeba a odběr ze sítě. Uzel v klidu zešedne.
+- **Animace toku:** tečky běží od zdroje ke spotřebiči a s výkonem výrazně zrychlují. Uzel, který energii dodává, pulzuje ven; uzel, který ji odebírá, pulzuje dovnitř.
+- **Bez senzoru spotřeby domu:** spotřeba se počítá z fotovoltaiky, sítě a baterie. Co nepokryjí zadané spotřebiče, ukáže se jako „Ostatní".
+- **Bilance energie:** výroba, spotřeba, odběr a dodávka do sítě, soběstačnost a vlastní spotřeba za den, týden, měsíc nebo rok. Listuje se šipkami nebo tažením po grafu. Sekci lze vypnout.
+- **Baterie oběma způsoby:** jeden senzor výkonu se znaménkem, nebo zvlášť senzor nabíjení a vybíjení.
+- Klik na uzel otevře jeho detail v Home Assistantu. České a anglické popisky, světlý i tmavý motiv.
+
+Zatím chybí: vizuální editor nastavení, vlastní barvy a ikony.
+
+## Instalace
+
+### HACS
+
+1. HACS → **⋮** → **Vlastní repozitáře**.
+2. Přidej `Developer089/UltimatePower-Card`, typ **Dashboard** (ve starším HACS *Lovelace*).
+3. Najdi **UltimatePower Card**, stáhni ji a obnov stránku v prohlížeči.
+
+### Ručně
+
+1. Stáhni `ultimate-power-card.js` z [posledního vydání](https://github.com/Developer089/UltimatePower-Card/releases).
+2. Zkopíruj ho do `/config/www/ultimate-power-card/`.
+3. Přidej zdroj nástěnky: `/local/ultimate-power-card/ultimate-power-card.js`, typ **JavaScript modul**.
+
+## Nastavení
+
+Karta se nastavuje v YAML. Povinná je jen `grid_entity`.
+
+```yaml
+type: custom:ultimate-power-card
+name: Energie
+grid_entity: sensor.sit_vykon
+
+pv_strings:
+ - { power_entity: sensor.fve_vychod, name: Východ }
+ - { power_entity: sensor.fve_zapad, name: Západ }
+
+batteries:
+ # jeden senzor se znaménkem: kladná hodnota = vybíjení
+ - power_entity: sensor.baterie_1_vykon
+ soc_entity: sensor.baterie_1_soc
+ name: Baterie 1
+ # nebo dva senzory, které jsou oba vždy kladné
+ - charge_entity: sensor.baterie_2_nabijeni
+ discharge_entity: sensor.baterie_2_vybijeni
+ soc_entity: sensor.baterie_2_soc
+ name: Baterie 2
+
+appliances:
+ - { power_entity: sensor.wallbox_vykon, name: Wallbox }
+ - { power_entity: sensor.tepelne_cerpadlo_vykon, name: Tepelné čerpadlo }
+ - { power_entity: sensor.bojler_vykon, name: Bojler }
+```
+
+### Znaménka
+
+- **Síť:** kladná hodnota = odběr, záporná = dodávka. Pokud to elektroměr hlásí obráceně, nastav `grid_invert: true`. Pokud máš odběr a dodávku ve dvou senzorech, zadej druhý do `grid_export_entity`.
+- **Baterie:** kladná hodnota = vybíjení, záporná = nabíjení. U baterie s opačným znaménkem nastav `invert: true`.
+- **Spotřeba domu** se nečte ze senzoru. Je to `FVE + síť + baterie`, takže vychází správně jen tehdy, když jsou zadané všechny tři.
+
+Senzory výkonu mohou být ve W nebo kW.
+
+### Volby
+
+| Volba | Výchozí | Význam |
+|---|---|---|
+| `grid_entity` | povinná | Výkon sítě. Kladná hodnota = odběr, záporná = dodávka. |
+| `grid_export_entity` | – | Jen když jsou odběr a dodávka dva samostatné, vždy kladné senzory. |
+| `grid_invert` | `false` | Když senzor sítě hlásí dodávku kladně. |
+| `pv_strings[]` | – | `power_entity`, volitelně `name`. |
+| `pv_total_entity` | součet stringů | Celkový výkon FVE, pokud na něj máš samostatný senzor. |
+| `batteries[]` | – | `soc_entity`, volitelně `name` a výkon buď jedním senzorem se znaménkem `power_entity` (kladná hodnota = vybíjení, `invert` ho otočí), nebo dvěma vždy kladnými senzory `charge_entity` + `discharge_entity`. |
+| `battery_total_entity`, `battery_invert` | součet baterií | Celkový výkon baterií a přepínač jeho znaménka. |
+| `battery_charge_entity`, `battery_discharge_entity` | – | Celkový výkon baterií dvěma vždy kladnými senzory. |
+| `appliances[]` | – | `power_entity`, `name`, volitelně `on_threshold_w`. |
+| `show_other` | `true` | Zobrazit dopočtený zbytek spotřeby domu. |
+| `update_interval` | `1` | Jak často karta překresluje živé hodnoty, v sekundách (1–20). Senzory se nečtou častěji, než samy hlásí. |
+| `animation` | `auto` | `auto` se řídí systémovým omezením pohybu, `always` ho ignoruje, `off` animace vypne. |
+| `animation_speed` | `1` | Násobitel rychlosti toku. |
+| `max_power` | `10000` | Výkon (W), při kterém tok dosáhne plné rychlosti. |
+| `show_w_not_kw` | `false` | Vždy zobrazovat watty. |
+| `show_statistics` | `true` | Zobrazit sekci s bilancí energie. |
+| `statistics` | panel Energie | Vlastní senzory energie: `pv`, `grid_import`, `grid_export`, `battery_charge`, `battery_discharge` (u každého jedno id nebo seznam). |
+
+### Bilance energie
+
+Bilance čte dlouhodobé statistiky Home Assistantu, tedy stejná data jako panel Energie. Ve výchozím stavu si karta vezme senzory FVE, sítě a baterií nastavené v panelu Energie, proto ho nastav jako první. Jiné senzory zadáš pod `statistics`; musí to být senzory energie (kWh) se `state_class: total_increasing`.
+
+## Vývoj
+
+```bash
+npm install
+npm run watch # při uložení sestaví znovu do dist/
+```
+
+Soubor `dist/ultimate-power-card.js` zkopíruj do `/config/www/` vývojového Home Assistantu.
+
+## Licence
+
+Apache License 2.0 — viz [LICENSE](LICENSE).
diff --git a/README.md b/README.md
index 82bc49a..d56721d 100644
--- a/README.md
+++ b/README.md
@@ -1,51 +1,52 @@
# UltimatePower Card
-A Home Assistant Lovelace custom card that visualises real-time power flow between **multiple PV strings**, **multiple batteries**, the grid, and the home — with a Tesla-style bubble layout and animated flows.
+**English** · [Česky](README.cs.md)
-> **Status:** 🚧 early development (v0.x). API may change before the first stable release.
+A Home Assistant dashboard card that shows where your energy is flowing right now: solar production, house consumption, batteries and the grid, with animated flows and an energy balance you can page through. The layout follows the energy monitor known from Loxone.
-## Why another power card?
+
+
+
+
-Existing cards (`tesla-style-solar-power-card`, `power-flow-card-plus`, `power-flux-card`, …) all assume **one** battery and a small fixed number of consumers. UltimatePower Card targets larger residential / small-commercial setups where you have:
+The screenshots use demo data.
-- 🟧 **N PV strings / inverters** — see each one separately
-- 🟩 **N batteries side by side** — every module's SoC + power visible at a glance
-- 🟦 **One main house bubble** + **N appliance branches** (boiler, EV, heat-pump, kitchen circuits, server rack, …)
-- ⬜ Grid (import / export)
+> **Status:** early development (v0.x). Options may change before the first stable release.
-## Features (v0.2)
+## Features
-- Four main nodes in a cross around a central hub: production, consumption, battery and grid. The card fits one dashboard column.
-- N PV strings in a row above production; N batteries (with a state-of-charge ring) and N appliances as chains below their node.
-- Green marks own energy (production, battery, export), orange marks consumption and grid import. Idle nodes turn grey.
-- Animated flow: dots run from the source to the consumer and speed up steeply with power. A node that supplies energy pulses outwards, a node that draws energy pulses inwards.
-- House load is computed from PV, grid and battery; the remainder not covered by appliances is shown as "Other".
-- Optional statistics: production, consumption, grid import/export, self-sufficiency and self-consumption per day, week, month or year, with paging into the past (arrows or swipe on the chart).
-- Click-through to the HA `more-info` dialog. Czech and English labels, light and dark theme.
+- **Four main nodes around a central hub:** production, consumption, battery and grid. The card fits one dashboard column.
+- **Any number of PV strings, batteries and appliances.** Strings sit in a row above production; batteries (with a state-of-charge ring) and appliances hang below their node.
+- **Colours with one meaning:** green is your own energy (production, battery, export), orange is consumption and grid import. Idle nodes turn grey.
+- **Animated flow:** dots run from the source to the consumer and speed up steeply with power. A node that supplies energy pulses outwards, a node that draws energy pulses inwards.
+- **No house sensor needed:** the house load is computed from PV, grid and battery. Whatever your listed appliances do not cover is shown as "Other".
+- **Energy balance:** production, consumption, grid import and export, self-sufficiency and self-consumption per day, week, month or year. Page into the past with the arrows or by swiping the chart. The section can be switched off.
+- **Batteries either way:** one signed power sensor, or separate charge and discharge sensors.
+- Click a node to open its Home Assistant detail. English and Czech labels, light and dark theme.
-Not yet: visual config editor, custom colours and icons.
+Not yet available: visual config editor, custom colours and icons.
## Installation
-### Via HACS (recommended once published)
+### HACS
-1. HACS → Frontend → **⋮** → Custom repositories → add `Developer089/UltimatePower-Card` (type: Lovelace)
-2. Install **UltimatePower Card**
-3. Add the resource (HACS does this automatically) and refresh
+1. HACS → **⋮** → **Custom repositories**.
+2. Add `Developer089/UltimatePower-Card`, type **Dashboard** (called *Lovelace* in older HACS).
+3. Find **UltimatePower Card**, download it and reload the browser.
### Manual
-1. Download `ultimate-power-card.js` from the [latest release](https://github.com/Developer089/UltimatePower-Card/releases)
-2. Copy to `/config/www/community/ultimate-power-card/`
-3. Add a Lovelace resource: `/local/community/ultimate-power-card/ultimate-power-card.js` (type: `module`)
+1. Download `ultimate-power-card.js` from the [latest release](https://github.com/Developer089/UltimatePower-Card/releases).
+2. Copy it to `/config/www/ultimate-power-card/`.
+3. Add a dashboard resource: `/local/ultimate-power-card/ultimate-power-card.js`, type **JavaScript module**.
## Configuration
-Minimal example:
+The card is configured in YAML. Only `grid_entity` is required.
```yaml
type: custom:ultimate-power-card
-name: My Power
+name: Energy
grid_entity: sensor.grid_power
pv_strings:
@@ -53,18 +54,29 @@ pv_strings:
- { power_entity: sensor.pv_west, name: West }
batteries:
- - { power_entity: sensor.bat1_power, soc_entity: sensor.bat1_soc, name: BMS-1 }
- - { power_entity: sensor.bat2_power, soc_entity: sensor.bat2_soc, name: BMS-2 }
- - { power_entity: sensor.bat3_power, soc_entity: sensor.bat3_soc, name: BMS-3 }
+ # one signed sensor: positive = discharging
+ - power_entity: sensor.battery_1_power
+ soc_entity: sensor.battery_1_soc
+ name: Battery 1
+ # or two sensors that are both always positive
+ - charge_entity: sensor.battery_2_charge_power
+ discharge_entity: sensor.battery_2_discharge_power
+ soc_entity: sensor.battery_2_soc
+ name: Battery 2
appliances:
- - { power_entity: sensor.boiler_power, name: Boiler, icon: mdi:water-boiler }
- - { power_entity: sensor.ev_charger, name: EV, icon: mdi:car-electric }
- - { power_entity: sensor.heatpump_power, name: HP, icon: mdi:heat-pump }
- - { power_entity: sensor.kitchen_circuit, name: Kuchyň, icon: mdi:silverware-fork-knife }
+ - { power_entity: sensor.wallbox_power, name: Wallbox }
+ - { power_entity: sensor.heat_pump_power, name: Heat pump }
+ - { power_entity: sensor.boiler_power, name: Boiler }
```
-There is no house sensor to configure. The card derives the house load from the energy balance: `PV + grid + battery`, where grid is positive on import and battery is positive on discharge. On the consumption side you only list the individual appliances.
+### Sign conventions
+
+- **Grid:** positive = import, negative = export. Use `grid_invert: true` if your meter reports it the other way round, or `grid_export_entity` if import and export are two separate sensors.
+- **Battery:** positive = discharging, negative = charging. Use `invert: true` on a battery whose sensor is the other way round.
+- **House load** is not read from a sensor. It is `PV + grid + battery`, so it is only right when all three are configured.
+
+Power sensors may be in W or kW.
### Options
@@ -75,18 +87,22 @@ There is no house sensor to configure. The card derives the house load from the
| `grid_invert` | `false` | Set when the grid sensor reports export as positive. |
| `pv_strings[]` | – | `power_entity`, optional `name`. |
| `pv_total_entity` | sum of strings | Total PV power, if you have a dedicated sensor. |
-| `batteries[]` | – | `power_entity` (positive = discharging), `soc_entity`, optional `name`, `invert`. |
+| `batteries[]` | – | `soc_entity`, optional `name`, and the power either as one signed sensor `power_entity` (positive = discharging, `invert` flips it) or as two always-positive sensors `charge_entity` + `discharge_entity`. |
| `battery_total_entity`, `battery_invert` | sum of batteries | Total battery power and its sign switch. |
+| `battery_charge_entity`, `battery_discharge_entity` | – | Total battery power as two always-positive sensors. |
| `appliances[]` | – | `power_entity`, `name`, optional `on_threshold_w`. |
| `show_other` | `true` | Show the computed remainder of the house load. |
+| `update_interval` | `1` | How often the card redraws live values, in seconds (1–20). Sensors are not read more often than they report. |
| `animation` | `auto` | `auto` follows the system "reduce motion" setting, `always` ignores it, `off` never animates. |
| `animation_speed` | `1` | Multiplier for the flow speed. |
| `max_power` | `10000` | Power (W) at which the flow reaches full speed. |
| `show_w_not_kw` | `false` | Always show watts. |
-| `show_statistics` | `true` | Show the balance section. |
+| `show_statistics` | `true` | Show the energy balance section. |
| `statistics` | Energy dashboard | Override the energy sensors: `pv`, `grid_import`, `grid_export`, `battery_charge`, `battery_discharge` (one id or a list each). |
-Statistics read Home Assistant long-term statistics, so the energy sensors must be in kWh with `state_class: total_increasing`. Without the `statistics` option the card uses the sensors configured in the Energy dashboard.
+### Energy balance
+
+The balance reads Home Assistant long-term statistics, the same data the Energy dashboard uses. By default the card takes the solar, grid and battery sensors configured in the Energy dashboard, so set that up first. To use other sensors, list them under `statistics`; they must be energy sensors (kWh) with `state_class: total_increasing`.
## Development
@@ -95,15 +111,8 @@ npm install
npm run watch # rebuilds on save into dist/
```
-Then symlink (or copy) `dist/ultimate-power-card.js` into `/config/www/` of your dev Home Assistant.
-
-## Roadmap
-
-- v0.1 — visual MVP (this milestone)
-- v0.2 — visual config editor
-- v0.3 — `flow_diagram_mode` (line thickness ∝ power), forecast overlay
-- v0.4 — battery runtime / autonomy estimate, dynamic-pricing tint
+Copy `dist/ultimate-power-card.js` into `/config/www/` of a development Home Assistant.
## License
-Apache License 2.0 — see [LICENSE](LICENSE). Visual inspiration from the Tesla Powerwall app and from the `tesla-style-solar-power-card` project (also Apache-2.0).
+Apache License 2.0 — see [LICENSE](LICENSE).
diff --git a/docs/images/preview-dark-cs.png b/docs/images/preview-dark-cs.png
new file mode 100644
index 0000000..557eb18
Binary files /dev/null and b/docs/images/preview-dark-cs.png differ
diff --git a/docs/images/preview-dark-en.png b/docs/images/preview-dark-en.png
new file mode 100644
index 0000000..9ec0ba0
Binary files /dev/null and b/docs/images/preview-dark-en.png differ
diff --git a/docs/images/preview-light-cs.png b/docs/images/preview-light-cs.png
new file mode 100644
index 0000000..4ffa9bf
Binary files /dev/null and b/docs/images/preview-light-cs.png differ
diff --git a/docs/images/preview-light-en.png b/docs/images/preview-light-en.png
new file mode 100644
index 0000000..3420be0
Binary files /dev/null and b/docs/images/preview-light-en.png differ
diff --git a/info.md b/info.md
index 9857161..3937ccd 100644
--- a/info.md
+++ b/info.md
@@ -1,9 +1,13 @@
# UltimatePower Card
-Tesla-style power flow card with **multi-PV**, **multi-battery** and **multi-appliance** support — designed for residential setups bigger than a single inverter + one battery.
+Energy flow card for Home Assistant: solar production, house consumption, batteries and the grid around a central hub, with animated flows and an energy balance per day, week, month or year.
-- 🟧 N PV strings (one bubble each)
-- 🟩 N batteries side by side, each with SoC ring
-- 🟦 House bubble with a radial fan of appliances
-- ⬜ Grid bubble
-- Animated flow lines, auto-derived from sensor values
+Karta toku energie pro Home Assistant: výroba z fotovoltaiky, spotřeba domu, baterie a síť kolem společného středu, s animací toků a bilancí energie za den, týden, měsíc nebo rok.
+
+
+
+- Any number of PV strings, batteries and appliances · libovolný počet stringů, baterií a spotřebičů
+- House load computed from PV, grid and battery · spotřeba domu počítaná z FVE, sítě a baterie
+- Energy balance with paging into the past · bilance energie s listováním do minulosti
+
+[Documentation (English)](https://github.com/Developer089/UltimatePower-Card#readme) · [Dokumentace (česky)](https://github.com/Developer089/UltimatePower-Card/blob/main/README.cs.md)
diff --git a/package-lock.json b/package-lock.json
index 026a174..8919d81 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "ultimate-power-card",
- "version": "0.2.0",
+ "version": "0.2.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "ultimate-power-card",
- "version": "0.2.0",
+ "version": "0.2.1",
"license": "Apache-2.0",
"dependencies": {
"custom-card-helpers": "^1.9.0",
diff --git a/package.json b/package.json
index 146ecd4..ddafb03 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "ultimate-power-card",
- "version": "0.2.0",
+ "version": "0.2.1",
"description": "Home Assistant custom Lovelace card — Tesla-style power flow with multi-battery and multi-appliance support",
"main": "dist/ultimate-power-card.js",
"type": "module",
diff --git a/src/flow-calculator.ts b/src/flow-calculator.ts
index 3b48a14..3d5e1bd 100644
--- a/src/flow-calculator.ts
+++ b/src/flow-calculator.ts
@@ -11,9 +11,15 @@ export const readPower = (hass: HassLike, entity?: string): number => {
return unit === 'kw' ? v * 1000 : v;
};
+/** Discharge minus charge from two sensors that each report a positive value. */
+const readSplit = (hass: HassLike, charge?: string, discharge?: string): number =>
+ Math.abs(readPower(hass, discharge)) - Math.abs(readPower(hass, charge));
+
/** Battery power in watts, positive = discharging. */
export const readBattery = (hass: HassLike, b: BatteryConfig): number =>
- readPower(hass, b.power_entity) * (b.invert ? -1 : 1);
+ b.charge_entity || b.discharge_entity
+ ? readSplit(hass, b.charge_entity, b.discharge_entity)
+ : readPower(hass, b.power_entity) * (b.invert ? -1 : 1);
export const resolveState = (
hass: HassLike,
@@ -26,7 +32,9 @@ export const resolveState = (
: (config.pv_strings ?? []).reduce((sum, s) => sum + readPower(hass, s.power_entity), 0),
);
- const battery_total_w = config.battery_total_entity
+ const battery_total_w = config.battery_charge_entity || config.battery_discharge_entity
+ ? readSplit(hass, config.battery_charge_entity, config.battery_discharge_entity)
+ : config.battery_total_entity
? readPower(hass, config.battery_total_entity) * (config.battery_invert ? -1 : 1)
: (config.batteries ?? []).reduce((sum, b) => sum + readBattery(hass, b), 0);
diff --git a/src/styles.ts b/src/styles.ts
index f98deb3..2defacd 100644
--- a/src/styles.ts
+++ b/src/styles.ts
@@ -62,8 +62,11 @@ export const cardStyles = css`
stroke-linecap: round;
animation: up-flow linear infinite;
}
+ /* Base speeds: the stream covers its 16 px period in 1 s, the lead dot runs
+ 100 px/s. The card scales both through the animation playback rate. */
.stream {
--p: 16;
+ animation-duration: 1s;
stroke-width: 3;
stroke-dasharray: 0.1 15.9;
opacity: 0.8;
diff --git a/src/types.ts b/src/types.ts
index c964666..cabc463 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -5,11 +5,18 @@ export interface PVStringConfig {
name?: string;
}
+/**
+ * Battery power comes either from one signed sensor (power_entity, positive =
+ * discharging) or from two always-positive sensors (charge_entity and
+ * discharge_entity). The pair wins when both forms are given.
+ */
export interface BatteryConfig {
- power_entity: string;
+ power_entity?: string;
+ charge_entity?: string;
+ discharge_entity?: string;
soc_entity: string;
name?: string;
- /** Set when the sensor reports charging as a positive value. */
+ /** Set when power_entity reports charging as a positive value. */
invert?: boolean;
}
@@ -41,6 +48,9 @@ export interface UltimatePowerCardConfig extends LovelaceCardConfig {
grid_invert?: boolean;
pv_total_entity?: string;
battery_total_entity?: string;
+ /** Total battery power as two always-positive sensors instead of battery_total_entity. */
+ battery_charge_entity?: string;
+ battery_discharge_entity?: string;
/** Set when battery_total_entity reports charging as a positive value. */
battery_invert?: boolean;
@@ -60,6 +70,8 @@ export interface UltimatePowerCardConfig extends LovelaceCardConfig {
animation_speed?: number;
/** Power (W) at which the flow animation reaches full speed. Default 10000. */
max_power?: number;
+ /** How often the card redraws live values, in seconds (1–20). Default 1. */
+ update_interval?: number;
/** Show the computed remainder of the house load as an extra appliance. Default true. */
show_other?: boolean;
diff --git a/src/ultimate-power-card.ts b/src/ultimate-power-card.ts
index f368f97..32ceb9d 100644
--- a/src/ultimate-power-card.ts
+++ b/src/ultimate-power-card.ts
@@ -21,7 +21,7 @@ import {
} from './statistics';
import type { UltimatePowerCardConfig } from './types';
-const VERSION = '0.2.0';
+const VERSION = '0.2.1';
type Pt = [number, number];
type Tone = 'pos' | 'neg';
@@ -82,6 +82,8 @@ export class UltimatePowerCard extends LitElement {
private _request = 0;
private _timer?: number;
private _swipeX: number | null = null;
+ private _lastRender = 0;
+ private _pending?: number;
public static getStubConfig(): Partial {
return { grid_entity: 'sensor.grid_power' };
@@ -112,6 +114,8 @@ export class UltimatePowerCard extends LitElement {
public disconnectedCallback(): void {
super.disconnectedCallback();
window.clearInterval(this._timer);
+ window.clearTimeout(this._pending);
+ this._pending = undefined;
}
/** Home Assistant replaces `hass` on every state change; only our entities matter. */
@@ -120,10 +124,37 @@ export class UltimatePowerCard extends LitElement {
const old = changed.get('hass') as HomeAssistant | undefined;
if (!old || !this.hass || !this._config) return true;
if ((old.themes as any)?.darkMode !== (this.hass.themes as any)?.darkMode) return true;
- return this._entities().some((e) => old.states[e] !== this.hass!.states[e]);
+ if (!this._entities().some((e) => old.states[e] !== this.hass!.states[e])) return false;
+ // Redraw at most once per update_interval; a change that arrives sooner is
+ // picked up by the timer, which renders whatever hass holds by then.
+ const wait = this._lastRender + this._interval() - Date.now();
+ if (wait <= 0) return true;
+ if (this._pending === undefined) {
+ this._pending = window.setTimeout(() => {
+ this._pending = undefined;
+ this.requestUpdate();
+ }, wait);
+ }
+ return false;
+ }
+
+ /** Redraw interval in ms, from update_interval (1–20 s, default 1). */
+ private _interval(): number {
+ const s = Number(this._config?.update_interval ?? 1);
+ return Math.max(1, Math.min(20, isNaN(s) ? 1 : s)) * 1000;
}
protected updated(): void {
+ this._lastRender = Date.now();
+ // The flow speed is set through the playback rate: unlike a changed
+ // animation-duration it keeps the dots where they are, so they do not jump
+ // every time the power changes.
+ this.renderRoot.querySelectorAll('[data-rate]').forEach((el) => {
+ const rate = Number(el.dataset.rate);
+ for (const a of el.getAnimations?.() ?? []) {
+ if (rate > 0 && Math.abs(a.playbackRate - rate) > 0.001) a.updatePlaybackRate(rate);
+ }
+ });
if (this._statsState === 'idle' && this.hass && this._config?.show_statistics !== false) {
this._loadStats();
}
@@ -155,8 +186,10 @@ export class UltimatePowerCard extends LitElement {
c.grid_export_entity,
c.pv_total_entity,
c.battery_total_entity,
+ c.battery_charge_entity,
+ c.battery_discharge_entity,
...(c.pv_strings ?? []).map((s) => s.power_entity),
- ...(c.batteries ?? []).flatMap((b) => [b.power_entity, b.soc_entity]),
+ ...(c.batteries ?? []).flatMap((b) => [b.power_entity, b.charge_entity, b.discharge_entity, b.soc_entity]),
...(c.appliances ?? []).map((a) => a.power_entity),
].filter((e): e is string => !!e);
}
@@ -201,10 +234,10 @@ export class UltimatePowerCard extends LitElement {
return svg`
+ data-rate=${(speed / 16).toFixed(3)}>
${main
- ? svg``
+ ? svg``
: nothing}
`;
}
@@ -248,7 +281,8 @@ export class UltimatePowerCard extends LitElement {
const strings = cfg.pv_strings ?? [];
const bats = cfg.batteries ?? [];
const hasPv = strings.length > 0 || !!cfg.pv_total_entity;
- const hasBat = bats.length > 0 || !!cfg.battery_total_entity;
+ const hasBat =
+ bats.length > 0 || !!(cfg.battery_total_entity || cfg.battery_charge_entity || cfg.battery_discharge_entity);
const pvW = strings.map((x) => Math.max(0, readPower(hass, x.power_entity)));
const batW = bats.map((b) => readBattery(hass, b));
@@ -349,7 +383,7 @@ export class UltimatePowerCard extends LitElement {
const soc = Math.max(0, Math.min(100, parseFloat(hass.states?.[b.soc_entity]?.state ?? '') || 0));
const sign = batW[i] > IDLE_W ? '−' : batW[i] < -IDLE_W ? '+' : '';
return svg`
- this._moreInfo(b.power_entity)}>
+ this._moreInfo(b.power_entity ?? b.soc_entity)}>