Trigger Automation X minutes before alarm, chosing whichever alarm is set to go off first

Hello Folks,

I currently have an automation that is set to trigger 5 minutes before whatever my alarm is set to (sensor from HA app), that seems to be working well. The trigger is set up in the from of a helper that triggers true or false:

{{ as_timestamp(states('sensor.pixel_5_next_alarm_2')) - 600 < as_timestamp(now()) }}

What I’d like to do is determine which alarm is going to go off first, mine or my wife’s and trigger the automation 5 minutes before that alarm.

Any help you can offer is greatly appricated. Thank you!

Use the min filter to get the lowest timestamp value.

{{ ['sensor.pixel_5_next_alarm_2', 'sensor.other_phone_alarm']
  | map('states') | map('as_timestamp')
  | min - 600 < now().timestamp() }}