Skip to content

Add automated cell balancing for Tesla batteries (bleed+charge cycle)#2074

Open
hpetersen wants to merge 2 commits intodalathegreat:mainfrom
hpetersen:feature/tesla-auto-balance
Open

Add automated cell balancing for Tesla batteries (bleed+charge cycle)#2074
hpetersen wants to merge 2 commits intodalathegreat:mainfrom
hpetersen:feature/tesla-auto-balance

Conversation

@hpetersen
Copy link
Copy Markdown

@hpetersen hpetersen commented Feb 27, 2026

Summary

Adds an automated balancing procedure for Tesla batteries that solves the problem of high cell deviation causing premature charge termination.

The problem: When one cell reaches e.g. 3650 mV while others are at 3300 mV, the BMS stops charging and reports 100% SOC — but real capacity may only be ~75%. Manual intervention is tedious and time consuming.

The solution: An automated state machine that exploits Tesla's built-in passive bleed procedure (active when contactors are open) and cycles between bleed and charge phases until cells are balanced, automatically handling the isolation clear + BMS reset sequence required between cycles.

How it works

  1. Open contactors — Tesla BMS passively bleeds high cells down via internal resistors
  2. Wait until cell deviation drops below the configured threshold (default 20 mV)
  3. Automatically run isolation clear + BMS reset (up to 5 retries if contactor close fails)
  4. Close contactors and charge at a limited power (default 500 W, ~1.4 A at 350 V)
  5. Re-bleed if deviation exceeds the re-bleed threshold (default 50 mV) during charging
  6. Stop when any cell reaches the configured max voltage ceiling (default 3650 mV LFP)

Configurable settings (via webserver)

Setting Default Description
Max cell voltage ceiling 3650 mV Hard stop — never exceeded
Charge power limit 500 W Gentle charge to protect imbalanced cells
Open contactors above deviation 50 mV Re-bleed trigger during charging
Close contactors below deviation 20 mV Exit bleed, start charging

Events & MQTT

Six new events (all automatically published to MQTT via the existing event system):

Event Level Trigger
AUTO_BALANCE_START INFO Feature activated
AUTO_BALANCE_CONTACTORS_OPEN INFO Bleed phase started (data = cycle number)
AUTO_BALANCE_CONTACTORS_CLOSED INFO Charge phase started (data = cycle number)
AUTO_BALANCE_STOP INFO Ceiling hit, normal operation restored
AUTO_BALANCE_RETRY WARNING Contactor close failed, retrying (data = attempt number)
AUTO_BALANCE_ERROR ERROR Hard abort (data: 1=open timeout, 2=close failed after 5 attempts)

Files changed

  • TESLA-BATTERY.cpp — 12-state machine in update_values(), charge power cap, contactor hold flag in transmit_can()
  • TESLA-BATTERY.h — 5 new member variables
  • datalayer.h — 5 new settings fields
  • events.h / events.cpp — 6 new event types with messages
  • webserver.cpp — 5 new HTTP routes
  • settings_html.cpp — template vars, JS functions, HTML section (Tesla-only, hidden for other chemistries)

Notes

  • Tesla Model 3/Y only (chassis type > 1), same guard as existing manual balancing
  • Charge power limit is independent from the manual balancing float power
  • Contactors are held open by sending ACCESSORY/GOING_DOWN/OFF instead of DRIVE on CAN 0x221 — no hardware changes required
  • State machine runs on the existing 1-second update_values() tick — negligible CPU/memory impact

hpetersen and others added 2 commits February 27, 2026 11:53
Adds an automated balancing state machine for Tesla Model 3/Y batteries
that cycles between contactor-open bleed phases and charge phases to
restore cell balance when high deviation prevents a full charge.

- 12-state machine in update_values() controls the full cycle
- Contactors held open via ACCESSORY/GOING_DOWN/OFF on CAN 0x221
- Automatically runs isolation clear + BMS reset between cycles,
  with up to 5 retries if contactors fail to close
- Charge power independently capped (default 500W) to protect
  imbalanced cells during forced charging
- Hard stop when any cell reaches the configured voltage ceiling
- 6 new events (INFO/WARNING/ERROR) auto-published to MQTT
- All settings configurable via webserver (Tesla-only UI section)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

1 participant