Android app next alarm updated too soon ends up not triggering alarms

In my HA installation I have created a rule to turn on lights and other actions when my alarm clock on the phone activates.
the rule actions run perfectly when triggered manually, but the template always fails to trigger.
After a few nights of trying to understand the reason of this, I have found out that the Android App updates the next alarm state instantly. My HA installation seems to update the next alarm sensor before it updates now() meaning that the automation never triggers.

I have tried to create a workaround that stores the alarm value in a helper for a few seconds longer, but that is proving way more complicated than it should be, so here I am.

Is it just me, is there an option to delay the phone sending updates until the alarm has run for a few seconds?

sync the time on the server and device

They are already synced via NTP, is this what you mean?

yup, what does your automation look like?

The trigger is exactly as I copied from:

I don’t get why it needs to be this complex.

This is the trigger code:

alias: When alarm clock rings on Galaxy S20
enabled: true
value_template: >-
  {{now().strftime("%a %h %d %H:%M %Z %Y") ==
  ((state_attr('sensor.galaxys20fe_next_alarm', 'Time in Milliseconds') |
    int / 1000)) | timestamp_custom('%a %h %d %H:%M %Z %Y')}}

try the example from the official docs

Thanks, that is so simple and works :astonished:

Why is it hidden so deep into the documentation? I would think that this should be a prime feature to brag about. Should be the first result when searching terms related to phone alarm automation. :man_facepalming:

In the meanwhile I managed to get the same result by using a Helper, but that method is way more complicated.