Skip to content

Commit a5d92a9

Browse files
Merge pull request #5338 from springfall2008/fix/car-charging-now-response-charging
fix(fetch): accept a charger's "Charging" status in car_charging_now_response by default; document matching
2 parents c00eb8b + 7d0d2a1 commit a5d92a9

22 files changed

Lines changed: 132 additions & 20 deletions

‎apps/predbat/fetch.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2611,7 +2611,7 @@ def get_car_charging_planned(self):
26112611
self.car_charging_exclusive = [False for c in range(self.num_cars)]
26122612

26132613
self.car_charging_planned_response = [str(response).lower() for response in self.get_arg("car_charging_planned_response", ["yes", "on", "enable", "true"])]
2614-
self.car_charging_now_response = [str(response).lower() for response in self.get_arg("car_charging_now_response", ["yes", "on", "enable", "true"])]
2614+
self.car_charging_now_response = [str(response).lower() for response in self.get_arg("car_charging_now_response", ["yes", "on", "enable", "true", "charging"])]
26152615
self.car_charging_from_battery = self.get_arg("car_charging_from_battery")
26162616

26172617
# Car charging planned sensor

‎apps/predbat/tests/test_car_charging_now.py‎

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"car_charging_battery_size",
6767
)
6868
IOG_SENSOR = "binary_sensor.octopus_intelligent_slot_test"
69+
SAVED_ARGS = ("car_charging_now", "octopus_intelligent_slot", "car_charging_now_response")
6970

7071

7172
def _check(name, condition, detail=""):
@@ -377,23 +378,49 @@ def _run_power(my_predbat):
377378
return failed
378379

379380

381+
def _run_default_response(my_predbat):
382+
"""
383+
With car_charging_now_response unset, a charger status sensor reading "Charging" (e.g. a Zappi's
384+
plug_status) counts as charging. It did not before (GH#5335), so the Octopus Intelligent check
385+
cancelled the car's dispatch while it charged and the house battery lost the dispatch rate.
386+
"""
387+
failed = False
388+
print("Test 23: the default car_charging_now_response accepts a charger's Charging status")
389+
_car(my_predbat, False)
390+
my_predbat.args.pop("car_charging_now_response", None)
391+
for state, expected in (("Charging", True), ("EV Connected", False), ("on", True), ("off", False)):
392+
_sensor(my_predbat, state)
393+
my_predbat.get_car_charging_planned()
394+
failed |= _check("t23 cycle {!r}".format(state), my_predbat.car_charging_now == [expected], "now {}".format(my_predbat.car_charging_now))
395+
failed |= _check("t23 live {!r}".format(state), my_predbat.car_charging_now_reading(0) is expected, "")
396+
397+
print("Test 24: a car_charging_now_response set in apps.yaml replaces the default rather than adding to it")
398+
my_predbat.args["car_charging_now_response"] = ["yes", "on", "true"]
399+
_sensor(my_predbat, "Charging")
400+
my_predbat.get_car_charging_planned()
401+
failed |= _check("t24 Charging not in the set list", my_predbat.car_charging_now == [False], "now {}".format(my_predbat.car_charging_now))
402+
_sensor(my_predbat, None)
403+
return failed
404+
405+
380406
def test_car_charging_now(my_predbat):
381407
"""
382408
car_charging_now holds the battery and feeds the model, but never adds a car slot.
383409
"""
384410
print("*** Running test: car_charging_now")
385411
saved_state = {field: copy.deepcopy(getattr(my_predbat, field, None)) for field in STATE_FIELDS}
386-
saved_args = {key: copy.deepcopy(my_predbat.args[key]) for key in ("car_charging_now", "octopus_intelligent_slot") if key in my_predbat.args}
412+
saved_args = {key: copy.deepcopy(my_predbat.args[key]) for key in SAVED_ARGS if key in my_predbat.args}
387413
try:
388414
failed = _run_plan(my_predbat)
389415
failed |= _run_poll(my_predbat)
390416
failed |= _run_dynamic(my_predbat)
391417
failed |= _run_iog(my_predbat)
392418
failed |= _run_power(my_predbat)
419+
failed |= _run_default_response(my_predbat)
393420
finally:
394421
for field, value in saved_state.items():
395422
setattr(my_predbat, field, value)
396-
for key in ("car_charging_now", "octopus_intelligent_slot"):
423+
for key in SAVED_ARGS:
397424
if key in saved_args:
398425
my_predbat.args[key] = saved_args[key]
399426
else:

‎apps/predbat/tests/test_infra.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ def get_default_config(self):
479479
"car_charging_exclusive": False,
480480
"car_charging_from_battery": False,
481481
"car_charging_planned_response": ["yes", "on", "enable", "true"],
482-
"car_charging_now_response": ["yes", "on", "enable", "true"],
482+
"car_charging_now_response": ["yes", "on", "enable", "true", "charging"],
483483
"combine_rate_threshold": 1.0,
484484
"combine_export_slots": True,
485485
"combine_charge_slots": True,

