Skip to content

Commit 1879a4f

Browse files
author
Sebastian N.
committed
added possibility to use 4 MPPT
1 parent 3da0765 commit 1879a4f

6 files changed

Lines changed: 56 additions & 8 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ For the compact card, it’s enough to provide e.g. `battery_percentage`, `solar
149149
| `solar` | boolean | Show solar card | `true` |
150150
| `compact` | boolean | Show compact version | `false` |
151151
| `max_input_power` | number | Maximum input power per input (W), for scaling P1/P2 bars | `600` |
152+
| `p3_power` | string | PV string 3 sensor | `null`|
153+
| `p4_power` | string | PV string 4 sensor | `null`|
152154

153155
### ⚙️ Custom Settings (`custom_settings`)
154156

b2500d-card.js

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const languages = { en, de, es, fr };
99

1010
function _getLangCode(langInput) {
1111
const raw = (langInput || (typeof navigator !== "undefined" && navigator.language) || "en").toString().toLowerCase();
12-
return raw.split(/[_-]/)[0];
12+
return raw.split(/[_-]/)[0];
1313
}
1414

1515
function localize(key, langInput) {
@@ -387,6 +387,27 @@ class B2500DCard extends LitElement {
387387
throw new Error(localize("errors.missing", this._hass?.language));
388388
}
389389

390+
391+
if (entities) {
392+
// Nur die relevanten Keys p1–p4 prüfen
393+
const powerKeys = ["p1_power", "p2_power", "p3_power", "p4_power"]
394+
.filter(k => entities[k] !== undefined);
395+
396+
const valid2 =
397+
powerKeys.length === 2 &&
398+
powerKeys.includes("p1_power") &&
399+
powerKeys.includes("p2_power");
400+
401+
const valid4 =
402+
powerKeys.length === 4 &&
403+
["p1_power", "p2_power", "p3_power", "p4_power"].every(k =>
404+
powerKeys.includes(k)
405+
);
406+
407+
if (!valid2 && !valid4) {
408+
throw new Error(localize("errors.entities_invalid", this._hass?.language));
409+
}
410+
}
390411
this.config = {
391412
output: true,
392413
battery: true,
@@ -439,6 +460,13 @@ class B2500DCard extends LitElement {
439460
this._solarPower = Number(this._hass.states[e.solar_power]?.state) || 0;
440461
this._p1 = Number(this._hass.states[e.p1_power]?.state) || 0;
441462
this._p2 = Number(this._hass.states[e.p2_power]?.state) || 0;
463+
this._p3 = this._hass.states[e.p3_power]?.state !== undefined
464+
? Number(this._hass.states[e.p3_power].state)
465+
: null;
466+
467+
this._p4 = this._hass.states[e.p4_power]?.state !== undefined
468+
? Number(this._hass.states[e.p4_power].state)
469+
: null;
442470
this._outputPower = Number(this._hass.states[e.output_power]?.state) || 0;
443471
this._batteryPercent = Number(this._hass.states[e.battery_percentage]?.state) || 0;
444472

@@ -472,6 +500,8 @@ class B2500DCard extends LitElement {
472500
total_input_power: "solar_power",
473501
input_1_power: "p1_power",
474502
input_2_power: "p2_power",
503+
input_3_power: "p3_power",
504+
input_4_power: "p4_power",
475505
total_output_power: "output_power",
476506
};
477507

@@ -576,12 +606,15 @@ class B2500DCard extends LitElement {
576606
const maxInputPower = this.config.max_input_power || 600;
577607
const p1Pct = Math.round((this._p1 / maxInputPower) * 100);
578608
const p2Pct = Math.round((this._p2 / maxInputPower) * 100);
609+
const p3Pct = Math.round((this._p3 / maxInputPower) * 100);
610+
const p4Pct = Math.round((this._p4 / maxInputPower) * 100);
611+
579612

580613
const selectEntity = this._hass.states[`select.${this.config.device}_charging_mode`];
581614
const switchEntity = this._hass.states[`switch.${this.config.device}_adaptive_mode`];
582615

583616

584-
return html`
617+
return html`
585618
<div class="container">
586619
<div class="device">
587620
<!-- Header -->
@@ -614,15 +647,24 @@ class B2500DCard extends LitElement {
614647
<div class="barlabels">
615648
<div>${this._p1} W</div>
616649
<div>${this._p2} W</div>
650+
${this._p3 != null ? html`<div>${this._p3} W</div>` : ""}
651+
${this._p4 != null ? html`<div>${this._p4} W</div>` : ""}
617652
</div>
618653
<div class="barwrap">
619-
<div class="bar p1"><div class="fill" style="width:${p1Pct}%"></div></div>
620-
<div class="bar p2 r"><div class="fill" style="width:${p2Pct}%"></div></div>
654+
<div class="bar"><div class="fill" style="width:${p1Pct}%"></div></div>
655+
<div class="bar ${this._p3 == null && this._p4 == null ? "r" : ""}"><div class="fill" style="width:${p2Pct}%"></div></div>
656+
${this._p3 != null ? html`<div class="bar r"><div class="fill" style="width:${p3Pct}%"></div></div>`
657+
: ""}
658+
${this._p4 != null ? html`<div class="bar r"><div class="fill" style="width:${p4Pct}%"></div></div>`
659+
: ""}
621660
</div>
622661
<div class="barlabels">
623662
<div class="hint">P1</div>
624663
<div class="hint">P2</div>
664+
${this._p3 != null ? html`<div class="hint">P3</div>` : ""}
665+
${this._p4 != null ? html`<div class="hint">P4</div>` : ""}
625666
</div>
667+
626668
</div>
627669
<div class="icon"><ha-icon icon="mdi:solar-power-variant-outline"></ha-icon></div>
628670
</article>` : ''}

