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.

  1. Go to Settings > Devices & services > Helpers, and select Create helper.
  2. 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

input_datetime map Required

Alias for the datetime input. Multiple entries are allowed.

name string (Optional)

Friendly name of the datetime input.

has_time boolean (Optional, default: false)

Set to true if the input should have a time. At least one of has_time or has_date must be defined.

has_date boolean (Optional, default: false)

Set to true if the input should have a date. At least one of has_time or has_date must be defined.

icon icon (Optional)

Icon to display in front of the input element in the frontend.

initial datetime | time | date (Optional)

Set the initial value of this input, depending on has_time and has_date.

Default:

00:00 | 00:00 |

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)
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.

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

  1. Add input_datetime: 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].
  2. Restart Home Assistant.
  3. After the restart, create your date and time helpers from the user interface.