‎docs/apps-yaml.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2084,7 +2084,7 @@ whether you are within an Octopus Energy "smart charge" slot
20842084
- **car_charging_planned** - Indicates when your EV is plugged in and planned to charge during low-rate slots.
20852085
- **car_charging_planned_response** - Values for the car_charging_planned sensor that indicate that the car is plugged in and will charge in the next low rate slot.
20862086
- **car_charging_now** - Sensor to indicate when the EV is charging, used to hold the house battery for the car. Either an on/off sensor or a charging power sensor (W or kW, 200W or more counts as charging)
2087-
- **car_charging_now_response** - Responses for car_charging_now to indicate that the car is charging
2087+
- **car_charging_now_response** - Responses for car_charging_now to indicate that the car is charging (default `yes`, `on`, `enable`, `true` and `charging`). The sensor state must match one of them, ignoring case
20882088
- **car_charging_battery_size** - Car battery size in kWh
20892089
- **car_charging_limit** - Percentage limit the car is set to charge to
20902090
- **car_charging_soc** - Car's current charge level expressed as a percentage

‎docs/car-charging.md‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ The following entries are pre-configured in the `apps.yaml` template:
186186
- 'yes'
187187
- 'on'
188188
- 'true'
189+
- 'charging'
189190
```
190191

191192
- **car_charging_planned** - Optional, can be set to a Home Assistant sensor (e.g. from your car charger integration) which lets Predbat know the car is plugged in and planned to charge during low-rate slots.
@@ -210,6 +211,8 @@ Leave it commented out if you have no sensor that reports the car actually drawi
210211
The Ohme (`ohme_automatic`), myenergi Zappi (`myenergi_automatic`) and Predbat gateway integrations set it for you, unless you have set it yourself in `apps.yaml`.
211212

212213
- **car_charging_now_response** - Set to the range of positive responses for car_charging_now to indicate that the car is charging. Useful if you have a sensor for your car charger that isn't binary.
214+
The sensor's state must match one of these exactly (ignoring case). If unset it defaults to `yes`, `on`, `enable`, `true` and `charging`, which covers on/off sensors and chargers whose status reads `Charging`, such as a myenergi Zappi's plug status.
215+
If your charger reports something else while charging, add that value here. Otherwise Predbat never sees the car charging, and with Octopus Intelligent it [cancels the car's dispatches](#checking-intelligent-dispatches-against-the-car).
213216

214217
To make Predbat-led car charging more accurate, additionally you can configure the following items in `apps.yaml`:
215218

@@ -523,6 +526,18 @@ It can be an on/off sensor (matched against **car_charging_now_response**), or a
523526
- sensor.wallbox_portal_charging_power
524527
```
525528

529+
A status sensor works too, as long as its state while charging is one of the **car_charging_now_response** values. For example a myenergi Zappi's plug status, from the Home Assistant myenergi integration, reads `Charging`, which the default list accepts:
530+
531+
```yaml
532+
car_charging_now:
533+
- sensor.myenergi_zappi_XXXXXXXX_plug_status
534+
```
535+
536+
If you set **car_charging_now_response** yourself, keep `charging` in it, and the values your other cars' sensors use: the one list covers every car.
537+
With `myenergi_automatic`, Predbat already points **car_charging_now** at the Zappi's charging power, so leave it unset.
538+
539+
If the sensor's state never matches, Predbat never sees the car charging, so it cancels every dispatch the car is in, even while the car charges.
540+
526541
Without **car_charging_now**, if your car is inside the CT clamp (**switch.predbat_car_energy_reported_load** On), Predbat uses the house load instead - slower and less certain, as other appliances also move it.
527542
With neither, nothing is checked.
528543

@@ -565,6 +580,14 @@ For example, Octopus dispatches the car from 15:55 to 16:01 but the charger repo
565580
- Check **switch.predbat_octopus_intelligent_charging** is On, so Predbat builds the car plan from the Octopus dispatches.
566581
- Look in the log for `Octopus Intelligent: car` lines. If there are none while the car sits idle in a dispatch, the check is not running. Note that the `Dynamic load last period ...` line is written every cycle whatever these settings are, so it does not show the check is running.
567582

583+
**If a dispatch is cancelled while the car is charging**
584+
585+
The log shows `car 0 is in a dispatch but not charging, cancelling its slots` although the car is charging. Predbat is not reading **car_charging_now** as charging:
586+
587+
- Look at the sensor's history in Home Assistant while the car charges. If it shows a status such as `Charging`, check that value is in **car_charging_now_response**. A `car_charging_now_response` list you set in `apps.yaml` replaces the default, so it must include `charging` itself.
588+
- The log's `Cars ... charging_now [False]` line shows what Predbat made of the sensor each cycle.
589+
- A charging power sensor (200W or more counts as charging) avoids matching status text altogether.
590+
568591
#### Reading the dispatch timeline in the logs
569592

