Skip to content
Jan Seidl edited this page Oct 11, 2021 · 3 revisions

The design of Magic Areas is largely based on features listening to an area's state change. On versions prior to 3.0.0 we used to track entities directly from the features but we steered away from that design as it's not as efficient as using an event-based approach.

Every state change of either a primary (presence) or secondary state triggers an Magic Areas-specific event which our features listens to. This approach offloads state-tracking from the feature and allows multiple features to trap an event without having to add their trackers to entities. From a development perspective, this also simplifies the code and allows for quicker development.

As a result, you can also listen for these events on your automations if want to!

Current events fired by Magic Areas are:

  • EVENT_MAGICAREAS_STARTED: Magic Areas fully loaded
  • EVENT_MAGICAREAS_READY: All areas are ready but features are not yet loaded (used internally to know when to load features)
  • EVENT_MAGICAREAS_AREA_STATE_CHANGED : When presence or secondary_states state changes