Home Assistant Unofficial Reference 2024.12.1
homeassistant.helpers.event Namespace Reference

Classes

class  _KeyedEventData
 
class  _KeyedEventTracker
 
class  _TrackPointUTCTime
 
class  _TrackStateChangeFiltered
 
class  _TrackTimeInterval
 
class  _TrackUTCTimeChange
 
class  SunListener
 
class  TrackStates
 
class  TrackTemplate
 
class  TrackTemplateResult
 
class  TrackTemplateResultInfo
 

Functions

bool _async_device_registry_updated_filter (HomeAssistant hass, dict[str, list[HassJob[[Event[EventDeviceRegistryUpdatedData]], Any]]] callbacks, EventDeviceRegistryUpdatedData event_data)
 
None _async_dispatch_device_id_event (HomeAssistant hass, dict[str, list[HassJob[[Event[EventDeviceRegistryUpdatedData]], Any]]] callbacks, Event[EventDeviceRegistryUpdatedData] event)
 
None _async_dispatch_domain_event (HomeAssistant hass, dict[str, list[HassJob[[Event[EventStateChangedData]], Any]]] callbacks, Event[EventStateChangedData] event)
 
None _async_dispatch_entity_id_event (HomeAssistant hass, dict[str, list[HassJob[[Event[_StateEventDataT]], Any]]] callbacks, Event[_StateEventDataT] event)
 
None _async_dispatch_entity_id_event_soon (HomeAssistant hass, dict[str, list[HassJob[[Event[_StateEventDataT]], Any]]] callbacks, Event[_StateEventDataT] event)
 
None _async_dispatch_old_entity_id_or_entity_id_event (HomeAssistant hass, dict[str, list[HassJob[[Event[EventEntityRegistryUpdatedData]], Any]]] callbacks, Event[EventEntityRegistryUpdatedData] event)
 
bool _async_domain_added_filter (HomeAssistant hass, dict[str, list[HassJob[[Event[EventStateChangedData]], Any]]] callbacks, EventStateChangedData event_data)
 
bool _async_domain_removed_filter (HomeAssistant hass, dict[str, list[HassJob[[Event[EventStateChangedData]], Any]]] callbacks, EventStateChangedData event_data)
 
bool _async_entity_registry_updated_filter (HomeAssistant hass, dict[str, list[HassJob[[Event[EventEntityRegistryUpdatedData]], Any]]] callbacks, EventEntityRegistryUpdatedData event_data)
 
bool _async_state_filter (HomeAssistant hass, dict[str, list[HassJob[[Event[_StateEventDataT]], Any]]] callbacks, _StateEventDataT event_data)
 
list[str] _async_string_to_lower_list (str|Iterable[str] instr)
 
CALLBACK_TYPE _async_track_event (_KeyedEventTracker[_TypedDictT] tracker, HomeAssistant hass, str|Iterable[str] keys, Callable[[Event[_TypedDictT]], None] action, HassJobType|None job_type)
 
CALLBACK_TYPE _async_track_state_added_domain (HomeAssistant hass, str|Iterable[str] domains, Callable[[Event[EventStateChangedData]], Any] action, HassJobType|None job_type)
 
CALLBACK_TYPE _async_track_state_change_event (HomeAssistant hass, str|Iterable[str] entity_ids, Callable[[Event[EventStateChangedData]], Any] action, HassJobType|None job_type)
 
tuple[set[str], set[str]] _entities_domains_from_render_infos (Iterable[RenderInfo] render_infos)
 
bool _event_triggers_rerender (Event[EventStateChangedData] event, RenderInfo info)
 
Callable[Concatenate[HomeAssistant, _P], CALLBACK_TYPE] _P (Callable[Concatenate[HomeAssistant, _P], Any] async_factory)
 
float|None _rate_limit_for_event (Event[EventStateChangedData] event, RenderInfo info, TrackTemplate track_template_)
 
None _remove_empty_listener ()
 
None _remove_listener (HomeAssistant hass, _KeyedEventTracker[_TypedDictT] tracker, Iterable[str] keys, HassJob[[Event[_TypedDictT]], Any] job, dict[str, list[HassJob[[Event[_TypedDictT]], Any]]] callbacks)
 
bool _render_infos_needs_all_listener (Iterable[RenderInfo] render_infos)
 
