Sensor.next_alarm entity reverts to "unknown" state after Home Assistant restarts

Whenever my instance of Home Assistant restarts, the next_alarm state for my Android device reverts to “unknown” instead of falling back to the previous value. Since sensor.next_alarm is only updated when the alarm state changes, the state remains “unknown” until my next alarm fires or I add, remove, or change the next alarm. The only other way the state gets updated is if I open the companion app, navigate to the next_alarm state, and open it.

The issue I’m trying to solve is running an automation prior to my alarm time. I run Home Assistant as a docker on Unraid, and Unraid restarts all dockers while I’m asleep to perform it’s AppData backup. This means the next_alarm state falls back to “unkown” until my alarm goes off, and by then it’s too late.

My current workaround uses the Tasker app to run a profile at the same time each morning to 1) get my next alarm time, 2) set an alarm for 1 minute before that, 3) cancel the alarm it just set. By doing this, it gets Home Assistant to update sensor.next_alarm for my phone.

I would much prefer to get something working natively in Home Assistant so I don’t have to rely on Tasker. Is there something I can implement that forces sensor.next_alarm to hold the last value or actively get a new one after a restart? Does anyone know if this qualifies as a feature or a bug?

It should update every 15 minutes.
Sensors | Home Assistant Companion Docs (home-assistant.io)

And there is a command added, never tried it though

Add notification command to update sensors by dshokouhi · Pull Request #2194 · home-assistant/android (github.com)

And it’s also listed here:

Notification Commands | Home Assistant Companion Docs (home-assistant.io)

With this command you could create an automation to trigger on HA restart and send the command to the phone.

The Android app keeps track of the last sent state and it will not send an update if the state didn’t change so the command won’t help here.

I believe this issue is https://github.com/home-assistant/core/issues/77106

I just updated my app to the latest beta version on playstore and rebooted HA.
The sensor was unavailable for a minute or so then it came back as normal again.

@dshokouhi That indeed appears to be the issue, thanks. I wasn’t finding the issue via Google, but I didn’t think to check the GitHub.

@Hellis81 I just tried the beta app too. When I first installed it, the alarm time was updated. But when I restarted HA, next_alarm has remained “unknown” for at least 12 minutes and counting.

I have the same problem :frowning:

When I restart HA, status is unknown.
So I have to turn off & on my alarm to get the status back.

That’s because when the app version or HA core changes the app will re-register the sensors which forces a new state to show.

I updated first and had it running that way for a couple of minutes then restarted HA.

I did the same thing again:

I don’t get this behaviour, this time the alarm time was correct from when I could connect to HA again.

This appears to be fixed in version 2022.9. Even if my phone is unreachable (e.g. powered off), upon restart, the next_alarm value is still retained.