Using input_datetime as For: on automation trigger

This must have been asked before, but I haven’t been able to find a way to do it…

I’d like to trigger an automation when a devices status has been the case for x amount of time, with that time coming from an input_datetime helper.

However I can think to try setting it, I’m told something like this:
Message malformed: offset input_datetime.my_period should be format 'HH:MM', 'HH:MM:SS' or 'HH:MM:SS.F' for dictionary value @ data['for']

Developer tools>States shows a state of 01:01:01 for input_datetime.my_period (which seems to fit ‘HH:MM:SS’ in the message I’m getting?).

Using this works just fine:

for:
  hours: 1
  minutes: 01
  seconds: 01

Does anyone know a way to do this please?

There is a documented example of doing this in the documentation, using a template.

Thanks. I can see two parts that might cover it:

for:
  minutes: "{{ states('input_number.lock_min')|int }}"
  seconds: "{{ states('input_number.lock_sec')|int }}"

and

minutes: "{{ states('input_number.minutes')|int(0) }}"

Maybe I’m reading it wrong or missing something obvious though, both look like they’re using separate helpers for minutes and seconds? I was hoping to use one holding a time like hours:minutes:seconds

If it doesn’t accept that, you’ll have to split the string yourself in the template, and pass the parts to hours/minutes/seconds. I didn’t test if it can or not.

Post your actual automation… I have a a number of automations that use time-only Input datetime helpers in this way and they are working.

Thats one of the approaches I’ve been trying, but I havent found how to pull hours and minutes from input_datetime.my_period

One of the triggers I’m trying to get going is:

trigger: state
entity_id:
  - binary_sensor.pir_stairs_top_occupancy
id: "Off"
to: "off"
for:
  the part I'm asking about

The rest of the automation’s working a treat, its specifically ‘the part I’m asking about’ where I’d like to refer to a input_datetime.my_period, so I can use the same (single) helper in multiple triggers for different PIR sensors and lights.

Be aware that having a typo like missing quotes, misspelled entity ID, or “pretty” quotes in the template could easily lead to the error you mentioned in the original post… which is why I asked you to post the actual automation.

If you are sure there are no such issues, then all you should need to do is add the template to the given example.

trigger: state
entity_id: 
  - binary_sensor.pir_stairs_top_occupancy
id: "Off"
to: "off"
for: "{{ states('input_datetime.my_period') }}"

If you were going to retrieve the individual unit values as karwost suggested you would use the split() method:

trigger: state
entity_id: 
  - binary_sensor.pir_stairs_top_occupancy
id: "Off"
to: "off"
for:
  hours: "{{ states('input_datetime.my_period').split(':')[0] }}"
  minutes: "{{ states('input_datetime.my_period').split(':')[1] }}"
  seconds: "{{ states('input_datetime.my_period').split(':')[2] }}"

Both of the methods above have been tested and work on 2025.4.3

The for: on the trigger is the only place I’m trying to use this input_datetime.
I just copied/pasted your example, and thought it still wasn’t triggering like this does:

for:
  hours: 0
  minutes: 0
  seconds: 10

Then I spot my mistake. 00:10 in the helper is 10 minutes not 10 seconds.
Sometimes I’m scarily good at being an idiot.:man_facepalming:

Not being able to set the seconds through the gui, I’ve set this:

for:
  minutes: "{{ states('input_datetime.my_period').split(':')[0] }}"
  seconds: "{{ states('input_datetime.my_period').split(':')[1] }}"

A bodge, but it’ll let me do what I was originally hoping.

Thanks