Subtract time and date based on a helper?

Hi,

I have two date and time helpers which I use to input when we are gone on a vacation (one named “departure” and “arrival”). I want my house to be warm when we come home. I figure the best practice is to create a helper based on the “departure” helper. If I could create an helper which takes the arrival time- and date and subtracts 4-5 hours, I could use that to “prepare the house” for our arrival (warm up, run the vacuum, run air-vents etc.

Help? Thanks in advance.

Convert the Input Datetime’s value from a datetime string to a datetime object then subtract the desired number of hours by representing it as a timedelta object.

{{ states('input_datetime.arrival') | as_datetime | as_local - timedelta(hours=4) }}

Copy-paste the template into the Template Editor, change the Input Datetime’s entity_id to match yours then confirm it reports the desired date and time.

The template can be used to create a Template Sensor Helper. Set its device_class to timestamp and use this version of the template:

{{ (states('input_datetime.arrival') | as_datetime | as_local - timedelta(hours=4)).isoformat() }}

The resulting Template Sensor Helper can be used directly in an automation’s Time Trigger.