Add automated cell balancing for Tesla batteries (bleed+charge cycle)#2074
Open
hpetersen wants to merge 2 commits intodalathegreat:mainfrom
Open
Add automated cell balancing for Tesla batteries (bleed+charge cycle)#2074hpetersen wants to merge 2 commits intodalathegreat:mainfrom
hpetersen wants to merge 2 commits intodalathegreat:mainfrom
Conversation
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>
for more information, see https://pre-commit.ci
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Configurable settings (via webserver)
Events & MQTT
Six new events (all automatically published to MQTT via the existing event system):
Files changed
TESLA-BATTERY.cpp— 12-state machine inupdate_values(), charge power cap, contactor hold flag intransmit_can()TESLA-BATTERY.h— 5 new member variablesdatalayer.h— 5 new settings fieldsevents.h/events.cpp— 6 new event types with messageswebserver.cpp— 5 new HTTP routessettings_html.cpp— template vars, JS functions, HTML section (Tesla-only, hidden for other chemistries)Notes
ACCESSORY/GOING_DOWN/OFFinstead ofDRIVEon CAN 0x221 — no hardware changes requiredupdate_values()tick — negligible CPU/memory impact