Skip to content

Commit 7bc8f44

Browse files
committed
Add Power Negate option to Solar Power Sensor
Some exotic setups may have a negative power value for solar. Given grid and battery have negate options it doesn't seem out of place for solar to have that also.
1 parent 4b4cfc9 commit 7bc8f44

File tree

5 files changed

+31
-2
lines changed

5 files changed

+31
-2
lines changed

src/data/energy.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ export interface SolarSourceTypeEnergyPreference {
158158

159159
stat_energy_from: string;
160160
stat_rate?: string;
161+
stat_rate_negate?: boolean;
161162
config_entry_solar_forecast: string[] | null;
162163
}
163164

src/panels/config/energy/dialogs/dialog-energy-solar-settings.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,19 @@ export class DialogEnergySolarSettings
135135
{ unit: this._power_units?.join(", ") || "" }
136136
)}
137137
></ha-statistic-picker>
138+
<ha-formfield
139+
.label=${html`<div style="display: flex; align-items: center;">
140+
${this.hass.localize(
141+
"ui.panel.config.energy.solar.dialog.solar_production_power_negate"
142+
)}
143+
</div>`}
144+
>
145+
<ha-checkbox
146+
@change=${this._powerNegateChanged}
147+
.checked=${!!this._source?.stat_rate_negate}
148+
>
149+
</ha-checkbox>
150+
</ha-formfield>
138151
139152
<h3>
140153
${this.hass.localize(
@@ -293,6 +306,14 @@ export class DialogEnergySolarSettings
293306
this._source = { ...this._source!, stat_rate: ev.detail.value };
294307
}
295308

309+
private _powerNegateChanged(ev) {
310+
const input = ev.currentTarget as HaCheckbox;
311+
this._source = {
312+
...this._source!,
313+
stat_rate_negate: input.checked,
314+
};
315+
}
316+
296317
private async _save() {
297318
try {
298319
if (!this._forecast) {

src/panels/lovelace/cards/energy/hui-power-sankey-card.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,10 @@ class HuiPowerSankeyCard
494494
.filter((source) => source.type === "solar")
495495
.forEach((source) => {
496496
if (source.type === "solar" && source.stat_rate) {
497-
const value = this._getCurrentPower(source.stat_rate);
497+
const value = this._getCurrentPower(
498+
source.stat_rate,
499+
!!source.stat_rate_negate
500+
);
498501
if (value > 0) {
499502
solar += value;
500503
}

src/panels/lovelace/cards/energy/hui-power-sources-graph-card.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,10 @@ export class HuiPowerSourcesGraphCard
180180
for (const source of energyData.prefs.energy_sources) {
181181
if (source.type === "solar") {
182182
if (source.stat_rate) {
183-
statIds.solar.stats.push({ id: source.stat_rate });
183+
statIds.solar.stats.push({
184+
id: source.stat_rate,
185+
negate: !!source.stat_rate_negate,
186+
});
184187
}
185188
continue;
186189
}

src/translations/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3163,6 +3163,7 @@
31633163
"entity_para": "Pick a sensor which measures solar production in either of {unit}.",
31643164
"solar_production_energy": "Solar production energy",
31653165
"solar_production_power": "Solar production power",
3166+
"solar_production_power_negate": "Invert power sensor polarity",
31663167
"solar_production_forecast": "Solar production forecast",
31673168
"solar_production_forecast_description": "Adding solar production forecast information will allow you to quickly see your expected production for today.",
31683169
"dont_forecast_production": "Don't forecast production",

0 commit comments

Comments
 (0)