I have a sensor from the HA mobile app that reflects the next alarm set on my phone. I’m trying to express it as something similar “The next alarm will happen in 1 day, 2 hours and 10 minutes”. I can work out the if/then logic to handle when I have or don’t have days/hours (alarm is less than a day or less than an hour).
I’m having trouble isolating the number of hours or minutes in the future that the alarm is set for.
{% set next_alarm = as_local(as_datetime(states('sensor.phone_next_alarm'))) %}
{% set alarm_diff = (next_alarm - now()) %}
next alarm: {{next_alarm}}
day of the week of next alarm: {{next_alarm.strftime('%A')}}
hour of next alarm: {{next_alarm.hour}}
minutes of next alarm: {{next_alarm.minute}}
Timedelta {{alarm_diff}}
how many days in the future: {{alarm_diff.days}}
which yields something like
next alarm: 2022-01-07 11:30:00-05:00
day of the week of next alarm: Friday
hour of next alarm: 11
minutes of next alarm: 30
Timedelta 2 days, 1:03:59.990890
how many days in the future: 2
But there doesn’t appear to be a “minutes” or “hours” attribute of the alarm_diff (like {{alarm_dif.minutes}} or {{alarm_diff.hours}}
Can someone point me in the right direction?