Input_datetime how to

this is my configuration.yaml entry

input_datetime:
  time1:
    name: time1
    has_date: true
    has_time: true

but the entity input_datetime.time1 doesn’t show up in HA

can someone explain how to do this properly please? Thank you

Can you please format your code properly by marking the code and pressing the </> button on top. Otherwise we will not be able to know if there’s an indentation error for example.

Edited my post. Sorry I didn’t know how to do it properly

The config looks fine. Did you restart HA after adding the input_datetime? If you go to Developer Tool -> States, do you see your entitiy? Do you see any errors under Developer Tools -> Logs?

i restarted several times until it showed up (weird)
so i tried using this:

entity_id: input_datetime.gatestairs
  time: '{{ now().strftime("%H:%M:%S") }}'
service: input_datetime.set_datetime

but an error message shows up saying it’s an invalid datetime specified for dictionary value time
i changed time to datetime but get the same error

The datetime you created was called time1
Where did you create gatestairs ?

oh i copy pasted the sample.
so this is my config yaml entry

input_datetime:
  gatestairs:
    name: gatestairs
    has_date: true
    has_time: true

and i tried this which doesnt work:

entity_id: input_datetime.gatestairs
  time: '{{ now().strftime("%H:%M:%S") }}'
service: input_datetime.set_datetime

What is the second block meant to be ? It’s incomplete.
But the main thing is that it doesn’t have date, your datetime does

Edit: Why the hell do people post code A when they want help with code B ?

I copied this config

# 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

From here

I even added date value but still won’t accept the values.
I want to get the current date and time and set to
Input_datetime.gatestairs as it’s value

So you want to create an automation that when an event occurs (say your gate opens) it store the time and date of that event ?
Manually fill in the input_datetime: with a fictious date
Go to the dev tools template page and type in “{{ states(‘input_datetime.gatestairs’) }}”
That will give you the format you need to enter.
Replicate that format with the time and date formatting parameters you used for H M S

Bullseye! Yes that’s what I want.
Thanks I’ll try it

I would guess (I’m not at a workstation) that it’ll be something like ‘%YYYY-%m-%d %H:%mm:%ss’

I can input a specific date or time using dev tools but I still am stumped about the current time syntax.

I even tried examples from here


to no avail

Can you please post the full automation that doesn’t work? I’m pretty sure that you are missing a “data_template” somewhere in there.

It’s always the “data_template” :rofl:

1 Like

I got the below code out of the examples in the input_datetime docs and it works fine on my test system:

- id: '1578278123313'
  alias: 'Set datetime on change of input_boolean'
  description: ''
  trigger:
    platform: state
    entity_id: input_boolean.test_boolean
  action:
  - service: input_datetime.set_datetime
    entity_id: input_datetime.gatestairs
    data_template:
      datetime: "{{ now().strftime('%Y-%m-%d %H:%M:%S') }}"

This sets the input_datetime to the current time, any time input_boolean.test_boolean changes.

2 Likes

Can you please help with the automation?
I need to save the time and date when the gate is last opened (I’m using a Reed sensor connected to a wemos mini) and have it shown on Lovelace

I’ll try this when I get home. Thank you