Input_datetime how to

You need data_template any time you use a template to define the data part in your automation.

You should be able to adapt my example to your needs, just replace the trigger part with your sensor.

1 Like

So absolutely nothing like my guess : -

:roll_eyes:, I must be just another victim of ‘cut and paste from another template’ fatigue :rofl:

2 Likes

I copied it straight out of the docs, took me like 5 secs :rofl:

What’s the entity id from the Reed sensor and do you want it to trigger when it goes ‘on’ or ‘off’ ?

I guessed at it from a vague recollection, took me 5 mins, dementia setting in :tongue:

- 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') }}"

the above code works. Thank you.

1 Like

Now change it to use your sensor as a trigger and done :wink:

i did and then used the timestamp attribute and converted it to timestamp_custom to my liking.

Thank you very much for being patient with me

Just for your information, I updated the official docs to make the examples more clear.

1 Like