Repository navigation
Limit db_primary recording to entities Predbat actually uses - #34
Merged
Merged
Conversation
With db_primary enabled the websocket subscription delivers state_changed for every entity in Home Assistant, and update_state_item recorded all of them: 1,846 entities and 5.3M state rows (1.4 GB at db_days=14) on a live install, two thirds of it lights, cameras and presence sensors Predbat never reads. One mmWave presence sensor alone was 36% of the database. db_mirror_list already holds exactly the entities Predbat has read or written (get_state, update_state, get_history and set_state all register there), so gate db_primary recording on membership of that list, the same way db_mirror_ha already is. In-memory state_data is unaffected, so watched entities still update live; only what is persisted changes. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Problem
With
db_primary: truethe websocket subscription deliversstate_changedfor every entity in Home Assistant, andupdate_state_itemrecorded all of them —db_mirror_ha: falseis bypassed by theor self.db_primaryin the condition.Measured on the live install: 1,846 entities and 5.3M state rows (1.4 GB at
db_days: 14), two thirds of it lights, cameras, automations and presence sensors Predbat never reads. One mmWave presence sensor alone accounted for 36% of the database. The oversized file also lengthens write transactions, which widened the window for the restart-time corruption incidents.Fix
db_mirror_listalready contains exactly the entities Predbat has read or written (get_state,update_state,get_historyandset_stateall register there), so gatedb_primaryrecording on membership of that list, the same waydb_mirror_haalready is.state_data(in-memory state) is untouched, so watched entities still update live; only what is persisted to SQLite changes.Verified
Deployed on the Pi 2026-08-05: after a restart plus one full plan cycle, only 70 entities are being recorded (predbat's own entities, GivTCP sensors, Octopus rates, car chargers, Solcast) instead of all 1,846. Plan output unchanged.
No THIS_VERSION bump — intended to ride along with the next release.
🤖 Generated with Claude Code