Magic Areas Documentation

repository·main·Indexed 19 days ago

https://github.com/jseidl/magic-areas

A Home Assistant custom integration that adds intelligent presence tracking to Areas. It transforms standard areas into presence-aware zones using motion sensors, media players, device trackers, and BLE beacons. Key features include secondary states (dark, sleep, extended, accented), Meta-Areas for hierarchical grouping (Interior, Exterior, Floors), smart light and fan groups, and automated sensor aggregation by device class and unit of measurement.

Tokens
18.4K
Snippets
23
Records
97
Agent score
59%

What's inside Magic Areas

  1. Overview of Magic Areas features

    main

    Magic Areas transforms standard Home Assistant Areas into presence-aware zones. Key capabilities include:

    • Presence Detection: Uses motion sensors, media players, device trackers, and BLE beacons to track room occupancy.
    • Smart Groups: Automatically creates groups for lights (overhead, task, accent, sleep), fans, and climate devices.
    • Secondary States: Provides nuanced context like dark/bright, sleep, extended (long-term occupancy), and accented (media-based presence).
    • Meta-Areas: Allows grouping areas into hierarchies like interior, exterior, or specific floors to track presence across multiple rooms.
    • Sensor Aggregation: Automatically aggregates sensors by device_class and unit_of_measurement, and provides a Health Sensor for safety-related classes (gas, smoke, moisture, problem, safety).
  2. Overview of Magic Areas for Home Assistant

    main
    Magic Areas is a Home Assistant custom integration that provides context-aware, state-driven automation. Instead of manual entity configuration, it uses areas, meta-areas, and presence sensing to create intelligent, presence-aware zones. It automatically detects when occupants are in a room using existing sensors (motion, occupancy, etc.) and manages smart groups like lights, fans, and climate devices through a clean UI.
  3. What is Presence Hold and how to use it

    main

    The Presence Hold feature provides a dedicated switch for a specific area that acts as a manual override for presence detection.

    When the Presence Hold switch is turned on, the area's presence state is forced to occupied, overriding all other configured presence sensors and logic. When the switch is off, the area reverts to normal presence detection behavior based on your existing sensors.

    Common use cases include:

    • Manually marking a room as occupied when sensors fail to detect someone (e.g., guests or pets).
    • Temporarily keeping an area "occupied" for testing automations.
    • Overriding presence during maintenance or cleaning.
  4. Understand Light Groups in Magic Areas

    main

    The Light Groups feature organizes and automates lights based on their purpose and the current state of an area.

    At its core, Magic Areas automatically creates a Home Assistant light.group for every area containing light entities. You can further classify these lights into predefined groups to enable smarter, context-aware automation:

    • Overhead Lights: Main ceiling lights for general illumination.
    • Accent Lights: Decorative or highlight lighting (e.g., under cabinets, wall sconces).
    • Task Lights: Focused lights for workspaces, desks, or reading.
    • Sleep Lights: Dim lighting suitable for nighttime or bedtime use.

    Each populated group automatically receives a dedicated light.group entity in Home Assistant. To enable the automation logic for these groups, you must turn on the Light Control ($Area) switch created by Magic Areas.

  5. Core concepts in Magic Areas

    main

    Magic Areas is built upon three fundamental pillars:

    • Presence Sensing: Detecting occupancy in an area using various sources like motion sensors, media players, device trackers, or BLE beacons.
    • Area States: The state of an area (e.g., occupied vs. empty) which drives automations.
    • Meta-Areas: Higher-level groupings (e.g., 'Interior', 'Exterior', 'Global', 'Floors') used to coordinate multiple areas simultaneously.
  6. How Aggregation works in Magic Areas

    main

    The Aggregation feature automatically creates aggregate sensors for all sensor and binary_sensor entities within a specific area. Entities are grouped together based on their device_class and unit_of_measurement tuple.

    Entity Naming Convention

    Aggregate entities follow a predictable template:

    • Binary Sensors: binary_sensor.magic_areas_aggregates_{area}_aggregate_{device_class}
    • Sensors: sensor.magic_areas_aggregates_{area}_aggregate_{device_class}

    If multiple unit_of_measurement values exist for the same device_class, a suffix is appended: _{unit_of_measurement}.

    Aggregation Logic

    • Binary Sensors: The aggregate state is on if any underlying entity is on (OR logic).
    • Sensors: Values are averaged, with the exception of power, current, and energy, which are summed.
    (binary_?)sensor.magic_areas_aggregates_{area}_aggregate_{device_class}
  7. How Wasp-in-a-Box improves presence detection

    main

    The Wasp in a Box 🐝📦 feature adds contextual logic to motion-based sensors by using an associated door or entry sensor (the "box"). This prevents false clears when a motion sensor times out after you have already left a room, or when a door is closed while motion is still active.

    The Logic:

    1. Wasp detected: If a motion sensor triggers, a "wasp" is assumed to be in the box.
    2. Box closed: If the door/garage closes while motion is active, the wasp is assumed to stay inside.
    3. Inactivity: If the box remains closed and motion stops, the wasp is assumed to still be inside.
    4. Box opened: If the door opens and no motion is detected, the wasp is assumed to be gone.

    This is particularly useful for enclosed spaces like bathrooms, bedrooms, offices, garages, and laundry rooms.

  8. How Area States work in Magic Areas

    main

    Magic Areas goes beyond simple binary presence (occupied/clear) by tracking secondary states. These states provide environmental context for an area, allowing automations to behave differently based on the time of day or activity level.

    Common secondary states include:

    • dark
    • sleep
    • extended

    Developers can use these states to create context-aware automations, such as adjusting lighting brightness or color temperature when an area enters a dark or sleep state.

  9. How presence sensing works in Magic Areas

    main

    Magic Areas determines if an area is occupied or clear by monitoring presence-related events from specific Home Assistant entity types. It interprets the states and device_class values of these entities to automate area state changes without requiring manual configuration for most standard sensors.

    Core Logic Examples:

    • media_player (and remote): If the state is playing in an area $\rightarrow$ area is occupied.
    • device_tracker: If the state is home $\rightarrow$ area is occupied.
    • binary_sensor: If the state is on $\rightarrow$ area is occupied.
  10. Use 'Keep-only sensors' to reduce false positives

    main

    Magic Areas' core strength is stacking multiple presence sources. To handle 'flappy' or unreliable sensors (like BLE trackers that jump between rooms or mmWave sensors that trigger on moving curtains), use the 'Keep-only sensors' functionality.

    Recommended Strategy:

    • Use high-reliability sensors (mmWave, BLE, or 'Wasp in a box') as your primary sources.
    • Add unreliable or slow sensors (like BLE trackers) to the 'keep-only sensors' list. This allows them to maintain presence state without causing the 'flapping' behavior typical of these devices.