Update input_datetime format description (#8430)

* Update input_datetime.markdown

Added description of correct format of date/time variables with automation examples.

* Add missing raw
This commit is contained in:
akasma74 2019-02-10 22:19:21 +00:00 committed by Fabian Affolter
parent b7dee5cbb8
commit af0e934df6

View File

@ -114,9 +114,11 @@ automation:
{% endraw %}
To dynamically set the `input_datetime` you can call
`input_datetime.set_datetime`. The following example can be used in an
automation rule:
`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.
The following example can be used in an automation rule:
{% raw %}
```yaml
# Example configuration.yaml entry
# Sets input_datetime to '05:30' when an input_boolean is turned on.
@ -126,8 +128,24 @@ automation:
entity_id: input_boolean.example
to: 'on'
action:
service: input_datetime.set_datetime
- service: input_datetime.set_datetime
entity_id: input_datetime.bedroom_alarm_clock_time
data:
time: '05:30:00'
- service: input_datetime.set_datetime
entity_id: input_datetime.another_time
data_template:
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") }}'
- service: input_datetime.set_datetime
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) }}
```
{% endraw %}