WTH Can we have an offset on date/time helper trigger in automations

A time trigger allows you to use a date/time helper instead of a hardcoded time. Would it be possible to add an optional offset (+/-) to this, in the same way as sunrise/sunset does.

Could be used in a situation like an alarm time (the date/time helper) and the automation can be triggered to run, say, 15 minutes before the date/time to turn something on to be ready for alarm time.

This way changing the alarm time helper adjusts the ‘alarm’ automation and the ‘turn on before alarm’ automation

And not just for the date/time helpers, It will be useful to any timestamp entity. For example running automation to notify about certificate expire two weeks before it expires.

Being able to trigger an automation before/after the next_alarm sensor from the companion app would be a great use for this too !

I did a little digging and found something that works. I am using 2022.12.8 and tested (successfully) the following automation that will allow you do an offset. You can configure it however you like, but note that the “120” is seconds.

alias: Test Automation
description: "2 minutes before the value template triggers, based on the datetime helper, an audible notification will be sent to a specific echo device"
  - platform: template
    value_template: >-
      {{ states('sensor.time') == (
      states.input_datetime.alarm_clock.attributes.timestamp | int - 120 ) |
      timestamp_custom('%H:%M', False) }}
condition: []
  - service: notify.alexa_media_my_echo
      message: This is a test
        type: tts
mode: single

Hope that this is close to what you were looking for, and helps you out

1 Like

I tried your automation, but the trigger doesn’t work for me

platform: template
value_template: >-
  {{ states('sensor.time') == (
  states.input_datetime.testzeithelfer.attributes.timestamp | int - 120 ) |
  timestamp_custom('%H:%M', False) }}

I did create the date/time helper and set it to a time later today, so I assumed that the trigger will start the automation 120 seconds before the set time. But it didn’t
Anything else I have to do before?