TrackStates _render_infos_to_track_states (Iterable[RenderInfo] render_infos)
 
None _run_async_call_action (HomeAssistant hass, HassJob[[datetime], Coroutine[Any, Any, None]|None] job)
 
RenderInfo _suppress_domain_all_in_render_info (RenderInfo render_info)
 
CALLBACK_TYPE async_call_at (HomeAssistant hass, HassJob[[datetime], Coroutine[Any, Any, None]|None]|Callable[[datetime], Coroutine[Any, Any, None]|None] action, float loop_time)
 
CALLBACK_TYPE async_call_later (HomeAssistant hass, float|timedelta delay, HassJob[[datetime], Coroutine[Any, Any, None]|None]|Callable[[datetime], Coroutine[Any, Any, None]|None] action)
 
CALLBACK_TYPE async_track_device_registry_updated_event (HomeAssistant hass, str|Iterable[str] device_ids, Callable[[Event[EventDeviceRegistryUpdatedData]], Any] action, HassJobType|None job_type=None)
 
CALLBACK_TYPE async_track_entity_registry_updated_event (HomeAssistant hass, str|Iterable[str] entity_ids, Callable[[Event[EventEntityRegistryUpdatedData]], Any] action, HassJobType|None job_type=None)
 
CALLBACK_TYPE async_track_point_in_time (HomeAssistant hass, HassJob[[datetime], Coroutine[Any, Any, None]|None]|Callable[[datetime], Coroutine[Any, Any, None]|None] action, datetime point_in_time)
 
CALLBACK_TYPE async_track_point_in_utc_time (HomeAssistant hass, HassJob[[datetime], Coroutine[Any, Any, None]|None]|Callable[[datetime], Coroutine[Any, Any, None]|None] action, datetime point_in_time)
 
CALLBACK_TYPE async_track_same_state (HomeAssistant hass, timedelta period, Callable[[], Coroutine[Any, Any, None]|None] action, Callable[[str, State|None, State|None], bool] async_check_same_func, str|Iterable[str] entity_ids=MATCH_ALL)
 
CALLBACK_TYPE async_track_state_added_domain (HomeAssistant hass, str|Iterable[str] domains, Callable[[Event[EventStateChangedData]], Any] action, HassJobType|None job_type=None)
 
CALLBACK_TYPE async_track_state_change (HomeAssistant hass, str|Iterable[str] entity_ids, Callable[[str, State|None, State|None], Coroutine[Any, Any, None]|None] action, str|Iterable[str]|None from_state=None, str|Iterable[str]|None to_state=None)
 
CALLBACK_TYPE async_track_state_change_event (HomeAssistant hass, str|Iterable[str] entity_ids, Callable[[Event[EventStateChangedData]], Any] action, HassJobType|None job_type=None)
 
_TrackStateChangeFiltered async_track_state_change_filtered (HomeAssistant hass, TrackStates track_states, Callable[[Event[EventStateChangedData]], Any] action)
 
CALLBACK_TYPE async_track_state_removed_domain (HomeAssistant hass, str|Iterable[str] domains, Callable[[Event[EventStateChangedData]], Any] action, HassJobType|None job_type=None)
 
CALLBACK_TYPE async_track_state_report_event (HomeAssistant hass, str|Iterable[str] entity_ids, Callable[[Event[EventStateReportedData]], Any] action, HassJobType|None job_type=None)
 
CALLBACK_TYPE async_track_sunrise (HomeAssistant hass, Callable[[], None] action, timedelta|None offset=None)
 
CALLBACK_TYPE async_track_sunset (HomeAssistant hass, Callable[[], None] action, timedelta|None offset=None)
 
CALLBACK_TYPE async_track_template (HomeAssistant hass, Template template, Callable[[str, State|None, State|None], Coroutine[Any, Any, None]|None] action, TemplateVarsType|None variables=None)
 
TrackTemplateResultInfo async_track_template_result (HomeAssistant hass, Sequence[TrackTemplate] track_templates, TrackTemplateResultListener action, bool strict=False, Callable[[int, str], None]|None log_fn=None, bool has_super_template=False)
 
CALLBACK_TYPE async_track_time_change (HomeAssistant hass, Callable[[datetime], Coroutine[Any, Any, None]|None] action, Any|None hour=None, Any|None minute=None, Any|None second=None)
 
