Next Alarm Sensor: Set state to "unavailable" if next alarm's app is not on allow list

Hello,

because the Next Alarm Sensor is using Androids AlarmManager it can only see the very next alarm. If the app that scheduled the next alarm is not on the allow list, this hides the next alarm of any app on the allow list that is scheduled after that. In that case I think it would be a good idea to set the state of the sensor to unavailable instead of skipping the sensor update and possibly leaving behind a wrong sensor value.

Example: Let’s say I have two apps A (my alarm clock) and B (some other app, not a real “alarm” but still using Androids AlarmManager for scheduling), and I’m only interested in the alarms from A, so only A is on the allow list.

It’s currently before 07:00, A’s next alarm is set to 07:00, B’s next alarm is 08:00. HA correctly knows that the next alarm is at 07:00.
Now I change the A’s alarm from 07:00 to 10:00 (maybe I have a day off and want to sleep in), so Androids next alarm is 08:00, but B is not on the allow list, so HA doesn’t update the next alarm sensor and leaves it at 07:00. The next alarm from A that I’m actually interested in is hidden behind the alarm from B. Because the sensor was not updated my automation still triggers at 07:00 (and turns on the lights in the bedroom).

My current workaround would be to not use the allow list and add a condition on the next alarm sensor’s package attribute in my Automation but I think having the value set to unavailable or unknown would be a cleaner approach.

This is a bad idea. Some apps set the alarm every 30 seconds. If you want to use the sensor you’ll need to stop using those apps.

Thanks for your response. Can you elaborate why this is a bad idea?
In any case other apps setting alarms will impede the next alarm with the allow list but explicity stating

I don’t know when the next alarm for your white-listed apps is, because of how Android API works

is better than

"Here’s some next alarm time, it might be right or it might be wrong. Actually I could know if it’s probably wrong but I won’t tell you."

EDIT:
Only disadvantage I could think of would be a sensor update every 30 seconds for a new “unavailable”, but I’d prefer that over automations triggering at the wrong time.