if i activate or make an alarm on my phone the next alarm sensor from the home assistant app won’t recognize that there is a new alarm and it will on default go to 22:01 UTC time. Sometimes when i restart the app after i made a alarm it will detect the new alarm it but after 10 min it will just go back again to the 22:01 UTC time. When i set no alarm, it should say unavailable but it says again the 22:01 UTC time.
It looks like it is stuck on the 22:01 UTC for some reason i cannot figure out.
This is a known issue with Samsung devices as they like to override the default Android behavior for AlarmManager. We can’t do anything about it because all we are doing is grabbing the value that Android stores. Samsung needs to fix this in their own firmware. Check the package attribute for the sensor to see which app is setting the current alarm. I know that Samsung also made changes to Google Calendar for the alarm as well so it might be that.
I’m having this same issue with my S10. My automation that I set up to trigger just before my alarm kept triggering throughout the day every time a work meeting comes up in my Google Calendar.
In my case I think I will set up the automation with conditionals to only trigger when my phone is plugged in AND it’s before a certain time in the day. That should take care of most of my issues. Definitely not ideal though.
You might be able to work around this using a template sensor. Template sensors can effectively refer to themselves in their template, and you can use this to do some filtering.
This can be done in two ways.
If there is one specific package which is creating the wrong alarm times, use something like this to filter those out:
next_alarm_time:
value_template: >-
{{ states("sensor.my_phone_next_alarm") if state_attr("sensor.my_phone_next_alarm", "Package") != "the offending package name" else states("sensor.next_alarm_time") }}
If there are multiple packages doing this, then you can filter out anything other than those created by your alarm clock app by using this:
next_alarm_time:
value_template: >-
{{ states("sensor.my_phone_next_alarm") if state_attr("sensor.my_phone_next_alarm", "Package") == "package name of your alarm clock app" else states("sensor.next_alarm_time") }}
I understood it, it is only filtering of right package. But so i can not get right alarm time for example for next day.
It would be better if i could choose alarm package right in APP…
That should give you a new sensor called sensor.next_alarm_time and that’s the one you need to check (although you would need to change “sensor.my_phone_next_alarm” in the template to the entity id of your phone alarm sensor, such as “sensor.mi_mux_2s_next_alarm”).
The original sensor won’t be affected, that would still give the wrong time if the alarm was created by the calendar app).
The issue is that the API only gives us the next scheduled alarm, we can’t filter by app because then we would only get the correct time when that app has the next alarm. Now imagine if you had an app you did not care about set an alarm every 5 minutes. You would miss that event which is why filtering by package is better. You have to account for your own use cases with the data we get.
Hey, for me is the “next alarm time” doing some weird thing.
When the remaining time is above 60min, there is a time different from 1h, between the value in HA and my alarm on my phone. When the remaining time is under 60min, the different is 15min. AND is there only 15min left to the alarm, there is no (0min) different between phone and HA.
Here an example:
My “Package” is for all the 3 phases “com.android.deskclock” so there are no changes.
I am using a Xiaomi Mi9T with Android 10 and MIUI 12.0.2.
It would no problem, when I am not wanted to use this timer as a wake-up light with more than 15min time…
I think the best way is to save the “next alarm time” into a cache. But I don’t get it working
I have the exact same problem, just recorded it on video. Mine is a Mi Pad 4 Plus, with last xiaomi.eu beta ROM.
Alarm within 15 minutes, everything is fine. Between 15 and 60, it is 15 minutes earlier, over 60 minutes, it is 60 minutes earlier. Check below screencapture.
I could repeat the same on my Mi8 (11.0.6). Maybe it is a Xiaomi issue? Otherwise alarm clock works fine.
True, I can confirm my old Samsung phone is not suffering from the same issue. Using an external alarm clock solves the problem on Xiaomi devices, simply upgrading the built-in application makes no difference.
I’m trying to get something similar from SleepAsAndroid on my Xiaomi Mi 9 (Cepheus) but still unable to get the right data. When you say “use an external alarm clock” could you please elaborate? Because even with SleepAsAndroid setting the time correctly, I’m currently having a nightmare of a time with it. At this point, I’m resorting to a LogCat filter in Tasker to try and get the correct time when the alarm is set or changed. But this is far from ideal and requires a lot of javascript to parse the logcat entry.
Ideally, I just want SleepAsAndroid to just expose the next alarm time via something easy to read. But at this point, I don’t know if that’s even a possibility outside of the Alarm API the HA client is already using on Android.
Essentially exactly the same problem as the original post. The Alarm API the HA app uses always shows the com.xiaomi.calendar details, but never any of the others. Thus the whole reason I’m resorting to using LogCat in Tasker to try and get the time and send that via a webhook.