Input Datetime
The Input Datetime integrationIntegrations connect and integrate Home Assistant with your devices, services, and more. [Learn more] lets you create a date and time helperA helper is a virtual entity you create inside Home Assistant. It is not backed by a physical device. Helpers store values, track state, or do calculations that your automations and dashboards need. [Learn more]: an entity that stores a date, a time, or both, which you can set yourself. Because the value is not tied to a physical device, you can use it as an adjustable date or time setting for your automations, scripts, and dashboards. For example, you can create a date and time helper to store a wake-up time, a target date, or the moment an automation should run.
On a dashboard, a date and time helper appears as a date picker, a time picker, or both. Each time the value changes, Home Assistant records a new stateThe state holds the information of interest of an entity, for example, if a light is on or off. Each entity has exactly one state and the state only holds one value at a time. However, entities can store attributes related to that state such as brightness, color, or a unit of measurement. [Learn more], which you can use in your automations and templates. Your automations and scripts can also change the value, which makes a date and time helper a convenient way to share a setting between the UI and your automations.
- Go to Settings > Devices & services > Helpers, and select Create helper.
- Select Date and/or time.
input_datetime can also be configured via YAML. 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.yamlThe configuration.yaml file is the main configuration file for Home Assistant. It lists the integrations to be loaded and their specific configurations. In some cases, the configuration needs to be edited manually directly in the configuration.yaml file. Most integrations can be configured in the UI. [Learn more]:
# 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 Variables
Alias for the datetime input. Multiple entries are allowed.
Set to true if the input should have a time. At least one of has_time or has_date must be defined.
Set to true if the input should have a date. At least one of has_time or has_date must be defined.
Icon to display in front of the input element in the frontend.
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. |
yearmonthday
|
The year, month and day of the date. (only available if has_date: true) |
timestamp |
A timestamp representing the time held in the input. (only available if has_time: true) |
Restore state
If you set a valid value for initial, this integration will start with the state set to that value. Otherwise, it will restore the state it had before Home Assistant stopping.
List of actions
The Input Datetime integrationIntegrations connect and integrate Home Assistant with your devices, services, and more. [Learn more] provides the following actions. Each link below opens a dedicated page with examples, parameters, and a step-by-step UI walkthrough.
-
Reload input datetimes (
input_datetime.reload) Reloads the input datetime helpers from the YAML configuration. -
Set input datetime value (
input_datetime.set_datetime) Sets the date and/or time of an input datetime.
For an overview of every action across all integrations, see the actions reference.
Examples
The following example shows the usage of the input_datetime as a trigger in an
automation:
# Example configuration.yaml entry
# Turns on bedroom light at the time specified.
automation:
triggers:
- trigger: time
at: input_datetime.bedroom_alarm_clock_time
actions:
- action: light.turn_on
target:
entity_id: light.bedroom
To dynamically set the input_datetime you can call
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 the Set input datetime value action for the expected formats.
If you have a datetime object, you can use its timestamp method. Or, if you have a timestamp, you can just use it directly.
# Sets time to 05:30:00
- action: input_datetime.set_datetime
target:
entity_id: input_datetime.XXX
data:
time: "05:30:00"
# Sets time to time from datetime object
- action: input_datetime.set_datetime
target:
entity_id: input_datetime.XXX
data:
time: "{{ now().strftime('%H:%M:%S') }}"
# Sets date to 2020-08-24
- action: input_datetime.set_datetime
target:
entity_id: input_datetime.XXX
data:
date: "2020-08-24"
# Sets date to date from datetime object
- action: input_datetime.set_datetime
target:
entity_id: input_datetime.XXX
data:
date: "{{ now().strftime('%Y-%m-%d') }}"
# Sets date and time to 2020-08-25 05:30:00
- action: input_datetime.set_datetime
target:
entity_id: input_datetime.XXX
data:
datetime: "2020-08-25 05:30:00"
# Sets date and time from datetime object
- action: input_datetime.set_datetime
target:
entity_id: input_datetime.XXX
data:
datetime: "{{ now().strftime('%Y-%m-%d %H:%M:%S') }}"
# Sets date and/or time from UNIX timestamp
# This can be used whether the input_datetime has just a date,
# or just a time, or has both
- action: input_datetime.set_datetime
target:
entity_id: input_datetime.XXX
data:
timestamp: "{{ now().timestamp() }}"
Troubleshooting
The Date and/or time helper option is missing from the UI
Symptom
When you go to Settings > Devices & services > Helpers to add a helper, the Date and/or time option is not listed.
Description
Date and time helpers are provided through default_config:, which is part of your configuration.yamlThe configuration.yaml file is the main configuration file for Home Assistant. It lists the integrations to be loaded and their specific configurations. In some cases, the configuration needs to be edited manually directly in the configuration.yaml file. Most integrations can be configured in the UI. [Learn more] by default. If you removed default_config:, the option is no longer available.
Resolution
- Add
input_datetime:to yourconfiguration.yamlThe configuration.yaml file is the main configuration file for Home Assistant. It lists the integrations to be loaded and their specific configurations. In some cases, the configuration needs to be edited manually directly in the configuration.yaml file. Most integrations can be configured in the UI. [Learn more]. - Restart Home Assistant.
- After the restart, create your date and time helpers from the user interface.