WTH, why don't (some) alerts alert on startup?

When HA starts/restarts, alerts sometimes don’t fire if the monitored state is already set. It seems like there is a race condition between the alert integration loading and the monitored state getting set - if the monitored state for the alert is set first, then when the alert integration loads no alert is fired.

This leads to some unexpected situations where I’d expect an alert to be firing, but it is not, and the only difference seems to be whether or not the monitored state was already set at startup or if it changed later.

One example is an alert based on an input_select. If the input_select changes while HA is running, the alert fires. But if HA is restarted after the input_select enters the alert condition, the alert does not fire when HA starts up - it instead shows as idle.

Here’s a gif of that alert after startup (idle when it should be on) vs after I manually re-trigger the state change. The alert condition is that scan status is offline.

alerts

See also:

PS: Thanks for HA, it is amazing! And thanks for running a “WTH” month :slight_smile:

Hi - you may want to take a look at Alert2. It has a parameter, early_start, that let’s you alert as HA is starting.
Alert2 has a different startup process than Alert, and I’d hope it doesn’t ever let you end up in a state where an alert condition is true but the alert isn’t firing.

I’m not sure how Alert handles startup and races such as you mention.