Skip to main content
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.
HomeAssistant
required
Home Assistant instance
str | Iterable[str]
required
Entity IDs to track (automatically lowercased)
Callable[[Event[EventStateChangedData]], Any]
required
Callback function to execute when state changes
HassJobType | None
default:"None"
Job type for the callback
CALLBACK_TYPE
Function to call to remove the listener

async_track_state_report_event

Track EVENT_STATE_REPORTED by entity_ids. This fires when state is updated but not changed.
HomeAssistant
required
Home Assistant instance
str | Iterable[str]
required
Entity IDs to track
Callable[[Event[EventStateReportedData]], Any]
required
Callback function to execute
HassJobType | None
default:"None"
Job type for the callback

async_track_point_in_time

Add a listener that fires once at or after a specific point in time.
HomeAssistant
required
Home Assistant instance
HassJob[[datetime], Coroutine] | Callable[[datetime], Coroutine]
required
Callback to execute (passed the time it fires in local time)
datetime
required
Point in time to fire the callback

async_track_template_result

Add a listener that fires when the result of a template changes.
HomeAssistant
required
Home Assistant instance
Sequence[TrackTemplate]
required
List of templates to track
TrackTemplateResultListener
required
Callback to call with results
bool
default:"False"
When True, raise on undefined variables
Callable[[int, str], None] | None
default:"None"
Optional custom logging function for template errors
bool
default:"False"
When True, first template blocks rendering of others if it doesn’t render as True
TrackTemplateResultInfo
Object used to unregister the listener and refresh the template

Data Classes

TrackStates

Class for keeping track of states being tracked.
bool
Whether all states on the system are being tracked
set[str]
Lowercased entities to track
set[str]
Lowercased domains to track

TrackTemplate

Class for keeping track of a template with variables.
Template
Template to calculate
TemplateVarsType
Variables to pass to the template
float | None
default:"None"
Rate limit on how often the template is re-rendered

TrackTemplateResult

Class for result of template tracking.
Template
The template that has changed
Any
Output from the template on the last successful run (None if no previous run)
Any
Result from the template run (string or TemplateError if template errored)

Device and Entity Registry Tracking

async_track_entity_registry_updated_event

Track specific entity registry updated events indexed by entity_id.
HomeAssistant
required
Home Assistant instance
str | Iterable[str]
required
Entity IDs to track (must be lowercase)
Callable[[Event[EventEntityRegistryUpdatedData]], Any]
required
Callback function
HassJobType | None
default:"None"
Job type for the callback

async_track_device_registry_updated_event

Track specific device registry updated events indexed by device_id.
HomeAssistant
required
Home Assistant instance
str | Iterable[str]
required
Device IDs to track
Callable[[Event[EventDeviceRegistryUpdatedData]], Any]
required
Callback function
HassJobType | None
default:"None"
Job type for the callback

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)