mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-07-17 22:36:51 +00:00
Add timestamp option for input_datetime.set_datetime (#14308)
This commit is contained in:
parent
f5eeb86ab6
commit
0a4fc1d0cc
@ -88,21 +88,25 @@ If you set a valid value for `initial` this integration will start with state se
|
|||||||
|
|
||||||
Available service: `input_datetime.set_datetime` and `input_datetime.reload`.
|
Available service: `input_datetime.set_datetime` and `input_datetime.reload`.
|
||||||
|
|
||||||
|
#### input_datetime.set_datetime
|
||||||
|
|
||||||
Service data attribute | Format String | Description
|
Service data attribute | Format String | Description
|
||||||
-|-|-
|
-|-|-
|
||||||
`date` | `%Y-%m-%d` | This can be used to dynamically set the date.
|
`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.
|
`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.
|
`datetime` | `%Y-%m-%d %H:%M:%S` | This can be used to dynamically set both the date & time.
|
||||||
|
`timestamp` | N/A | This can be used to dynamically set both the date & time using a UNIX timestamp.
|
||||||
|
|
||||||
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.
|
To set both the date and time in the same call, use `date` and `time` together, or use `datetime` or `timestamp` by itself. Using `datetime` or `timestamp` has the advantage that both can be set using one template.
|
||||||
|
|
||||||
|
#### input_datetime.reload
|
||||||
|
|
||||||
`input_dateteime.reload` service allows one to reload `input_datetime`'s configuration without restarting Home Assistant itself.
|
`input_dateteime.reload` service allows one to reload `input_datetime`'s configuration without restarting Home Assistant itself.
|
||||||
|
|
||||||
## Automation Examples
|
## Examples
|
||||||
|
|
||||||
The following example shows the usage of the `input_datetime` as a trigger in an
|
The following example shows the usage of the `input_datetime` as a trigger in an
|
||||||
automation (note that you will need a
|
automation:
|
||||||
[time sensor](/integrations/time_date) elsewhere in your configuration):
|
|
||||||
|
|
||||||
{% raw %}
|
{% raw %}
|
||||||
```yaml
|
```yaml
|
||||||
@ -110,56 +114,56 @@ automation (note that you will need a
|
|||||||
# Turns on bedroom light at the time specified.
|
# Turns on bedroom light at the time specified.
|
||||||
automation:
|
automation:
|
||||||
trigger:
|
trigger:
|
||||||
platform: template
|
platform: time
|
||||||
value_template: "{{ states('sensor.time') == (state_attr('input_datetime.bedroom_alarm_clock_time', 'timestamp') | int | timestamp_custom('%H:%M', False)) }}"
|
at: input_datetime.bedroom_alarm_clock_time
|
||||||
action:
|
action:
|
||||||
service: light.turn_on
|
service: light.turn_on
|
||||||
entity_id: light.bedroom
|
entity_id: light.bedroom
|
||||||
```
|
```
|
||||||
{% endraw %}
|
{% endraw %}
|
||||||
|
|
||||||
To dynamically set the `input_datetime` you can call
|
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. (See service description above.)
|
`input_datetime.set_datetime`. The values for `date`, `time` and/or `datetime` 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.
|
If you have a `datetime` object you can use its `timestamp` method. Of if you have a timestamp you can just use it directly.
|
||||||
The following example shows the different methods in an automation rule:
|
|
||||||
|
|
||||||
{% raw %}
|
{% raw %}
|
||||||
```yaml
|
```yaml
|
||||||
# Example configuration.yaml entry
|
# Sets time to 05:30:00
|
||||||
# Shows different ways to set input_datetime when an input_boolean is turned on
|
- service: input_datetime.set_datetime
|
||||||
automation:
|
entity_id: input_datetime.XXX
|
||||||
trigger:
|
|
||||||
platform: state
|
|
||||||
entity_id: input_boolean.example
|
|
||||||
to: 'on'
|
|
||||||
action:
|
|
||||||
# Sets time to '05:30:00
|
|
||||||
- service: input_datetime.set_datetime
|
|
||||||
entity_id: input_datetime.bedroom_alarm_clock_time
|
|
||||||
data:
|
data:
|
||||||
time: '05:30:00'
|
time: '05:30:00'
|
||||||
# Sets time to time from datetime object (current time in this example)
|
# Sets time to time from datetime object
|
||||||
- service: input_datetime.set_datetime
|
- service: input_datetime.set_datetime
|
||||||
entity_id: input_datetime.another_time
|
entity_id: input_datetime.XXX
|
||||||
data:
|
data:
|
||||||
time: "{{ now().strftime('%H:%M:%S') }}"
|
time: "{{ now().strftime('%H:%M:%S') }}"
|
||||||
# Sets date to date from timestamp (current date in this example)
|
# Sets date to 2020-08-24
|
||||||
- service: input_datetime.set_datetime
|
- service: input_datetime.set_datetime
|
||||||
entity_id: input_datetime.another_date
|
entity_id: input_datetime.XXX
|
||||||
data:
|
data:
|
||||||
date: "{{ as_timestamp(now())|timestamp_custom('%Y-%m-%d') }}"
|
date: '2020-08-24'
|
||||||
# Sets date and time to date and time from datetime object (current date and time in this example)
|
# Sets date to date from datetime object
|
||||||
- service: input_datetime.set_datetime
|
- service: input_datetime.set_datetime
|
||||||
entity_id: input_datetime.date_and_time
|
entity_id: input_datetime.XXX
|
||||||
|
data:
|
||||||
|
date: "{{ now().strftime('%Y-%m-%d') }}"
|
||||||
|
# Sets date and time to 2020-08-25 05:30:00
|
||||||
|
- service: input_datetime.set_datetime
|
||||||
|
entity_id: input_datetime.XXX
|
||||||
|
data:
|
||||||
|
datetime: '2020-08-25 05:30:00'
|
||||||
|
# Sets date and time from datetime object
|
||||||
|
- service: input_datetime.set_datetime
|
||||||
|
entity_id: input_datetime.XXX
|
||||||
data:
|
data:
|
||||||
datetime: "{{ now().strftime('%Y-%m-%d %H:%M:%S') }}"
|
datetime: "{{ now().strftime('%Y-%m-%d %H:%M:%S') }}"
|
||||||
# Sets date and time to date and time from timestamp (current date and time in this example)
|
# Sets date and/or time from UNIX timestamp
|
||||||
- service: input_datetime.set_datetime
|
# This can be used whether the input_datetime has just a date,
|
||||||
|
# or just a time, or has both
|
||||||
|
- service: input_datetime.set_datetime
|
||||||
data:
|
data:
|
||||||
entity_id: input_datetime.date_and_time
|
entity_id: input_datetime.XXX
|
||||||
date: >
|
timestamp: "{{ now().timestamp() }}"
|
||||||
{{ now().timestamp() | timestamp_custom("%Y-%m-%d", true) }}
|
|
||||||
time: >
|
|
||||||
{{ now().timestamp() | timestamp_custom("%H:%M:%S", true) }}
|
|
||||||
```
|
```
|
||||||
{% endraw %}
|
{% endraw %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user