Good morning. I’m trying to create an automation that turns a switch off after 1hr. Originally I just put a 1hr delay into my automation, after the switch is turned on but, after reading various topics on here, I realised that if Home Assistant where to restart during this period then the switch would not be turned off.
Instead I have created an input_datetime helper and I’m trying to set the it to now() + 1hr and have that as a trigger. I found this example from different topics.
{{ (now().strftime("%s") | int + (3600)) | timestamp_custom("%H:%M:%S", false) }}
This displays the time + 1hr in the Templating tool but when I trigger the automation the date/time state is 00:00:00
Here’s the action from my automation:-
- service: input_datetime.set_datetime
data_template:
entity_id: input_datetime.switch
time: >
{{ (now().strftime("%s") | int + (3600)) | timestamp_custom("%H:%M:%S", false) }}
I set up the input_datetime from the Helper GUI and only set it for Time, not for Date.
For completeness, I’ve also tried now().timestamp() but that threw up an ‘unknown error rendering template’.
Any help would be much appreciated.