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?).
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.
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:
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.
Not being able to set the seconds through the gui, I’ve set this: