Time trigger can also accept an input_datetime Entity ID (#14207)

Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
Phil Bruckner 2020-08-13 06:29:20 -05:00 committed by GitHub
parent 445a7a0d5e
commit a89d99be20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -282,9 +282,10 @@ automation:
The `for` template(s) will be evaluated when the `value_template` becomes `true`.
<div class='note warning'>
Rendering templates with time (`now()`) is dangerous as trigger templates are only updated based on entity state changes.
</div>
</div>
As an alternative, providing you include the sensor [time](/integrations/time_date/) in your configuration, you can use the following template:
@ -303,7 +304,11 @@ which will evaluate to `True` if `YOUR.ENTITY` changed more than 300 seconds ago
### Time trigger
The time trigger is configured to fire once at a specific point in time each day.
The time trigger is configured to fire once a day at a specific time, or at a specific time on a specific date. There are two allowed formats:
#### Time String
A string that represents a time to fire on each day. Can be specified as `HH:MM` or `HH:MM:SS`. If the seconds are not specified, `:00` will be used.
```yaml
automation:
@ -313,15 +318,55 @@ automation:
at: "15:32:00"
```
Or at multiple specific times:
#### Input Datetime
The Entity ID of an [Input Datetime](/integrations/input_datetime/).
has_date | has_time | Description
-|-|-
`true` | `true` | Will fire at specified date & time.
`true` | `false` | Will fire at midnight on specified date.
`false` | `true` | Will fire once a day at specified time.
{% raw %}
```yaml
automation:
- trigger:
platform: state
entity_id: binary_sensor.motion
to: 'on'
action:
- service: climate.turn_on
entity_id: climate.office
- service: input_datetime.set_datetime
entity_id: input_datetime.turn_off_ac
data_template:
datetime: >
{{ (now().timestamp() + 2*60*60)
| timestamp_custom('%Y-%m-%d %H:%M:%S') }}
- trigger:
platform: time
at: input_datetime.turn_off_ac
action:
service: climate.turn_off
entity_id: climate.office
```
{% endraw %}
#### Multiple Times
Multiple times can be provided in a list. Both formats can be intermixed.
```yaml
automation:
trigger:
platform: time
at:
- "15:32:00"
- "20:30:00"
- input_datetime.leave_for_work
- "18:30:00"
```
### Time pattern trigger