Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 25, 2026

Manual car SOC (input_number.predbat_car_charging_manual_soc_kwh) was being reset to zero during charging slots. Root causes: entity configured with restore: False causing HA restart resets, and no validation before writing predicted values back to entity.

Changes

State persistence (config.py)

  • Set restore: True for car_charging_manual_soc_kwh entities (all 4 cars)
  • Prevents reset to default 0.0 on HA restart

Write protection (predbat.py)

  • Validate car_charging_soc_next before updating entity
  • Block writes when value drops from >1 kWh to <0.1 kWh
  • Log warning instead of corrupting user data
if self.car_charging_soc_next[car_n] < 0.1 and self.car_charging_soc[car_n] > 1.0:
    self.log("Warn: Car {} manual SOC would be reset from {:.2f} kWh to {:.2f} kWh - skipping update".format(...))
else:
    self.expose_config("car_charging_manual_soc_kwh" + car_postfix, dp3(self.car_charging_soc_next[car_n]))

Diagnostic logging (fetch.py)

  • Track previous SOC values across update cycles
  • Log when manual SOC unexpectedly drops from high to near-zero values

Tests (tests/test_car_charging_manual_soc.py)

  • Validates protection allows reasonable updates (30→35 kWh)
  • Validates protection blocks resets (30→0.05 kWh)
  • Validates zero-to-zero and small value edge cases

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • api.octopus.energy
    • Triggering command: /home/REDACTED/work/batpred/batpred/coverage/venv/bin/python3 python3 ../apps/predbat/unit_test.py --quick (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Car charging manual SOC (Car 0) changed to Zero when charging starts</issue_title>
<issue_description>Describe the bug
When predbat starts a charging slot the nput_number.predbat_car_charging_manual_soc_kwh is reset to zero even if a value has been put in previousely and used by predbat to calculate charging slots, this then causes the charging slots to be recalulaed as if the car battery was empty.
The value continues to incriment throught the charge after it being reset
If you re-reset it to a value during the charge it is once again ptu back to zero

Expected behaviour
When the charging starts teh additional charge is added to the input_number.predbat_car_charging_manual_soc_kwh

Predbat version

v8.32.11

Environment details

Give Energy Inverter & Battery
Homeassistant OS running in hyper-v on windows
zappi car charger

switch.predbat_car_charging_manual_soc set to true
input_number.predbat_car_charging_manual_soc_kwh initialy set to the Kwh left in the battery
switch.predbat_car_charging_plan_smart set to true

num_cars: 1
car_charging_energy: "re:(sensor.myenergi_zappi_[0-9a-z]+charge_added_session|sensor.wallbox_portal_added_energy)"
car_charging_planned: - "re:(sensor.wallbox_portal_status_description|sensor.myenergi_zappi
[0-9a-z]+_plug_status)"

the three values below are all commented out in my apps.yaml
car_charging_limit:
car_charging_soc:
car_charging_exclusive:

Screenshots
If applicable, add screenshots to help explain your problem. The most useful ones can be your battery chart, the Predbat HTML plan and your current settings in HA.

Log file
I can download after the weekend with a fresh example if needed

Predbat debug yaml file

predbat_debug.yaml.txt
</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits January 25, 2026 13:50
Co-authored-by: springfall2008 <48591903+springfall2008@users.noreply.github.com>
Co-authored-by: springfall2008 <48591903+springfall2008@users.noreply.github.com>
Co-authored-by: springfall2008 <48591903+springfall2008@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix manual SOC reset when charging starts Fix car charging manual SOC reset to zero on entity write Jan 25, 2026
Copilot AI requested a review from springfall2008 January 25, 2026 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Car charging manual SOC (Car 0) changed to Zero when charging starts

2 participants