570593
When Octopus Intelligent charging is active Predbat writes a diagnostic line to the log each cycle

‎templates/alphaess_cloud.yaml‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,15 @@ pred_bat:
164164
#car_charging_now:
165165
# - sensor.wallbox_portal_charging_power
166166

167-
# Positive responses for car_charging_now
167+
# Positive responses for car_charging_now, for an on/off or status sensor. Its state must match one
168+
# of these (ignoring case) for Predbat to see the car charging - e.g. 'charging' for a myenergi Zappi
169+
# plug_status sensor. If it never matches while the car charges, Predbat cancels the car's Octopus Intelligent
170+
# dispatches (switch.predbat_octopus_intelligent_dynamic, On by default) and the house battery can lose their cheap rate.
168171
car_charging_now_response:
169172
- 'yes'
170173
- 'on'
171174
- 'true'
175+
- 'charging'
172176

173177
# To make planned car charging more accurate, either using car_charging_planned or the Octopus Energy plugin,
174178
# specify your battery size in kwh, charge limit % and current car battery soc % sensors/values.

‎templates/enphase_cloud.yaml‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,15 @@ pred_bat:
145145
#car_charging_now:
146146
# - sensor.wallbox_portal_charging_power
147147

148-
# Positive responses for car_charging_now
148+
# Positive responses for car_charging_now, for an on/off or status sensor. Its state must match one
149+
# of these (ignoring case) for Predbat to see the car charging - e.g. 'charging' for a myenergi Zappi
150+
# plug_status sensor. If it never matches while the car charges, Predbat cancels the car's Octopus Intelligent
151+
# dispatches (switch.predbat_octopus_intelligent_dynamic, On by default) and the house battery can lose their cheap rate.
149152
car_charging_now_response:
150153
- 'yes'
151154
- 'on'
152155
- 'true'
156+
- 'charging'
153157

154158
# To make planned car charging more accurate, either using car_charging_planned or the Octopus Energy plugin,
155159
# specify your battery size in kwh, charge limit % and current car battery soc % sensors/values.

‎templates/ep_cube_cloud.yaml‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,15 @@ pred_bat:
199199
#car_charging_now:
200200
# - sensor.wallbox_portal_charging_power
201201

202-
# Positive responses for car_charging_now
202+
# Positive responses for car_charging_now, for an on/off or status sensor. Its state must match one
203+
# of these (ignoring case) for Predbat to see the car charging - e.g. 'charging' for a myenergi Zappi
204+
# plug_status sensor. If it never matches while the car charges, Predbat cancels the car's Octopus Intelligent
205+
# dispatches (switch.predbat_octopus_intelligent_dynamic, On by default) and the house battery can lose their cheap rate.
203206
car_charging_now_response:
204207
- 'yes'
205208
- 'on'
206209
- 'true'
210+
- 'charging'
207211

208212
# To make planned car charging more accurate, either using car_charging_planned or the Octopus Energy plugin,
209213
# specify your battery size in kwh, charge limit % and current car battery soc % sensors/values.

‎templates/fox_cloud.yaml‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,15 @@ pred_bat:
136136
#car_charging_now:
137137
# - sensor.wallbox_portal_charging_power
138138

139-
# Positive responses for car_charging_now
139+
# Positive responses for car_charging_now, for an on/off or status sensor. Its state must match one
140+
# of these (ignoring case) for Predbat to see the car charging - e.g. 'charging' for a myenergi Zappi
141+
# plug_status sensor. If it never matches while the car charges, Predbat cancels the car's Octopus Intelligent
142+
# dispatches (switch.predbat_octopus_intelligent_dynamic, On by default) and the house battery can lose their cheap rate.
140143
car_charging_now_response:
141144
- 'yes'
142145
- 'on'
143146
- 'true'
147+
- 'charging'
144148

145149
# To make planned car charging more accurate, either using car_charging_planned or the Octopus Energy plugin,
146150
# specify your battery size in kwh, charge limit % and current car battery soc % sensors/values.

‎templates/ge_cloud_octopus_standalone.yaml‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,15 @@ pred_bat:
160160
#car_charging_now:
161161
# - sensor.wallbox_portal_charging_power
162162

163-
# Positive responses for car_charging_now
163+
# Positive responses for car_charging_now, for an on/off or status sensor. Its state must match one
164+
# of these (ignoring case) for Predbat to see the car charging - e.g. 'charging' for a myenergi Zappi
165+
# plug_status sensor. If it never matches while the car charges, Predbat cancels the car's Octopus Intelligent
166+
# dispatches (switch.predbat_octopus_intelligent_dynamic, On by default) and the house battery can lose their cheap rate.
164167
car_charging_now_response:
165168
- 'yes'
166169
- 'on'
167170
- 'true'
171+
- 'charging'
168172

169173
# To make planned car charging more accurate, either using car_charging_planned or the Octopus Energy plugin,
170174
# specify your battery size in kwh, charge limit % and current car battery soc % sensors/values.

0 commit comments

Comments
 (0)