Skip to content

Commit 41afe3d

Browse files
committed
Report solar surplus power even when no car is charging
The power sensor now shows effective export whenever the solar surplus feature is enabled, not only when a car qualifies. This lets automations for other surplus loads (iBoost, pool pump) use the same signal.
1 parent 80fa301 commit 41afe3d

3 files changed

Lines changed: 7 additions & 6 deletions

File tree

apps/predbat/execute.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,7 @@ def detect_car_solar_surplus(self, in_force_export_window):
733733
self._car_surplus_prev = list(self.car_charging_solar_surplus_active)
734734
return
735735

736+
self.car_charging_solar_surplus_power = max(0, self.grid_power)
736737
surplus_hysteresis = 200 # W deadband to prevent flapping
737738
# Tolerance for transient battery discharge while surplus is asserted.
738739
# Distinct from car_charging_solar_surplus_threshold (the user-facing

apps/predbat/tests/test_execute.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2589,7 +2589,7 @@ def run_execute_tests(my_predbat):
25892589
battery_power=0,
25902590
assert_status="Demand",
25912591
assert_solar_surplus_active=[False],
2592-
assert_solar_surplus_power=0,
2592+
assert_solar_surplus_power=3000,
25932593
)
25942594
if failed:
25952595
return failed
@@ -3032,7 +3032,7 @@ def run_solar_surplus_power_sensor_test(my_predbat):
30323032
print("ERROR: power sensor surplus_active should be True, got {}".format(power_sensor.get("surplus_active")))
30333033
failed = True
30343034

3035-
# Now test with no surplus — sensor should publish 0
3035+
# When car doesn't qualify but there's still export, sensor shows raw export
30363036
failed |= run_execute_test(
30373037
my_predbat,
30383038
"solar_surplus_power_sensor_inactive",
@@ -3044,12 +3044,12 @@ def run_solar_surplus_power_sensor_test(my_predbat):
30443044
battery_power=0,
30453045
assert_status="Demand",
30463046
assert_solar_surplus_active=[False],
3047-
assert_solar_surplus_power=0,
3047+
assert_solar_surplus_power=3000,
30483048
)
30493049
power_sensor = my_predbat.ha_interface.dummy_items.get(power_sensor_id, {})
30503050
if isinstance(power_sensor, dict):
3051-
if power_sensor.get("state") != 0.0:
3052-
print("ERROR: power sensor state should be 0.0 when inactive, got {}".format(power_sensor.get("state")))
3051+
if power_sensor.get("state") != 3.0:
3052+
print("ERROR: power sensor state should be 3.0 (kW) when car inactive, got {}".format(power_sensor.get("state")))
30533053
failed = True
30543054
if power_sensor.get("surplus_active") is not False:
30553055
print("ERROR: power sensor surplus_active should be False when inactive, got {}".format(power_sensor.get("surplus_active")))

docs/car-charging.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ Enable the feature with these Predbat entities:
587587

588588
- **binary_sensor.predbat_car_charging_slot** gains a `solar_surplus: true` attribute when activated by surplus (rather than a planned charging window).
589589
- **binary_sensor.predbat_car_charging_solar_surplus** -- Dedicated sensor showing whether surplus charging is currently active.
590-
- **predbat.car_charging_solar_surplus_power** -- Numeric sensor (kW) showing the effective solar surplus power available for car charging. When surplus is active and the car was charging last cycle, this includes the car's own consumption added back to get the true available export. Useful for automations that adjust charging current proportionally (e.g. `surplus_kw * 1000 / 230 = amps`). Attributes include `threshold` (configured shortfall allowance in W), `battery_power` (current home battery power in kW), and `surplus_active` (boolean).
590+
- **predbat.car_charging_solar_surplus_power** -- Numeric sensor (kW) showing the effective solar surplus power available. Always reports current export power when the solar surplus feature is enabled, even if no car is currently charging from surplus. When a car was surplus-charging last cycle, the car's own consumption is added back to show the true available export. Useful for automations that adjust charging current proportionally (e.g. `surplus_kw * 1000 / 230 = amps`) or for driving other solar surplus loads (iBoost, pool pump). Attributes include `threshold` (configured shortfall allowance in W), `battery_power` (current home battery power in kW), and `surplus_active` (boolean).
591591

592592
### Interaction with other settings
593593

0 commit comments

Comments
 (0)