Manual alarm armed state before "pending" or "triggered"

When coding automations for the Manual alarm, I’d like to know what the armed state was or will be while in one of the other alarm states (arming, pending, triggered).

For example, when in the “arming” state an automation might want to do something different (or not at all) depending on the armed state that the alarm is transitioning to. But since the alarm state can only have one value at a time I can’t find a way to know what I want to know.

I suppose that once the alarm enters one of the armed states I could set a variable, but that won’t help me in the “arming” state.

Any ideas?

You can eliminate one. “Triggered” implies the the alarm was previously “armed”.

If you are using automations you can get the current and previous state using trigger variables, e.g.

trigger:
  platform: state
  entity_id: alarm.your_alarm
action:
  service: persistent_notification.create
  data:
    message: "Alarm state was {{ trigger.from_state.state }} and is now {{ trigger.to_state.state }} "

Thanks for your reply Tom. I hadn’t considered the trigger.from_state.state.

Unfortunately, the “triggered” state is actually the hardest one of all because the from_state is “pending”. Who knows which armed state it was before “pending” when you are in the “triggered” state.

My solution was to reluctantly create a helper variable that I set when in the armed states and I refer to that when I need to.

Ah I see. Yeah if you want the state prior to the pending state you are going to have to record it yourself.

Hello,
I also have the same need to adjust the volume of my siren.
I tried the following code without success :

- action:
    data:
      payload: >
        '{"warning": {"mode": "police_panic", "level": "
        {% if is_state_attr("alarm_control_panel.alarm", "from_state", "armed_home") -%}
          low
        {% else -%}
          high
        {% endif -%}"}}'
      topic: Siren/set
    service: mqtt.publish

How does HA save the nominal state to restore it when disarm_after_trigger is false ? (state and from_state are not the right attributes)