From 844e15a79703e2719c93e186eafaea0dacb2b6c4 Mon Sep 17 00:00:00 2001 From: hbrain Date: Thu, 25 Jun 2026 11:33:43 +0000 Subject: [PATCH] History stats sensor prioritized --- ha_observer.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/ha_observer.py b/ha_observer.py index 3140687..6b20490 100755 --- a/ha_observer.py +++ b/ha_observer.py @@ -125,6 +125,17 @@ IMPORTANT_ENTITY_KEYWORDS = { "smb_": 60, } +HISTORY_STATS_MARKERS = { + "_daily", + "_weekly", + "_monthly", + "_last7days", + "_last_7_days", + "_work_hours", + "_flex_hours", + "_count_sql", +} + class ConfigError(RuntimeError): pass @@ -480,6 +491,18 @@ def display_time(value: str | None) -> str: return value +def looks_like_history_stats_sensor(entity_id: str, attrs: dict[str, Any] | None = None) -> bool: + attrs = attrs or {} + if not entity_id.startswith("sensor."): + return False + text = f"{entity_id} {attrs.get('friendly_name', '')}".lower() + if any(marker in text for marker in HISTORY_STATS_MARKERS): + return True + if any(marker in text for marker in {"work hours", "flex hours"}): + return True + return attrs.get("device_class") == "duration" and any(marker in text for marker in {"hours today", "hours this week"}) + + def entity_importance(entity_id: str, attrs: dict[str, Any] | None = None) -> int: attrs = attrs or {} domain = entity_id.split(".", 1)[0] @@ -505,6 +528,11 @@ def entity_importance(entity_id: str, attrs: dict[str, Any] | None = None) -> in if keyword in text: score += points + # History Stats sensors summarize behavior over a day/week/month; keep them + # above lower-value chatter when snapshots are capped. + if looks_like_history_stats_sensor(entity_id, attrs): + score += 220 + # Sønderborg/Denmark home is the primary residence and absolute priority. # Samobor/Croatia entities use the smb_ prefix and are still included, but # they should lose ties when the LLM input has to be size-limited.