> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/home-assistant/core/llms.txt
> Use this file to discover all available pages before exploring further.

# Event Helpers

> Helper functions for listening to and tracking events in Home Assistant.

The `homeassistant.helpers.event` module provides utilities for listening to events, tracking state changes, and managing time-based operations.

## Key Functions

### async\_track\_state\_change\_event

Track specific state change events indexed by entity\_id.

<ParamField path="hass" type="HomeAssistant" required>
  Home Assistant instance
</ParamField>

<ParamField path="entity_ids" type="str | Iterable[str]" required>
  Entity IDs to track (automatically lowercased)
</ParamField>

<ParamField path="action" type="Callable[[Event[EventStateChangedData]], Any]" required>
  Callback function to execute when state changes
</ParamField>

<ParamField path="job_type" type="HassJobType | None" default="None">
  Job type for the callback
</ParamField>

<ResponseField name="return" type="CALLBACK_TYPE">
  Function to call to remove the listener
</ResponseField>

```python theme={null}
from homeassistant.helpers.event import async_track_state_change_event

def my_callback(event):
    print(f"State changed: {event.data['entity_id']}")

remove_listener = async_track_state_change_event(
    hass,
    ["light.living_room", "light.bedroom"],
    my_callback
)
```

### async\_track\_state\_report\_event

Track EVENT\_STATE\_REPORTED by entity\_ids. This fires when state is updated but not changed.

<ParamField path="hass" type="HomeAssistant" required>
  Home Assistant instance
</ParamField>

<ParamField path="entity_ids" type="str | Iterable[str]" required>
  Entity IDs to track
</ParamField>

<ParamField path="action" type="Callable[[Event[EventStateReportedData]], Any]" required>
  Callback function to execute
</ParamField>

<ParamField path="job_type" type="HassJobType | None" default="None">
  Job type for the callback
</ParamField>

### async\_track\_point\_in\_time

Add a listener that fires once at or after a specific point in time.

<ParamField path="hass" type="HomeAssistant" required>
  Home Assistant instance
</ParamField>

<ParamField path="action" type="HassJob[[datetime], Coroutine] | Callable[[datetime], Coroutine]" required>
  Callback to execute (passed the time it fires in local time)
</ParamField>

<ParamField path="point_in_time" type="datetime" required>
  Point in time to fire the callback
</ParamField>

### async\_track\_template\_result

Add a listener that fires when the result of a template changes.

<ParamField path="hass" type="HomeAssistant" required>
  Home Assistant instance
</ParamField>

<ParamField path="track_templates" type="Sequence[TrackTemplate]" required>
  List of templates to track
</ParamField>

<ParamField path="action" type="TrackTemplateResultListener" required>
  Callback to call with results
</ParamField>

<ParamField path="strict" type="bool" default="False">
  When True, raise on undefined variables
</ParamField>

<ParamField path="log_fn" type="Callable[[int, str], None] | None" default="None">
  Optional custom logging function for template errors
</ParamField>

<ParamField path="has_super_template" type="bool" default="False">
  When True, first template blocks rendering of others if it doesn't render as True
</ParamField>

<ResponseField name="return" type="TrackTemplateResultInfo">
  Object used to unregister the listener and refresh the template
</ResponseField>

## Data Classes

### TrackStates

Class for keeping track of states being tracked.

<ParamField path="all_states" type="bool">
  Whether all states on the system are being tracked
</ParamField>

<ParamField path="entities" type="set[str]">
  Lowercased entities to track
</ParamField>

<ParamField path="domains" type="set[str]">
  Lowercased domains to track
</ParamField>

### TrackTemplate

Class for keeping track of a template with variables.

<ParamField path="template" type="Template">
  Template to calculate
</ParamField>

<ParamField path="variables" type="TemplateVarsType">
  Variables to pass to the template
</ParamField>

<ParamField path="rate_limit" type="float | None" default="None">
  Rate limit on how often the template is re-rendered
</ParamField>

### TrackTemplateResult

Class for result of template tracking.

<ParamField path="template" type="Template">
  The template that has changed
</ParamField>

<ParamField path="last_result" type="Any">
  Output from the template on the last successful run (None if no previous run)
</ParamField>

<ParamField path="result" type="Any">
  Result from the template run (string or TemplateError if template errored)
</ParamField>

## Device and Entity Registry Tracking

### async\_track\_entity\_registry\_updated\_event

Track specific entity registry updated events indexed by entity\_id.

<ParamField path="hass" type="HomeAssistant" required>
  Home Assistant instance
</ParamField>

<ParamField path="entity_ids" type="str | Iterable[str]" required>
  Entity IDs to track (must be lowercase)
</ParamField>

<ParamField path="action" type="Callable[[Event[EventEntityRegistryUpdatedData]], Any]" required>
  Callback function
</ParamField>

<ParamField path="job_type" type="HassJobType | None" default="None">
  Job type for the callback
</ParamField>

### async\_track\_device\_registry\_updated\_event

Track specific device registry updated events indexed by device\_id.

<ParamField path="hass" type="HomeAssistant" required>
  Home Assistant instance
</ParamField>

<ParamField path="device_ids" type="str | Iterable[str]" required>
  Device IDs to track
</ParamField>

<ParamField path="action" type="Callable[[Event[EventDeviceRegistryUpdatedData]], Any]" required>
  Callback function
</ParamField>

<ParamField path="job_type" type="HassJobType | None" default="None">
  Job type for the callback
</ParamField>

## Constants

* `RANDOM_MICROSECOND_MIN = 50000` - Minimum microseconds for spreading listeners
* `RANDOM_MICROSECOND_MAX = 500000` - Maximum microseconds for spreading listeners
* `EVENT_STATE_CHANGED` - Event type for state changes
* `EVENT_STATE_REPORTED` - Event type for state reports (update without change)
