Variable in alert reversed?

Hi all, posting to get some input on some unexpected behavior in HA. I am fairly new to this, so I might not be describing this properly, but here goes:

I have an alert configured, working as expected. Here is a simplified version of the code:

alert:
    temp_low:
        name: "Temp Low"
        entity_id: binary_sensor.temp_low
        state: 'on'
        repeat: 60
        can_acknowledge: True
        title: "Temp Low"
        message: "temperature low"
        done_message: "temperature normal"
        notifiers:
          - send_email

I added a template variable to the title, like this:

 title: "Temp Low {% if states('alert.temp_low') != 'on' %}Cleared{% endif %}"

But that doesn’t work. What does work is the opposite:

 title: "Temp Low {% if states('alert.temp_low') == 'on' %}Cleared{% endif %}"

When the alert is “on” the variable matches “not on”, and when the alert is “not on” the variable matches “on”. The alert works, but the config feels backwards and wrong. Am I doing something incorrectly? Is this a bug or a race condition?

Probably because the alert state does not change until after the message is finished being sent. Use the state of your binary sensor instead.

That works, thanks. Appreciate your input!