CALLBACK_TYPE async_track_time_interval (HomeAssistant hass, Callable[[datetime], Coroutine[Any, Any, None]|None] action, timedelta interval, *str|None name=None, bool|None cancel_on_shutdown=None)
 
CALLBACK_TYPE async_track_utc_time_change (HomeAssistant hass, Callable[[datetime], Coroutine[Any, Any, None]|None] action, Any|None hour=None, Any|None minute=None, Any|None second=None, bool local=False)
 
Callable[[str|None], bool] process_state_match (str|Iterable[str]|None parameter, bool invert=False)
 

Variables

 _ALL_LISTENER
 
 _DOMAINS_LISTENER
 
 _ENTITIES_LISTENER
 
 _KEYED_TRACK_DEVICE_REGISTRY_UPDATED
 
 _KEYED_TRACK_ENTITY_REGISTRY_UPDATED
 
 _KEYED_TRACK_STATE_ADDED_DOMAIN
 
 _KEYED_TRACK_STATE_CHANGE
 
 _KEYED_TRACK_STATE_REMOVED_DOMAIN
 
 _KEYED_TRACK_STATE_REPORT
 
 _LOGGER
 
 _StateEventDataT
 
 _TypedDictT
 
 bound
 
 call_later
 
None dispatcher_callable = _async_dispatch_entity_id_event_soon,
 
 event_type = EVENT_STATE_CHANGED,
 
bool filter_callable = _async_state_filter,
 
 key = _TRACK_STATE_CHANGE_DATA,
 
 RANDOM_MICROSECOND_MAX
 
 RANDOM_MICROSECOND_MIN
 
 time_tracker_timestamp
 
 time_tracker_utcnow
 
 track_point_in_time
 
 track_point_in_utc_time
 
 track_same_state
 
 track_state_change
 
 track_sunrise
 
 track_sunset
 
 track_template
 
 track_time_change
 
 track_time_interval
 
 track_utc_time_change
 
 TrackTemplateResultListener
 

Detailed Description

Helpers for listening to events.

Function Documentation

◆ _async_device_registry_updated_filter()

bool homeassistant.helpers.event._async_device_registry_updated_filter ( HomeAssistant  hass,
dict[str, list[HassJob[[Event[EventDeviceRegistryUpdatedData]], Any]]]  callbacks,
EventDeviceRegistryUpdatedData  event_data 
)
private
Filter device registry updates by device_id.

Definition at line 556 of file event.py.

◆ _async_dispatch_device_id_event()

None homeassistant.helpers.event._async_dispatch_device_id_event ( HomeAssistant  hass,
dict[str, list[HassJob[[Event[EventDeviceRegistryUpdatedData]], Any]]]  callbacks,
Event[EventDeviceRegistryUpdatedData]  event 
)
private
Dispatch to listeners.

Definition at line 566 of file event.py.

◆ _async_dispatch_domain_event()

None homeassistant.helpers.event._async_dispatch_domain_event ( HomeAssistant  hass,
dict[str, list[HassJob[[Event[EventStateChangedData]], Any]]]  callbacks,
Event[EventStateChangedData]  event 
)
private
Dispatch domain event listeners.

Definition at line 610 of file event.py.

◆ _async_dispatch_entity_id_event()

