ha_history_detect_sessions
Detect activity sessions from numeric sensors using a threshold to reveal appliance runs, charging sessions, or heating cycles. Returns event counts, total duration, and session lists or daily summaries.
Instructions
Detects activity sessions from a numeric sensor using a power/value threshold. Use for threshold-based activity questions such as charging sessions, appliance runs, or heating cycles. Uses long-term hourly statistics → full date range, no retention limit, ±1h precision. For binary sensors or person/zone state history, use ha_history_get_state_history instead. Returns event count, total duration, a compact session list, or a daily summary with group_by="day".
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| end_time | No | Period end, same formats as start_time. Default: now. | |
| group_by | No | "day" returns one row per day (date | count | first start | last end | total active) instead of individual sessions. Use for daily patterns ("how many runs per day?"). Summary stats always cover the full dataset. | |
| entity_id | Yes | Exact entity_id resolved earlier, e.g. "sensor.car_charger_power". Do not guess. | |
| threshold | Yes | Minimum value to count as "active", in the sensor's own unit. Example: 100 for a Watt sensor (EV charger, heater, washing machine). | |
| comparison | No | Compare session count and duration to the immediately preceding equal-length period, or to the same calendar period 12 months ago. | |
| start_time | No | Period start. Formats: relative (7d/30d/24h/2w/1y), named ("last month"/"last week"/"yesterday"/"last summer"/"Q1"), or ISO ("2026-04-01"). Default: 30d. Special: "overnight" = 22:00 yesterday → 06:00 today. | |
| max_results | No | Max rows (sessions, or days with group_by). Default: 20. Pass "all" to list all. Summary stats always cover the full dataset regardless. | |
| day_start_hour | No | Only with group_by="day". Shifts the day boundary from midnight to this hour (0-23). E.g. 6 → a day runs 06:00-05:59, so 01:30 activity counts on the previous evening's date. | |
| max_gap_minutes | No | Bridge inactive gaps shorter than this into one session (minutes). Default: 0 (no merging). E.g. 120 for a washing machine pausing between cycles. Hourly statistics → use multiples of 60; values below 60 have no effect. | |
| min_duration_minutes | No | Discard sessions shorter than this (minutes). Default: 1. Hourly statistics → values below 60 have no additional effect. |