home-assistant.io/source/_components/input_datetime.markdown
Franck Nijhof 6224c71c08 Various markdown, spelling, and grammar fixes #3 (#4510)
*  Various markdown, spelling, and grammar fixes

*  Various markdown, spelling, and grammar fixes

*  Various markdown, spelling, and grammar fixes
2018-01-25 18:21:05 +01:00

3.2 KiB

layout title description date sidebar comments sharing footer logo ha_category ha_release
page Input Datetime Instructions how to integrate the Input Datetime component into Home Assistant. 2017-09-14 16:01 true false true true home-assistant.png Automation 0.55

The input_datetime component allows the user to define date and time values that can be controlled via the frontend and can be used within automations and templates.

To add three datetime inputs to your installation, one with both date and time, and one with date or time each, add the following lines to your configuration.yaml:

# Example configuration.yaml entry
input_datetime:
  both_date_and_time:
    name: Input with both date and time
    has_date: true
    has_time: true
  only_date:
    name: Input with only date
    has_date: true
    has_time: false
  only_time:
    name: Input with only time
    has_date: false
    has_time: true

{% configuration %} input_datetime: description: Alias for the datetime input. Multiple entries are allowed. required: true type: map keys: name: description: Friendly name of the datetime input. required: false type: String has_time: description: Set to true if the input should have a time. At least one has_time or has_date must be defined. required: false type: Boolean default: false has_date: description: Set to true if the input should have a date. At least one has_time or has_date must be defined. required: false type: Boolean default: false initial: description: Set the initial value of this input, depending on has_time and has_date. required: false type: datetime | time | date default: 1970-01-01 00:00 | 1970-01-01 | 00:00 {% endconfiguration %}

{% linkable_title Attributes %}

A datetime input entity's state exports several attributes that can be useful in automations and templates.

Attribute Description
has_time true if this entity has a time.
has_date true if this entity has a date.
year
month
day
The year, month and day of the date.
(only available if has_date: true)
hour
minute
second
The hour, minute and second of the time.
(only available if has_time: true)
timestamp A timestamp representing the time held in the input.
If has_date: true, this is the UNIX timestamp of the date / time held by the input. Otherwise if only has_time: true, this is the number of seconds since midnight representing the time held by the input.

{% linkable_title Restore State %}

This component supports the restore_state function which restores the state after Home Assistant has started to the value it has been before Home Assistant stopped. To use this feature please make sure that the recorder component is enabled and your entity does not have a value set for initial. Additional information can be found in the Restore state section of the recorder component documentation.