2015-01-15 23:32:27 -08:00
|
|
|
"""
|
2016-03-07 20:20:07 +01:00
|
|
|
Offer time listening automation rules.
|
2015-10-13 21:08:51 +02:00
|
|
|
|
|
|
|
For more details about this automation rule, please refer to the documentation
|
2017-04-05 23:23:02 -07:00
|
|
|
at https://home-assistant.io/docs/automation/trigger/#time-trigger
|
2015-01-15 23:32:27 -08:00
|
|
|
"""
|
2015-09-13 22:25:42 -07:00
|
|
|
import logging
|
|
|
|
|
2016-04-28 12:03:57 +02:00
|
|
|
import voluptuous as vol
|
|
|
|
|
2016-10-04 20:44:32 -07:00
|
|
|
from homeassistant.core import callback
|
2017-07-17 22:24:05 +02:00
|
|
|
from homeassistant.const import CONF_AT, CONF_PLATFORM
|
2016-04-28 12:03:57 +02:00
|
|
|
from homeassistant.helpers import config_validation as cv
|
2016-10-01 01:22:13 -07:00
|
|
|
from homeassistant.helpers.event import async_track_time_change
|
2015-01-15 23:32:27 -08:00
|
|
|
|
2015-09-17 08:24:06 +02:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2019-01-15 12:33:34 -05:00
|
|
|
TRIGGER_SCHEMA = vol.Schema({
|
2016-04-28 12:03:57 +02:00
|
|
|
vol.Required(CONF_PLATFORM): 'time',
|
2019-01-15 12:33:34 -05:00
|
|
|
vol.Required(CONF_AT): cv.time,
|
|
|
|
})
|
2016-04-28 12:03:57 +02:00
|
|
|
|
2015-01-15 23:32:27 -08:00
|
|
|
|
2018-11-05 09:23:58 +01:00
|
|
|
async def async_trigger(hass, config, action, automation_info):
|
2017-05-02 22:47:20 +02:00
|
|
|
"""Listen for state changes based on configuration."""
|
2019-01-15 12:33:34 -05:00
|
|
|
at_time = config.get(CONF_AT)
|
|
|
|
hours, minutes, seconds = at_time.hour, at_time.minute, at_time.second
|
2015-09-15 08:56:06 -07:00
|
|
|
|
2016-10-04 20:44:32 -07:00
|
|
|
@callback
|
2015-01-15 23:32:27 -08:00
|
|
|
def time_automation_listener(now):
|
2016-03-07 20:20:07 +01:00
|
|
|
"""Listen for time changes and calls action."""
|
2016-10-04 20:44:32 -07:00
|
|
|
hass.async_run_job(action, {
|
2016-04-21 13:59:42 -07:00
|
|
|
'trigger': {
|
|
|
|
'platform': 'time',
|
|
|
|
'now': now,
|
|
|
|
},
|
|
|
|
})
|
2015-01-15 23:32:27 -08:00
|
|
|
|
2016-10-01 01:22:13 -07:00
|
|
|
return async_track_time_change(hass, time_automation_listener,
|
|
|
|
hour=hours, minute=minutes, second=seconds)
|