How to start an automation X hoursfater an input datetime

Hello
I have an input datetime who start an automation

alias: Mode presence
description: Active thermostat et chauffe eau a la date saisie
trigger:
  - platform: time
    at: input_datetime.date_retour
condition: []
action:
  - service: climate.set_hvac_mode
    target:
      entity_id: climate.thermostat
    data:
      hvac_mode: heat
  - service: input_boolean.turn_on
    target:
      entity_id:
        - input_boolean.absent_present
    data: {}
mode: single

I want with the same input datetime start my heater water but for example 23 hours later…
For example: i m back in my house the 12/12/2022
The input date time is in french 12/12/2022 00h05
the entity_id: climate.thermostat star at 00h05
The entity_id: water_heater.lineo start at 23h05
I dont know how to do that
Thank’s for your help

Is the input_datetime used to trigger something else at 00:05?

If it doesn’t then why not just set the input_datetime to 23:05 instead of 00:05?

If you must add 23 hours to the input_datetime’s value, create a Template Sensor.

template:
  - sensor:
      - name: Delayed Return Date
        state: "{{ (states('input_datetime.date_retour') | as_datetime | as_local + timedelta(hours=23)).isoformat() }}"
        device_class: timestamp

Then modify your automation’s Time Trigger to use the Template Sensor.

alias: Mode presence
description: Active thermostat et chauffe eau a la date saisie
trigger:
  - platform: time
    at: sensor.delayed_return_date
condition: []
... etc ...

Hello
Thank’s for your help. But it doesnt work

I enter this in the configuration.yaml file

template:
  - sensor:
      - name: delayed_return_date
        device_class: timestamp
        state: "{{ (states('input_datetime.date_retour') | as_datetime | as_local + timedelta(hours=1)).isoformat() }}"

I tested with 1 hour…

And the automation is

alias: Active chauffe eau
description: Active chauffe eau a la date saisie
trigger:
  - platform: time
    at: sensor.delayed_return_date
condition: []
action:
  - service: input_boolean.turn_on
    target:
      entity_id:
        - input_boolean.test
    data: {}
mode: single

I test with the input_bolean.test
Nothing happens 1 hour after the input time

The idea is to start the heater before i am back to my secondary house and later (23h) the heater water. I arrived at the end of the journey.
In France we have special price the night for electricity

Thank’s

I tested it and it works for me. Here’s how I tested it:

I have an existing Input Datetime named input_datetime.test and set its value to today at 08:20.

I created a Template Sensor that adds 2 minutes to the value of input_datetime.test.

template:
  - sensor:
      - name: test_delayed_time
        device_class: timestamp
        state: "{{ (states('input_datetime.test') | as_datetime | as_local + timedelta(minutes=2)).isoformat() }}"

After executing Developer Tools > YAML > Reload Template Entities, the entity sensor.test_delayed_time appears in Developers Tools > States. It displays the time in UTC (as opposed to my local time) but it’s obvious the minutes portion is 20 + 2 = 22.

I created the following automation to display a notification at the time specified by sensor.test_delayed_time. I created it in the Automation Editor so it was loaded the moment I clicked the Save button.

alias: Test delayed time
description: ""
trigger:
  - platform: time
    at: sensor.test_delayed_time
condition: []
action:
  - service: notify.persistent_notification
    data:
      title: "{{ now().timestamp() | timestamp_custom() }}"
      message: Test delayed time
mode: single

At 08:22, the automation triggered and produced the following notification:

The testing procedure confirmed the method I suggested does in fact work. What remains is to determine why it didn’t work for you.

Thank’s for your big help…
The problem was i haven’t restart HA.
When i made i see the sensor in Developers Tools > States and the automation work perfectly

Thank’s so much

But i din’t find Developer Tools > YAML > Reload Template Entities. I restart every yaml. But just the HA restart solved the problem
And now i have the line Developer Tools > YAML > Reload Template Entitie

1 Like

You’re welcome but please consider marking my post above with the Solution tag.

The purpose of the Solution tag is to direct other users to the post that contains the information that solves the original problem. You marked your own post as the Solution but it contains nothing explaining how to trigger an automation at a later time. Restarting Home Assistant to reload Template Entities isn’t a “solution” to the original problem.

That implies you didn’t have any existing Template Sensors (or any other entities based on the Template integration) and this was your first one. In that situation, yes, you’re obliged to restart Home Assistant in order to load your first Template Sensor.