localize/de.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
export default {
22
"errors": {
33
"both": "Bitte entweder 'device' oder 'entities' angeben, nicht beides.",
4-
"missing": "Du musst entweder 'device' oder 'entities' angeben."
4+
"missing": "Du musst entweder 'device' oder 'entities' angeben.",
5+
"entities_invalid" : "Erlaubt sind nur [p1_power + p2_power] oder [p1_power + p2_power + p3_power + p4_power].",
56
},
67
"labels": {
78
"last_update": "Aktualisierung",

localize/en.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
export default {
22
"errors": {
33
"both": "Please specify either 'device' or 'entities', not both.",
4-
"missing": "You must provide either 'device' or 'entities'."
4+
"missing": "You must provide either 'device' or 'entities'.",
5+
"entities_invalid" : "Only [p1_power + p2_power] or [p1_power + p2_power + p3_power + p4_power] are allowed",
56
},
67
"labels": {
78
"last_update": "Last Update",

localize/es.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
export default {
22
"errors": {
33
"both": "Especifica 'device' o 'entities', no ambos.",
4-
"missing": "Debes proporcionar 'device' o 'entities'."
4+
"missing": "Debes proporcionar 'device' o 'entities'.",
5+
"entities_invalid" : "Solo se permiten [p1_power + p2_power] o [p1_power + p2_power + p3_power + p4_power].",
56
},
67
"labels": {
78
"last_update": "Última actualización",

localize/fr.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
export default {
22
"errors": {
33
"both": "Veuillez indiquer soit 'device' soit 'entities', pas les deux.",
4-
"missing": "Vous devez fournir soit 'device' soit 'entities'."
4+
"missing": "Vous devez fournir soit 'device' soit 'entities'.",
5+
"entities_invalid" : "Seuls [p1_power + p2_power] ou [p1_power + p2_power + p3_power + p4_power] sont autorisés.",
56
},
67
"labels": {
78
"last_update": "Dernière mise à jour",

0 commit comments

Comments
 (0)