From 3c080e9379b1b8c8ed5a7fd8ca15c91688f06f90 Mon Sep 17 00:00:00 2001 From: Phil Bruckner Date: Mon, 8 Jul 2019 15:18:46 -0500 Subject: [PATCH] Add datetime option to input_datetime.set_datetime service (#9791) --- source/_components/input_datetime.markdown | 28 +++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/source/_components/input_datetime.markdown b/source/_components/input_datetime.markdown index 08fca824434..be9451e12ad 100644 --- a/source/_components/input_datetime.markdown +++ b/source/_components/input_datetime.markdown @@ -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 %}