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.Home Assistant instance
Entity IDs to track (automatically lowercased)
Callback function to execute when state changes
Job type for the callback
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.Home Assistant instance
Entity IDs to track
Callback function to execute
Job type for the callback
async_track_point_in_time
Add a listener that fires once at or after a specific point in time.Home Assistant instance
Callback to execute (passed the time it fires in local time)
Point in time to fire the callback
async_track_template_result
Add a listener that fires when the result of a template changes.Home Assistant instance
List of templates to track
Callback to call with results
When True, raise on undefined variables
Optional custom logging function for template errors
When True, first template blocks rendering of others if it doesn’t render as True
Object used to unregister the listener and refresh the template
Data Classes
TrackStates
Class for keeping track of states being tracked.Whether all states on the system are being tracked
Lowercased entities to track
Lowercased domains to track
TrackTemplate
Class for keeping track of a template with variables.Template to calculate
Variables to pass to the template
Rate limit on how often the template is re-rendered
TrackTemplateResult
Class for result of template tracking.The template that has changed
Output from the template on the last successful run (None if no previous run)
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.Home Assistant instance
Entity IDs to track (must be lowercase)
Callback function
Job type for the callback
async_track_device_registry_updated_event
Track specific device registry updated events indexed by device_id.Home Assistant instance
Device IDs to track
Callback function
Job type for the callback
Constants
RANDOM_MICROSECOND_MIN = 50000- Minimum microseconds for spreading listenersRANDOM_MICROSECOND_MAX = 500000- Maximum microseconds for spreading listenersEVENT_STATE_CHANGED- Event type for state changesEVENT_STATE_REPORTED- Event type for state reports (update without change)