Android Alarm Clock triggers without an Alarm being set

Hello everyone,

I am new to HA and would like to make the alarm clock of my Android phone turn on my coffee machine when I am about to get up in the morning.

For the trigger I created a template that looks like this:

{{ now().strftime("%a %h %d %H:%M %Z %Y") == (((state_attr("sensor.mysmartphone_nachster_wecker", "Time in Milliseconds") | int / 1000) - 1*60 ) | timestamp_custom("%a %h %d %H:%M %Z %Y")) }}

This works as expected: About one minute before my alarm clock rings, the coffee machine turns on. But there is one problem:

As soon as the alarm starts, the phone reports a new set alarm time which seems to be a random full hour in the future (same day). Lets say I set my alarm clock to 6 am, this will turn on my coffee machine at about 5:59 am. Then my phone reports a new set alarm time like 12 am which causes my coffee machine to turn on again at about 11:59 am. That’s obviously not what I want.
To be clear: No other alarm is set when this happens.

Why does the alarm sensor set another alarm when there is none set?

Thanks in advance!


What are the state and attributes of sensor.mysmartphone_nachster_wecker?

The states and attributes I check are the correct ones, I think.

What I found now is that if i set an alarm on the phone, the states and attributes are set by
When the alarm rings, the new (kind of random) time is being set by com.xiaomi.calender.

So now I obviously tried to fix the issue by limiting the sensor to
But this results in another issue: When I deactivate the alarm clock, the sensor stays unchanged. So let’s say I set an alarm clock for 10 am and then deactivate it, the routine will still be triggered.

The sensor does not seem to have a state like “active” or something similar!?

Did you wait a little while?
The state change is not instantaneous. The app must send an update to HA…

If there is no alarms, the state of the entity is set to “unavailable”

Unfortunately the state does not change. It stays at the previous value if I disable the alarm clock and allow only.
I can see this in the sensor setting of the phone app.

And now another issue occured out of nowhere… The state of the sensor shows a time 15 minutes before the set alarm. This never happened before. Really strange behavior.

Known issue with Xiaomi apparently.
Googling for com.xiaomi.calender next alarm brings quite some results.

Next Alarm comes directly from Android ( AlarmManager | Android Developers), so I assume the app devs can do nothing about it.

If you’re actually using the Xiami calendar, I don’t see a solution.
If you’re not, disable the app on your phone.

Well, this is not the main issue. I can restrict the sensor to receive events from only. This way it will ignore everything sent by com.xiaomi.calendar.

But as I said the problem is that does not reset the state when I disable the alarm. Additionally the strange -15min offset occured (see my last post). That’s so strange. Maybe using another calendar app could fix it. Worth a try at least.

There is no “reset the state”.
Even If you blacklisted the xiaomi calendar in the HA app, the actual “next alarm” is still the xiaomi one, just that the HA app does not notify about those.

What you could do is, in your automation, just ignore the “next alarm” if it comes from com.xiaomi.calender. Leave the HA android app default (the 15 min could still come from xiaomi)

For your morning routine, after midnight, the next alarm will be your waking one.

Ah, that’s an awesome idea. I added another condition to the automation whichs checks if the attribute “Package” is “”. This should prevent the routine from being fired by the xiaomi calendar.
I found that the -15 min offset only occurs if the set alarm is more that 15 minutes in the future. Now I have to check if it is changed automatically and early enough to not trigger the routine.

Okay, so the -15 min offset comes from, not from xiaomi.
If I set an alarm for let’s say 8am, the state is being set to 7:45am. Then at 7:45am it jumps to about 7:52:30am and at 7:52:30am it is finally being set to 8am. I don’t know why it behaves like this. Seems to be some kind of procedure that allows the phone to trigger events when an alarm is about to go off.

This obviously prevents me from using this alarm since all the events are coming from and the routine would be triggered 15 minutes early.

I switched to Alarmy as my alarm clock app and restricted the sensor to use its package (droom.sleepIfUCan) only. Works like a charm. Too bad that the integrated alarm won’t work but at least this workaround does.