None homeassistant.helpers.event._async_dispatch_entity_id_event ( HomeAssistant  hass,
dict[str, list[HassJob[[Event[_StateEventDataT]], Any]]]  callbacks,
Event[_StateEventDataT event 
)
private
Dispatch to listeners.

Definition at line 346 of file event.py.

◆ _async_dispatch_entity_id_event_soon()

None homeassistant.helpers.event._async_dispatch_entity_id_event_soon ( HomeAssistant  hass,
dict[str, list[HassJob[[Event[_StateEventDataT]], Any]]]  callbacks,
Event[_StateEventDataT event 
)
private
Dispatch to listeners soon to ensure one event loop runs before dispatch.

Definition at line 336 of file event.py.

◆ _async_dispatch_old_entity_id_or_entity_id_event()

None homeassistant.helpers.event._async_dispatch_old_entity_id_or_entity_id_event ( HomeAssistant  hass,
dict[str, list[HassJob[[Event[EventEntityRegistryUpdatedData]], Any]]]  callbacks,
Event[EventEntityRegistryUpdatedData]  event 
)
private
Dispatch to listeners.

Definition at line 495 of file event.py.

◆ _async_domain_added_filter()

bool homeassistant.helpers.event._async_domain_added_filter ( HomeAssistant  hass,
dict[str, list[HassJob[[Event[EventStateChangedData]], Any]]]  callbacks,
EventStateChangedData  event_data 
)
private
Filter state changes by entity_id.

Definition at line 627 of file event.py.

◆ _async_domain_removed_filter()

bool homeassistant.helpers.event._async_domain_removed_filter ( HomeAssistant  hass,
dict[str, list[HassJob[[Event[EventStateChangedData]], Any]]]  callbacks,
EventStateChangedData  event_data 
)
private
Filter state changes by entity_id.

Definition at line 677 of file event.py.

◆ _async_entity_registry_updated_filter()

bool homeassistant.helpers.event._async_entity_registry_updated_filter ( HomeAssistant  hass,
dict[str, list[HassJob[[Event[EventEntityRegistryUpdatedData]], Any]]]  callbacks,
EventEntityRegistryUpdatedData  event_data 
)
private
Filter entity registry updates by entity_id.

Definition at line 519 of file event.py.

◆ _async_state_filter()

bool homeassistant.helpers.event._async_state_filter ( HomeAssistant  hass,
dict[str, list[HassJob[[Event[_StateEventDataT]], Any]]]  callbacks,
_StateEventDataT  event_data 
)
private
Filter state changes by entity_id.

Definition at line 366 of file event.py.

◆ _async_string_to_lower_list()

list[str] homeassistant.helpers.event._async_string_to_lower_list ( str | Iterable[str]  instr)
private

Definition at line 714 of file event.py.

◆ _async_track_event()

CALLBACK_TYPE homeassistant.helpers.event._async_track_event ( _KeyedEventTracker[_TypedDictT tracker,
HomeAssistant  hass,
str | Iterable[str]  keys,
Callable[[Event[_TypedDictT]], None]  action,
HassJobType | None  job_type 
)
private
Track an event by a specific key.

This function is intended for internal use only.

Definition at line 448 of file event.py.

◆ _async_track_state_added_domain()

CALLBACK_TYPE homeassistant.helpers.event._async_track_state_added_domain ( HomeAssistant  hass,
str | Iterable[str]  domains,
Callable[[Event[EventStateChangedData]], Any]  action,
HassJobType | None  job_type 
)
private
Track state change events when an entity is added to domains.

Definition at line 664 of file event.py.

◆ _async_track_state_change_event()

CALLBACK_TYPE homeassistant.helpers.event._async_track_state_change_event ( HomeAssistant  hass,
str | Iterable[str]  entity_ids,
Callable[[Event[EventStateChangedData]], Any]  action,
HassJobType | None  job_type 
)
private
Faster version of async_track_state_change_event.

The passed in entity_ids will not be automatically lower cased.

Definition at line 384 of file event.py.

◆ _entities_domains_from_render_infos()

tuple[set[str], set[str]] homeassistant.helpers.event._entities_domains_from_render_infos ( Iterable[RenderInfo render_infos)
private
Combine from multiple RenderInfo.

Definition at line 1930 of file event.py.

◆ _event_triggers_rerender()

bool homeassistant.helpers.event._event_triggers_rerender ( Event[EventStateChangedData]  event,
RenderInfo   info 
)
private
Determine if a template should be re-rendered from an event.

Definition at line 1968 of file event.py.

◆ _P()

Callable[Concatenate[HomeAssistant, _P], CALLBACK_TYPE] homeassistant.helpers.event._P ( Callable[Concatenate[HomeAssistant, _P], Any]  async_factory)
private
Convert an async event helper to a threaded one.

Definition at line 175 of file event.py.

◆ _rate_limit_for_event()

float | None homeassistant.helpers.event._rate_limit_for_event ( Event[EventStateChangedData]  event,
RenderInfo  info,
TrackTemplate  track_template_ 
)
private
Determine the rate limit for an event.

Definition at line 1984 of file event.py.

◆ _remove_empty_listener()

None homeassistant.helpers.event._remove_empty_listener ( )
private
Remove a listener that does nothing.

Definition at line 424 of file event.py.

◆ _remove_listener()

None homeassistant.helpers.event._remove_listener ( HomeAssistant  hass,
_KeyedEventTracker[_TypedDictT tracker,
Iterable[str]  keys,
HassJob[[Event[_TypedDictT]], Any]  job,
dict[str, list[HassJob[[Event[_TypedDictT]], Any]]]  callbacks 
)
private
Remove listener.

Definition at line 429 of file event.py.

◆ _render_infos_needs_all_listener()

bool homeassistant.helpers.event._render_infos_needs_all_listener ( Iterable[RenderInfo render_infos)
private
Determine if an all listener is needed from RenderInfo.

Definition at line 1948 of file event.py.

◆ _render_infos_to_track_states()

TrackStates homeassistant.helpers.event._render_infos_to_track_states ( Iterable[RenderInfo render_infos)
private
Create a TrackStates dataclass from the latest RenderInfo.

Definition at line 1959 of file event.py.

◆ _run_async_call_action()

None homeassistant.helpers.event._run_async_call_action ( HomeAssistant  hass,
HassJob[[datetime], Coroutine[Any, Any, None] | None]   job 
)
private
Run action.

Definition at line 1563 of file event.py.

◆ _suppress_domain_all_in_render_info()

RenderInfo homeassistant.helpers.event._suppress_domain_all_in_render_info ( RenderInfo  render_info)
private
Remove the domains and all_states from render info during a ratelimit.

Definition at line 2002 of file event.py.

◆ async_call_at()

CALLBACK_TYPE homeassistant.helpers.event.async_call_at ( HomeAssistant  hass,
HassJob[[datetime], Coroutine[Any, Any, None] | None] | Callable[[datetime], Coroutine[Any, Any, None] | None]  action,
float  loop_time 
)
Add a listener that fires at or after <loop_time>.

The listener is passed the time it fires in UTC time.

Definition at line 1572 of file event.py.

◆ async_call_later()

CALLBACK_TYPE homeassistant.helpers.event.async_call_later ( HomeAssistant  hass,
float | timedelta  delay,
HassJob[[datetime], Coroutine[Any, Any, None] | None] | Callable[[datetime], Coroutine[Any, Any, None] | None]  action 
)
Add a listener that fires at or after <delay>.

The listener is passed the time it fires in UTC time.

Definition at line 1592 of file event.py.

◆ async_track_device_registry_updated_event()

CALLBACK_TYPE homeassistant.helpers.event.async_track_device_registry_updated_event ( HomeAssistant  hass,
str | Iterable[str]  device_ids,
Callable[[Event[EventDeviceRegistryUpdatedData]], Any]  action,
HassJobType | None   job_type = None 
)
Track specific device registry updated events indexed by device_id.

Similar to async_track_entity_registry_updated_event.

Definition at line 594 of file event.py.

◆ async_track_entity_registry_updated_event()

CALLBACK_TYPE homeassistant.helpers.event.async_track_entity_registry_updated_event ( HomeAssistant  hass,
str | Iterable[str]  entity_ids,
Callable[[Event[EventEntityRegistryUpdatedData]], Any]  action,
HassJobType | None   job_type = None 
)
Track specific entity registry updated events indexed by entity_id.

Entities must be lower case.

Similar to async_track_state_change_event.

Definition at line 538 of file event.py.

◆ async_track_point_in_time()

CALLBACK_TYPE homeassistant.helpers.event.async_track_point_in_time ( HomeAssistant  hass,
HassJob[[datetime], Coroutine[Any, Any, None] | None] | Callable[[datetime], Coroutine[Any, Any, None] | None]  action,
datetime  point_in_time 
)
Add a listener that fires once at or after a specific point in time.

The listener is passed the time it fires in local time.

Definition at line 1457 of file event.py.

◆ async_track_point_in_utc_time()

CALLBACK_TYPE homeassistant.helpers.event.async_track_point_in_utc_time ( HomeAssistant  hass,
HassJob[[datetime], Coroutine[Any, Any, None] | None] | Callable[[datetime], Coroutine[Any, Any, None] | None]  action,
datetime  point_in_time 
)
Add a listener that fires once at or after a specific point in time.

The listener is passed the time it fires in UTC time.

Definition at line 1537 of file event.py.

◆ async_track_same_state()

CALLBACK_TYPE homeassistant.helpers.event.async_track_same_state ( HomeAssistant  hass,
timedelta  period,
Callable[[], Coroutine[Any, Any, None] | None]  action,
Callable[[str, State | None, State | None], bool]  async_check_same_func,
str | Iterable[str]   entity_ids = MATCH_ALL 
)
Track the state of entities for a period and run an action.

If async_check_func is None it use the state of orig_value.
Without entity_ids we track all state changes.

Definition at line 1389 of file event.py.

◆ async_track_state_added_domain()

CALLBACK_TYPE homeassistant.helpers.event.async_track_state_added_domain ( HomeAssistant  hass,
str | Iterable[str]  domains,
Callable[[Event[EventStateChangedData]], Any]  action,
HassJobType | None   job_type = None 
)
Track state change events when an entity is added to domains.

Definition at line 643 of file event.py.

◆ async_track_state_change()

CALLBACK_TYPE homeassistant.helpers.event.async_track_state_change ( HomeAssistant  hass,
str | Iterable[str]  entity_ids,
Callable[ [str, State | None, State | None], Coroutine[Any, Any, None] | None ]  action,
str | Iterable[str] | None   from_state = None,
str | Iterable[str] | None   to_state = None 
)
Track specific state changes.

entity_ids, from_state and to_state can be string or list.
Use list to match multiple.

Returns a function that can be called to remove the listener.

If entity_ids are not MATCH_ALL along with from_state and to_state
being None, async_track_state_change_event should be used instead
as it is slightly faster.

This function is deprecated and will be removed in Home Assistant 2025.5.

Must be run within the event loop.

Definition at line 203 of file event.py.

◆ async_track_state_change_event()

CALLBACK_TYPE homeassistant.helpers.event.async_track_state_change_event ( HomeAssistant  hass,
str | Iterable[str]  entity_ids,
Callable[[Event[EventStateChangedData]], Any]  action,
HassJobType | None   job_type = None 
)
Track specific state change events indexed by entity_id.

Unlike async_track_state_change, async_track_state_change_event
passes the full event to the callback.

In order to avoid having to iterate a long list
of EVENT_STATE_CHANGED and fire and create a job
for each one, we keep a dict of entity ids that
care about the state change events so we can
do a fast dict lookup to route events.
The passed in entity_ids will be automatically lower cased.

EVENT_STATE_CHANGED is fired on each occasion the state is updated
and changed, opposite of EVENT_STATE_REPORTED.

Definition at line 309 of file event.py.

◆ async_track_state_change_filtered()

_TrackStateChangeFiltered homeassistant.helpers.event.async_track_state_change_filtered ( HomeAssistant  hass,
TrackStates  track_states,
Callable[[Event[EventStateChangedData]], Any]  action 
)
Track state changes with a TrackStates filter that can be updated.

Parameters
----------
hass
    Home assistant object.
track_states
    A TrackStates data class.
action
    Callable to call with results.

Returns
-------
Object used to update the listeners (async_update_listeners) with a new
TrackStates or cancel the tracking (async_remove).

Definition at line 857 of file event.py.

◆ async_track_state_removed_domain()

CALLBACK_TYPE homeassistant.helpers.event.async_track_state_removed_domain ( HomeAssistant  hass,
str | Iterable[str]  domains,
Callable[[Event[EventStateChangedData]], Any]  action,
HassJobType | None   job_type = None 
)
Track state change events when an entity is removed from domains.

Definition at line 701 of file event.py.

◆ async_track_state_report_event()

CALLBACK_TYPE homeassistant.helpers.event.async_track_state_report_event ( HomeAssistant  hass,
str | Iterable[str]  entity_ids,
Callable[[Event[EventStateReportedData]], Any]  action,
HassJobType | None   job_type = None 
)
Track EVENT_STATE_REPORTED by entity_ids.

EVENT_STATE_REPORTED is fired on each occasion the state is updated
but not changed, opposite of EVENT_STATE_CHANGED.

Definition at line 407 of file event.py.

◆ async_track_sunrise()

CALLBACK_TYPE homeassistant.helpers.event.async_track_sunrise ( HomeAssistant  hass,
Callable[[], None]  action,
timedelta | None   offset = None 
)
Add a listener that will fire a specified offset from sunrise daily.

Definition at line 1758 of file event.py.

◆ async_track_sunset()

CALLBACK_TYPE homeassistant.helpers.event.async_track_sunset ( HomeAssistant  hass,
Callable[[], None]  action,
timedelta | None   offset = None 
)
Add a listener that will fire a specified offset from sunset daily.

Definition at line 1774 of file event.py.

◆ async_track_template()

CALLBACK_TYPE homeassistant.helpers.event.async_track_template ( HomeAssistant  hass,
Template  template,
Callable[ [str, State | None, State | None], Coroutine[Any, Any, None] | None ]  action,
TemplateVarsType | None   variables = None 
)
Add a listener that fires when a template evaluates to 'true'.

Listen for the result of the template becoming true, or a true-like
string result, such as 'On', 'Open', or 'Yes'. If the template results
in an error state when the value changes, this will be logged and not
passed through.

If the initial check of the template is invalid and results in an
exception, the listener will still be registered but will only
fire if the template result becomes true without an exception.

Action arguments
----------------
entity_id
    ID of the entity that triggered the state change.
old_state
    The old state of the entity that changed.
new_state
    New state of the entity that changed.

Parameters
----------
hass
    Home assistant object.
template
    The template to calculate.
action
    Callable to call with results. See above for arguments.
variables
    Variables to pass to the template.

Returns
-------
Callable to unregister the listener.

Definition at line 886 of file event.py.

◆ async_track_template_result()

TrackTemplateResultInfo homeassistant.helpers.event.async_track_template_result ( HomeAssistant  hass,
Sequence[TrackTemplate track_templates,
TrackTemplateResultListener  action,
bool   strict = False,
Callable[[int, str], None] | None   log_fn = None,
bool   has_super_template = False 
)
Add a listener that fires when the result of a template changes.

The action will fire with the initial result from the template, and
then whenever the output from the template changes. The template will
be reevaluated if any states referenced in the last run of the
template change, or if manually triggered. If the result of the
evaluation is different from the previous run, the listener is passed
the result.

If the template results in an TemplateError, this will be returned to
the listener the first time this happens but not for subsequent errors.
Once the template returns to a non-error condition the result is sent
to the action as usual.

Parameters
----------
hass
    Home assistant object.
track_templates
    An iterable of TrackTemplate.
action
    Callable to call with results.
strict
    When set to True, raise on undefined variables.
log_fn
    If not None, template error messages will logging by calling log_fn
    instead of the normal logging facility.
has_super_template
    When set to True, the first template will block rendering of other
    templates if it doesn't render as True.

Returns
-------
Info object used to unregister the listener, and refresh the template.

Definition at line 1338 of file event.py.

◆ async_track_time_change()

CALLBACK_TYPE homeassistant.helpers.event.async_track_time_change ( HomeAssistant  hass,
Callable[[datetime], Coroutine[Any, Any, None] | None]  action,
Any | None   hour = None,
Any | None   minute = None,
Any | None   second = None 
)
Add a listener that will fire every time the local time matches a pattern.

The listener is passed the time it fires in local time.

Definition at line 1898 of file event.py.

◆ async_track_time_interval()

CALLBACK_TYPE homeassistant.helpers.event.async_track_time_interval ( HomeAssistant  hass,
Callable[[datetime], Coroutine[Any, Any, None] | None]  action,
timedelta  interval,
*str | None   name = None,
bool | None   cancel_on_shutdown = None 
)
Add a listener that fires repetitively at every timedelta interval.

The listener is passed the time it fires in UTC time.

Definition at line 1672 of file event.py.

◆ async_track_utc_time_change()

CALLBACK_TYPE homeassistant.helpers.event.async_track_utc_time_change ( HomeAssistant  hass,
Callable[[datetime], Coroutine[Any, Any, None] | None]  action,
Any | None   hour = None,
Any | None   minute = None,
Any | None   second = None,
bool   local = False 
)
Add a listener that will fire every time the UTC or local time matches a pattern.

The listener is passed the time it fires in UTC or local time.

Definition at line 1850 of file event.py.

◆ process_state_match()

Callable[[str | None], bool] homeassistant.helpers.event.process_state_match ( str | Iterable[str] | None  parameter,
bool   invert = False 
)
Convert parameter to function that matches input against parameter.

Definition at line 1915 of file event.py.

Variable Documentation

◆ _ALL_LISTENER

homeassistant.helpers.event._ALL_LISTENER
private

Definition at line 79 of file event.py.

◆ _DOMAINS_LISTENER

homeassistant.helpers.event._DOMAINS_LISTENER
private

Definition at line 80 of file event.py.

◆ _ENTITIES_LISTENER

homeassistant.helpers.event._ENTITIES_LISTENER
private

Definition at line 81 of file event.py.

◆ _KEYED_TRACK_DEVICE_REGISTRY_UPDATED

homeassistant.helpers.event._KEYED_TRACK_DEVICE_REGISTRY_UPDATED
private

Definition at line 585 of file event.py.

◆ _KEYED_TRACK_ENTITY_REGISTRY_UPDATED

homeassistant.helpers.event._KEYED_TRACK_ENTITY_REGISTRY_UPDATED
private

Definition at line 528 of file event.py.

◆ _KEYED_TRACK_STATE_ADDED_DOMAIN

homeassistant.helpers.event._KEYED_TRACK_STATE_ADDED_DOMAIN
private

Definition at line 655 of file event.py.

◆ _KEYED_TRACK_STATE_CHANGE

homeassistant.helpers.event._KEYED_TRACK_STATE_CHANGE
private

Definition at line 375 of file event.py.

◆ _KEYED_TRACK_STATE_REMOVED_DOMAIN

homeassistant.helpers.event._KEYED_TRACK_STATE_REMOVED_DOMAIN
private

Definition at line 692 of file event.py.

◆ _KEYED_TRACK_STATE_REPORT

homeassistant.helpers.event._KEYED_TRACK_STATE_REPORT
private

Definition at line 399 of file event.py.

◆ _LOGGER

homeassistant.helpers.event._LOGGER
private

Definition at line 83 of file event.py.

◆ _StateEventDataT

homeassistant.helpers.event._StateEventDataT
private

Definition at line 93 of file event.py.

◆ _TypedDictT

homeassistant.helpers.event._TypedDictT
private

Definition at line 92 of file event.py.

◆ bound

homeassistant.helpers.event.bound

Definition at line 92 of file event.py.

◆ call_later

homeassistant.helpers.event.call_later

Definition at line 1613 of file event.py.

◆ dispatcher_callable

None homeassistant.helpers.event.dispatcher_callable = _async_dispatch_entity_id_event_soon,

Definition at line 378 of file event.py.

◆ event_type

homeassistant.helpers.event.event_type = EVENT_STATE_CHANGED,

Definition at line 377 of file event.py.

◆ filter_callable

bool homeassistant.helpers.event.filter_callable = _async_state_filter,

Definition at line 379 of file event.py.

◆ key

homeassistant.helpers.event.key = _TRACK_STATE_CHANGE_DATA,

Definition at line 376 of file event.py.

◆ RANDOM_MICROSECOND_MAX

homeassistant.helpers.event.RANDOM_MICROSECOND_MAX

Definition at line 90 of file event.py.

◆ RANDOM_MICROSECOND_MIN

homeassistant.helpers.event.RANDOM_MICROSECOND_MIN

Definition at line 89 of file event.py.

◆ time_tracker_timestamp

homeassistant.helpers.event.time_tracker_timestamp

Definition at line 1789 of file event.py.

◆ time_tracker_utcnow

homeassistant.helpers.event.time_tracker_utcnow

Definition at line 1788 of file event.py.

◆ track_point_in_time

homeassistant.helpers.event.track_point_in_time

Definition at line 1487 of file event.py.

◆ track_point_in_utc_time

homeassistant.helpers.event.track_point_in_utc_time

Definition at line 1560 of file event.py.

◆ track_same_state

homeassistant.helpers.event.track_same_state

Definition at line 1452 of file event.py.

◆ track_state_change

homeassistant.helpers.event.track_state_change

Definition at line 305 of file event.py.

◆ track_sunrise

homeassistant.helpers.event.track_sunrise

Definition at line 1769 of file event.py.

◆ track_sunset

homeassistant.helpers.event.track_sunset

Definition at line 1785 of file event.py.

◆ track_template

homeassistant.helpers.event.track_template

Definition at line 973 of file event.py.

◆ track_time_change

homeassistant.helpers.event.track_time_change

Definition at line 1912 of file event.py.

◆ track_time_interval

homeassistant.helpers.event.track_time_interval

Definition at line 1693 of file event.py.

◆ track_utc_time_change

homeassistant.helpers.event.track_utc_time_change

Definition at line 1893 of file event.py.

◆ TrackTemplateResultListener

homeassistant.helpers.event.TrackTemplateResultListener

Definition at line 1317 of file event.py.