Add datetime option to input_datetime.set_datetime service (#9791)

This commit is contained in:
Phil Bruckner 2019-07-08 15:18:46 -05:00 committed by Paulus Schoutsen
parent f0e0ef8e38
commit 3c080e9379

View File

@ -87,12 +87,15 @@ Assistant stopping as long as your entity does **not** have a set value for
### Services
This integration provides a service to modify the state of the `input_datetime`.
Available service: `input_datetime.set_datetime`.
| Service | Data | Description |
| ----- | ----- | ----- |
| `set_datetime` | `time` | This can be used to dynamically set the time.
| `set_datetime` | `date` | This can be used to dynamically set the date.
Service data attribute | Format String | Description
-|-|-
`date` | `%Y-%m-%d` | This can be used to dynamically set the date.
`time` | `%H:%M:%S` | This can be used to dynamically set the time.
`datetime` | `%Y-%m-%d %H:%M:%S` | This can be used to dynamically set both the date & time.
To set both the date and time in the same call, use `date` and `time` together, or use `datetime` by itself. Using `datetime` has the advantage that both can be set using one template.
## Automation Examples
@ -115,8 +118,8 @@ automation:
{% endraw %}
To dynamically set the `input_datetime` you can call
`input_datetime.set_datetime`. The values for `date` and `time` must be in a certain format for the call to be successful.
You can use either `strftime("%Y-%m-%d")`/`strftime("%H:%M:%S")` or `timestamp_custom("%Y-%m-%d", true)`/`timestamp_custom("%H:%M:%S", true)` filter respectively.
`input_datetime.set_datetime`. The values for `date` and `time` must be in a certain format for the call to be successful. (See service description above.)
If you have a `datetime` object you can use its `strftime` method. Of if you have a timestamp you can use the `timestamp_custom` filter.
The following example can be used in an automation rule:
{% raw %}
@ -136,17 +139,14 @@ automation:
- service: input_datetime.set_datetime
entity_id: input_datetime.another_time
data_template:
time: '{{ now().strftime("%H:%M:%S") }}'
time: "{{ now().strftime('%H:%M:%S') }}"
- service: input_datetime.set_datetime
entity_id: input_datetime.another_date
data_template:
date: '{{ now().strftime("%Y-%m-%d") }}'
date: "{{ as_timestamp(now())|timestamp_custom('%Y-%m-%d') }}"
- service: input_datetime.set_datetime
entity_id: input_datetime.date_and_time
data_template:
entity_id: input_datetime.date_and_time
date: >
{{ now().timestamp() | timestamp_custom("%Y-%m-%d", true) }}
time: >
{{ now().timestamp() | timestamp_custom("%H:%M:%S", true) }}
datetime: "{{ now().strftime('%Y-%m-%d %H:%M:%S') }}"
```
{% endraw %}