Hey there!
I would find very useful a new automation event, containing the next upcoming alarm, that could fire whenever an alarm rings or is edited.
My usecase is as follows:
I’ve got SleepAsAndroid pushing events to an MQTT queue, and Home Assistant listening for them. I want to know when the next alarm is, so I can dim my lights 8 hours before the alarm, or have an announcement like “Your next alarm is in X hours Y minutes” on my speakers.
Would it be possible to have a new automation event (containing the time and name of the next alarm) that fires whenever:
- Any alarm is edited or disabled (There’s already an ALARM_RESCHEDULED, but that’s different. If I have an alarm A for 9am and an alarm B for 10am, and I change B from 10:00 to 10:30, I’d still want to receive “NEXT_ALARM A at 9:00”, while ALARM_RESCHEDULED notifies about alarm B)
- An alarm rings (if I have an alarm that rings daily at 9am, when it rings on Monday the event should get sent out, because now the next alarm is at 9am on Tuesday)
I think this could fix issues the home assistant community is having when trying to integrate with SleepAsAndroid (as currently the only real way to get the next alarm is through a home assistant sensor that’s extremely buggy and unreliable). There’s a few posts of people having issues with the next alarm sensor, that having this event would 100% fix:
- https://old.reddit.com/r/homeassistant/comments/mi3hj1/a_rambling_post_about_using_sleep_as_android_in/
- Next Alarm sensor not updating / stuck in the past (Samsung Galaxy S22) - Home Assistant Companion for Android - Home Assistant Community
I’ve had my own issues with this sensor (I set an alarm for tomorrow at 8 am, then immediately changed it to 9am. The next alarm sensor is still announcing the next alarm is at 8 am, not terribly useful)
1 Like
+1 for requesting a NEXT_ALARM intent from Sleep as Android.
I’ve also seen the Android OS level next alarm notification be weird (eg. the next alarm is constantly 10 minutes in the future), but I haven’t noticed it being weird recently so maybe it’s fixed now? I also didn’t realize the Home Assistant app can read it, I just enabled it so I’ll track the next alarm time for a week or so to see if it’s reliable enough to use for automatons.
I currently use Tasker to watch Sleep as Android intents to tell Home Assistant to turn the lights off when I start sleep tracking and turn the lights on when either the alarm rings or I stop sleep tracking. My use case for wanting the actual next alarm time is to have the heat turn on about 30 minutes before the next alarm so the house is warmed up a bit before I get out of bed.
Well, after like 5 minutes of testing I’ve discovered it’s Tasker that’s doing the “next alarm is constantly 10 minutes in the future” and it’s apparently a known issue with how Tasker is able to wake up and do stuff while the phone’s in doze mode. When watching the entity in Home Assistant I can see as soon as I lock my phone Tasker “sets an alarm” for 10 minutes in the future and as soon as I unlock my phone Tasker “unsets the alarm” and the Sleep as Android next alarm time shows up again.
The good news is that Home Assistant is aware of this and the entity reports the package that sets the alarm so it’s possible to distinguish Tasker fake alarms from real alarms. I’m going to try making a helper entity that gets updated whenever Sleep as Android shows up as the next alarm as a workaround to always know the next real alarm time.
1 Like
I got a Home Assistant automation working to set a helper input_datetime entity only when the phone app reports the next alarm time from Sleep as Android. Since Tasker and Sleep as Android basically trade off who is reporting the Next Alarm Time to the Home Assistant app, the helper entity will be constantly updated every time I unlock my phone. This won’t really solve IcerOut’s issue of their Home Assistant app not always reporting immediate alarm time changes since they don’t have Tasker which forces the next alarm time to change a lot and always be up to date. A NEXT_ALARM intent from Sleep as Android would still be a good thing to implement to make 100% sure everyone can always know the next alarm without needing something like Tasker that accidentally fixes it in my case.
I use Node-RED instead of the builtin Home Assistant automations, but hopefully this pseudocode version of what I made helps anyone else who wants to do something similar:
State Node for when the Next Alarm time reported from the phone app changes. This node passes along the following messages:
msg.payload is the entity state which is the next alarm time in UTC
msg.data is the whole event data which includes the app that set the next alarm time
Switch Node to only keep going when “msg.data.new_state.attributes.Package == com.urbanandroid.sleep”
Date/Time Formatter Node to convert the msg.payload entity state from the UTC timestamp to unix timestamp in my local timezone
Call Service Node to set_datetime on the helper input_datetime entity with the Data {“timestamp”: payload }
Time Node on my helper entity with an offset of -30 minutes to call my existing “set daytime temperature” flow so my thermostat can warm up the house before I wake up.
1 Like
Hi,
I’d also very much like an automation to get a next alarm time.
It seems that ALARM_RESCHEDULED doesn’t work as described by @IcerOut anymore. Now it reports truly the next scheduled alarm. Tested with Home Assistant.
But I need the next alarm time to be reported to the Automate app. There is an event “Reschedule alarm” in the plug-in that gets fired, but as far as I can tell it doesn’t set any variable.
Am I missing something there?
Hi, the alarm_reschedule broadcasts two values - the new alarm time in UNIX and label (if there is a label).
Real-life example from logs:
D[28Oct 05:40:10.628, DefaultDispatcher-worker-2]: automation:trigger:webhooks: sending body: {“value1”:“1761735000000”,“value2”:“work”,“event”:“alarm_rescheduled”}
Are you talking about webhooks? Because I’m takling about Tasker/Automate Plug-in.
Hello @lenka-urbandroid , any update here?
Hello @mikulik86 here is a version of Sleep as Android which adds alarm_label and alarm_time extras to ALARM_RESHEDULED intent
https://sleep.urbandroid.org/wp-content/uploads/release/sleep-20251211-beta-release.apk
That’s not exactly the intent. Let’s think about: I have 2 alarms:
alarm “work” - on working days at 6 am AND
alarm “weekend” - on weekends at 9 am.
So during the week everyday i get an event alarm rescheduled with the timestamp of the next alarm “week” - everything works fine, as i use this information for my smart-home-integration.
BUT on fridays: still the event alarm rescheduled - timestamp here is for the alarm on next monday (this ist okay).
The next alarm rather would be on saturday at 9am (alarm “weekend”).
So it would be nice to have an event, which sends the timestamp of the very next alarm. Maybe this has to be a new event type with the following infos: value1 - timestamp of the next alarm, value2 name of the alarm. It should fire on alarm_alert_start.
Fridays: at 6 am alarm “work” fires → new event next_alarm with info value1: timestamp (here saturday 9am) and value2: “weekend”
1 Like
I have been trying everything I can think of to reliably get the information of the next alarm in Home assistant but I am unable to find a way. The thing that is missing is a Next Alarm event after an alarm is started of dismissed.
When you enable, disable or reschedule an alarm you get the info of the next alarm but when an alarm is finished you only get the new info 1hour before the next alarm.
It could also be a value of the alarm dismissed event.
Hi @Sven_van_der_Meer, the alarm_rescheduled is sent when the app is saving a new alarm time.
When the alarm starts, the app saves the next new value, so it sends the alarm_rescheduled.
So your automation should receive the intent after the alarm is started.
alarm started
I[21Apr 12:08:00.196, main]: AlarmKlaxon: ALARM START
I[21Apr 12:08:00.469, main]: automation: broadcast com.urbandroid.sleep.alarmclock.ALARM_RESCHEDULED_AUTO
When the alarm is finished, the alarm_dismiss intent is broadcast
D[21Apr 12:08:02.528, main]: AlarmAlertFullScreen: Alarm dismiss request fired due to button click
I[21Apr 12:08:02.617, main]: automation: broadcast com.urbandroid.sleep.alarmclock.ALARM_ALERT_DISMISS_AUTO
So I finally got to it and it doesn’t work.
Anyways, I’d much rather if you built it into the Tasker plugin. Could you, please?
@lenka-urbandroid thanks for clarification. But that still doesn’t solve the problem with 2 different alarms (here alarm1 on weekdays (6a.m.) and alarm2 on weekends (9 a.m.)). Like i discribed above the alarm_rescheduled message everyday comes correct, but it doesn’t give me the information of the very next alarm (Friday 6 a.m. - the alram_rescheduled message gives me the next alarm time on MONDAY, but the very next alarm ist on SATURDAY at 9 a.m……. same on sundays….) thats why i asked for a new event next_alarm with info value1: timestamp (here saturday 9am) and value2: “weekend”