1 """Offer sun based automation rules."""
3 from datetime
import timedelta
5 import voluptuous
as vol
19 TRIGGER_SCHEMA = cv.TRIGGER_BASE_SCHEMA.extend(
21 vol.Required(CONF_PLATFORM):
"sun",
22 vol.Required(CONF_EVENT): cv.sun_event,
23 vol.Required(CONF_OFFSET, default=
timedelta(0)): cv.time_period,
31 action: TriggerActionType,
32 trigger_info: TriggerInfo,
34 """Listen for events based on configuration."""
35 trigger_data = trigger_info[
"trigger_data"]
36 event = config.get(CONF_EVENT)
37 offset = config.get(CONF_OFFSET)
40 description = f
"{description} with offset"
44 def call_action() -> None:
45 """Call action with right context."""
46 hass.async_run_hass_job(
54 "description": description,
59 if event == SUN_EVENT_SUNRISE:
CALLBACK_TYPE async_attach_trigger(HomeAssistant hass, ConfigType config, TriggerActionType action, TriggerInfo trigger_info)
CALLBACK_TYPE async_track_sunset(HomeAssistant hass, Callable[[], None] action, timedelta|None offset=None)
CALLBACK_TYPE async_track_sunrise(HomeAssistant hass, Callable[[], None] action, timedelta|None offset=None)