Components Home Assistant "Datetime Input"

2 minutes of reading
Proconductor: Home Assistant Community
Availability: included in thepersonale HUB Home Assistant
Category: software
Type: components Home Assistant
Implementation difficulties: low

The "Input Datetime" component di Home Assistant allows you to create entity that allow the user, via frontend, to collect a date and / or time. These entities are particularly useful for the realization of timers or automations related, appunto dates and / or times.

Home Assistant - Datetime Input - Detail
an example of a date and time acquisition entity.

Define entities using the component "Datetime Input" it's very simple. An example of configuration in configuration.yaml is the following:

    name: Input con data e ora
    has_date: true
    has_time: true
    name: Input con solo data
    has_date: true
    has_time: false
    name: Input con solo orario
    has_date: false
    has_time: true

Generating configuration entities of this type:

Home Assistant - Datetime input

Configuration details:

input_datetimedefines the configuration block related to the entity (multiple can be defined)
name(string, optional) defines the name of the entity
has_time(boolean, mandatory) if true, the entity will collect the time. Default: false
has_date(boolean, mandatory) if true, the entity will collect the date. Default: false
initial(datetime | date | time, optional) defines the initial value. Default: 1970-01-01 00: 00 | 1970-01-01 | 00: 00

Nb one of the two fields has_time e has_date must necessarily be present.
In the absence of the field initial, the last collected values ​​are reproplaced even at the possible restart of Home Assistant.


The services related to this component is only one: set_datetime.

set_datetimedateCan be used to set programmatically the date collected by the target entity
set_datetimetimeCan be used to set programmatically the time collected by the target entity

Automation examples

The one to follow is an example of automation in which a input_datetime is used as trigger of an automation. This automation verifies that the time (sensor.time) corresponds or not to that of the entity input_datetime.only_time. In case, turn on a light (

    platform: template
    value_template: "{{ states('sensor.time') == (states.input_datetime.only_time.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}"
    service: light.turn_on

In this other example, when activated theinput_boolean.esempio, automation prosee to set the time of input_datetime.only_time at the 7: 30 in the morning.

    platform: state
    entity_id: input_boolean.esempio
    to: 'on'
    service: input_datetime.set_datetime
    entity_id: input_datetime.only_time
      time: '07:30:00'

Home Assistant Official LogoATTENZIONE: remember that there is on our FORUM community an ad hoc section dedicated to Home Assistant, for any doubt, question, information on the specific merit of these components.

inDomus telegram channel