Skip to content

Limit db_primary recording to entities Predbat actually uses - #34

Merged
dandwhelan merged 1 commit into
mainfrom
db-primary-filter-mirror-list
Aug 5, 2026
Merged

dandwhelan merged 1 commit into
mainfrom
db-primary-filter-mirror-list

Conversation

@dandwhelan

Copy link
Copy Markdown
Owner

Problem

With db_primary: true the websocket subscription delivers state_changed for every entity in Home Assistant, and update_state_item recorded all of them — db_mirror_ha: false is bypassed by the or self.db_primary in 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_list already contains 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.

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

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>
@dandwhelan
dandwhelan merged commit 4e11374 into main Aug 5, 2026
2 checks passed
@dandwhelan
dandwhelan deleted the db-primary-filter-mirror-list branch August 5, 2026 11:07
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