|
| 1 | +--- |
| 2 | +title: Home Assistant Area Management & Automation |
| 3 | +date: 2026-01-18 |
| 4 | +draft: true |
| 5 | +highlight: false |
| 6 | +tags: |
| 7 | + - smart-home |
| 8 | + - automation |
| 9 | + - home-assistant |
| 10 | +description: Comprehensive guide to Custom Area Management & Automation system for presence-based home automation. |
| 11 | +--- |
| 12 | + |
| 13 | +# Area Management & Automation |
| 14 | + |
| 15 | +This article documents the complete Area Management & Automation system, which enables intelligent presence-based control of lights, climate, and other devices throughout the home. |
| 16 | + |
| 17 | +## Overview |
| 18 | + |
| 19 | +The system consists of two main components: |
| 20 | + |
| 21 | +1. **Area Manager** (`area_manager.yaml`) — Dynamically creates and manages area entities via MQTT |
| 22 | +2. **Area Logic** (`pyscript/area_logic.py`) — State machine that processes occupancy changes |
| 23 | +3. **Area Automations** (`area_automations.yaml`) — Executes actions based on state transitions *(planned)* |
| 24 | + |
| 25 | +--- |
| 26 | + |
| 27 | +## Automation Modes |
| 28 | + |
| 29 | +Each area can operate in one of four modes, controlling how the system responds to presence: |
| 30 | + |
| 31 | +| Mode | Description | |
| 32 | +|------|-------------| |
| 33 | +| `presence-control` | Full automation: responds to all state changes (occupied, idle, absence, sleep) | |
| 34 | +| `absence-detection` | Only responds to absence — useful for "turn off when empty" without auto-on | |
| 35 | +| `manual-control` | No automatic actions — area state still tracked but no automations fire | |
| 36 | +| `schedule-mode` | Actions based on time schedule rather than presence *(future)* | |
| 37 | + |
| 38 | +--- |
| 39 | + |
| 40 | +## Mode-Based Filtering |
| 41 | + |
| 42 | +The automation mode controls which state transitions trigger actions: |
| 43 | + |
| 44 | +| Mode | Occupied | Idle | Absence | Sleep | |
| 45 | +|------|:--------:|:----:|:-------:|:-----:| |
| 46 | +| `presence-control` | ✅ | ✅ | ✅ | ✅ | |
| 47 | +| `absence-detection` | ❌ | ❌ | ✅ | ❌ | |
| 48 | +| `schedule-mode` | ⏰ | ⏰ | ⏰ | ⏰ | |
| 49 | +| `manual-control` | ❌ | ❌ | ❌ | ❌ | |
| 50 | + |
| 51 | +> [!NOTE] |
| 52 | +> The `schedule-mode` uses time-based rules instead of presence triggers. |
| 53 | +
|
| 54 | +--- |
| 55 | + |
| 56 | +## State Machine Flow |
| 57 | + |
| 58 | +When presence is detected, areas transition through the following states: |
| 59 | + |
| 60 | +```mermaid |
| 61 | +stateDiagram-v2 |
| 62 | + direction LR |
| 63 | + |
| 64 | + [*] --> Absence : Initial |
| 65 | + |
| 66 | + Absence --> Occupied : Motion Detected |
| 67 | + Occupied --> Idle : Motion Stops |
| 68 | + Idle --> Occupied : Motion Detected |
| 69 | + Idle --> Absence : Idle Timer Expires |
| 70 | + Absence --> [*] : Shutdown Event |
| 71 | + |
| 72 | + Occupied --> Sleep : Bed Sensor ON\n(after entry delay) |
| 73 | + Sleep --> Occupied : Bed Sensor OFF\n(after exit delay) |
| 74 | +``` |
| 75 | + |
| 76 | +### State Descriptions |
| 77 | + |
| 78 | +| State | Description | Triggered By | |
| 79 | +|-------|-------------|--------------| |
| 80 | +| **Occupied** | Active presence detected | Occupancy sensor turns ON | |
| 81 | +| **Idle** | No motion but grace period active | Occupancy sensor turns OFF | |
| 82 | +| **Absence** | Area confirmed empty | Idle timer expires | |
| 83 | +| **Sleep** | Occupant is sleeping | Bed sensor ON + entry delay | |
| 84 | +| **DND** | Do Not Disturb (manual override) | User sets manually | |
| 85 | + |
| 86 | +--- |
| 87 | + |
| 88 | +## Key Entities |
| 89 | + |
| 90 | +When an area is initialized, the following entities are created via MQTT discovery: |
| 91 | + |
| 92 | +### Configuration Entities |
| 93 | + |
| 94 | +| Entity Pattern | Type | Purpose | |
| 95 | +|----------------|------|---------| |
| 96 | +| `select.area_{slug}_automation_mode` | Select | Sets the automation mode | |
| 97 | +| `select.area_{slug}_occupancy_source` | Select | Physical sensor for presence | |
| 98 | +| `select.area_{slug}_bed_sensor` | Select | Physical sensor for sleep detection | |
| 99 | +| `switch.area_{slug}_automation` | Switch | Master enable/disable for this area | |
| 100 | + |
| 101 | +### Timer Settings |
| 102 | + |
| 103 | +| Entity Pattern | Type | Default | Purpose | |
| 104 | +|----------------|------|---------|---------| |
| 105 | +| `number.area_{slug}_presence_idle_time` | Number | 15s | Time before Occupied → Idle | |
| 106 | +| `number.area_{slug}_lights_presence_delay` | Number | 120s | Time before Idle → Absence (shutdown) | |
| 107 | +| `number.area_{slug}_sleep_entry_delay` | Number | 300s | Time in bed before Sleep state | |
| 108 | +| `number.area_{slug}_sleep_exit_delay` | Number | 60s | Time out of bed before leaving Sleep | |
| 109 | + |
| 110 | +### State Entities |
| 111 | + |
| 112 | +| Entity Pattern | Type | Purpose | |
| 113 | +|----------------|------|---------| |
| 114 | +| `select.area_{slug}_state` | Select | Current area state (Occupied/Idle/Absence/Sleep/DND) | |
| 115 | +| `binary_sensor.area_{slug}_occupancy` | Binary Sensor | Computed occupancy (ON when state is not Absence) | |
| 116 | +| `sensor.area_{slug}_timer` | Sensor | Countdown timer display | |
| 117 | + |
| 118 | +--- |
| 119 | + |
| 120 | +## Events Fired |
| 121 | + |
| 122 | +The system fires events that automations can listen to: |
| 123 | + |
| 124 | +| Event | When Fired | Data | |
| 125 | +|-------|------------|------| |
| 126 | +| `event_area_{slug}_wakeup` | Area transitions TO "Occupied" | `area: {slug}` | |
| 127 | +| `event_area_{slug}_shutdown` | Absence delay timer expires | `area: {slug}` | |
| 128 | + |
| 129 | +### Example Automation Trigger |
| 130 | + |
| 131 | +```yaml |
| 132 | +automation: |
| 133 | + - alias: "Office: Turn off lights on shutdown" |
| 134 | + trigger: |
| 135 | + - platform: event |
| 136 | + event_type: event_area_office_shutdown |
| 137 | + action: |
| 138 | + - service: light.turn_off |
| 139 | + target: |
| 140 | + area_id: office |
| 141 | +``` |
| 142 | +
|
| 143 | +--- |
| 144 | +
|
| 145 | +## Time-Based Actions (Planned) |
| 146 | +
|
| 147 | +Area automations will support different actions based on time of day using the [Home Time Modes](../packages/home_time_modes.md) package: |
| 148 | +
|
| 149 | +| Time Mode | Typical Use | |
| 150 | +|-----------|-------------| |
| 151 | +| `Morning` | Bright, energizing lights | |
| 152 | +| `Day` | Full brightness, productivity focus | |
| 153 | +| `Evening` | Warm, relaxed lighting | |
| 154 | +| `Night` | Minimal lighting, sleep-friendly | |
| 155 | + |
| 156 | +### Example Configuration |
| 157 | + |
| 158 | +```yaml |
| 159 | +occupied: |
| 160 | + - when: [morning, evening] |
| 161 | + action: turn_on |
| 162 | + scene: cozy |
| 163 | + - when: [day] |
| 164 | + action: turn_on |
| 165 | + scene: bright |
| 166 | + - when: [night] |
| 167 | + action: turn_on |
| 168 | + scene: dim |
| 169 | +
|
| 170 | +absence: |
| 171 | + - when: [always] |
| 172 | + action: turn_off |
| 173 | +``` |
| 174 | + |
| 175 | +--- |
| 176 | + |
| 177 | +## Related Documentation |
| 178 | + |
| 179 | +- [Area Manager Package](../packages/area_manager.md) — Technical YAML configuration |
| 180 | +- [Home Time Modes](../packages/home_time_modes.md) — Time-of-day scheduling |
| 181 | +- [Area Occupancy Sensor](area-occupancy-sensor.md) — Physical presence sensors |
0 commit comments