Alarm Clock time Problem

Hello together,
although there are already hundreds of threads about this topic, I just can’t get ahead.

I want to create a helper automation for the alarm clock. As soon as Android’s _next_alarm is updated, the automation should take the new alarm time, subtract 5 minutes and store it in the helper input_datetime.alarmminusmin.

I just can’t manage to subtract 5 minutes. I have already tried several solutions, unfortunately without success. Since the data type at the end is a string, this is more difficult than I thought…

alias: Wecker_Hilfsautomatisierung
description: ""
  - platform: template
    value_template: >-
      {{ now() - states.sensor.poco_f2_pro_nachster_wecker.last_changed >
      timedelta(seconds=1) }}
    enabled: true
condition: []
  - service: input_datetime.set_datetime
      datetime: >-
        {{ as_timestamp(states('sensor.poco_f2_pro_nachster_wecker'))
        |timestamp_custom('%Y-%m-%d %H:%M:00') }} 
      entity_id: input_datetime.alarmminusmin
mode: single

Do you need this helper for something else than triggering on?
I mean you could just trigger on next alarm - 5 mins directly instead of going to a helper in beteeen

1 Like

Thank you for your reply. I had read about the problem that the alarm partly does not trigger the automation if the system time differs from the android phone time even one second. To get around this, I wanted to do it with the helper.

I honestly don’t quite understand why this shouldn’t trigger the automation (at most a time offset between the automation and the Android alarm clock would be conceivable from my point of view), but I didn’t want to take the risk.

(See Android next alarm sensor not triggering automations or Node Red time nodes at alarm time · Issue #2616 · home-assistant/android · GitHub)

What I meant with my previous post is. Do you need the datetime for something else than triggering your automation?

Instead of creating one automation to create a datetime, then create an automation tro trigger on this datetime. What about just creating one automation to trigger at five minutes before your alarm?

This will trigger (template trigger) at the time.

{{ (now().timestamp() |int) >= (state_attr('sensor.andreas_next_alarm', 'Time in Milliseconds') / 1000) |int }}

And if we subtract 300 seconds

{{ (now().timestamp() |int) >= (state_attr('sensor.andreas_next_alarm', 'Time in Milliseconds') / 1000) |int - 300 }}

Then we have an automation that triggers five minutes before the alarm.