How to Cancel Automation if trigger has not changed (input select)

I have an automation that I want to run if an input select is changed. It works fine. Sometimes I change the input select and then change my mind, and change it back to where it was to begin with. Ultimately the states have “changed” but they are now the same as when I started. I tried adding a 30 second delay, thinking that would do it, but of course that just delayed the action.

Looking for suggestions on how to accomplish this.

Example
Input select starts as “disarmed” changed to “Armed” then 2 seconds later set back to “disarmed”. I’d like nothing to happen.

Thanks in advance

Have your automation call a script to do the work.
When the input boolean is turned off you can stop the script.

I am using an input select. but maybe can accomplish the same thing with a script. Only “issue” is that I should have provided more details. I have a lot of input selects as well as input booleans that trigger the automation. Based on the select or boolean different things happen. Here is the automation

  - alias: Keypad switch turned on (Front Door)
    initial_state: true
    trigger:
      - platform: state
        to: 'on'
        for:
          seconds: 30
        entity_id:
# Entities need to be named to match your lock name.  In this case front
          - input_boolean.door_keypad_1_front_switch
          - input_boolean.door_keypad_2_front_switch
          - input_boolean.door_keypad_3_front_switch
          - input_boolean.door_keypad_4_front_switch
          - input_boolean.door_keypad_5_front_switch
          - input_boolean.door_keypad_6_front_switch
          - input_boolean.door_keypad_7_front_switch
          - input_boolean.door_keypad_8_front_switch
          - input_boolean.door_keypad_9_front_switch
          - input_boolean.door_keypad_10_front_switch
          - input_boolean.door_keypad_11_front_switch
          - input_boolean.door_keypad_12_front_switch
          - input_boolean.door_keypad_13_front_switch
          - input_boolean.door_keypad_14_front_switch
          - input_boolean.door_keypad_15_front_switch
          - input_boolean.door_keypad_16_front_switch
          - input_boolean.door_keypad_17_front_switch
          - input_boolean.door_keypad_18_front_switch
      - platform: state
        to: 'Always'
        for:
          seconds: 30
        entity_id:
          - input_select.door_keypad_1_access_schedule
          - input_select.door_keypad_2_access_schedule
          - input_select.door_keypad_3_access_schedule
          - input_select.door_keypad_4_access_schedule
          - input_select.door_keypad_5_access_schedule
          - input_select.door_keypad_6_access_schedule
          - input_select.door_keypad_7_access_schedule
          - input_select.door_keypad_8_access_schedule
          - input_select.door_keypad_9_access_schedule
          - input_select.door_keypad_10_access_schedule
          - input_select.door_keypad_11_access_schedule
          - input_select.door_keypad_12_access_schedule
          - input_select.door_keypad_13_access_schedule
          - input_select.door_keypad_14_access_schedule
          - input_select.door_keypad_15_access_schedule
          
    condition:
      - condition: template
        value_template:  >-
          {% set object_id = trigger.to_state.object_id %}
          {% set code_slot = "_".join(object_id.split("_")[2:-2]) %}
          {% set select_id = 'door_keypad_' ~ code_slot ~ '_access_schedule' %}
          {% set calendar_id = 'lock_code_' ~ code_slot ~ '_schedule' %}
          {{ (states['input_select'][select_id].state in ['Always', 'Enabled']) or (states['input_select'][select_id].state == 'Scheduled' and states['calendar'][calendar_id].state == 'on') }}
      - condition: template
        value_template:  >-
          {% set object_id = trigger.to_state.object_id %}
          {% set code_slot = "_".join(object_id.split("_")[2:-2]) %}
          {% set select_id = 'door_keypad_' ~ code_slot ~ '_front_switch' %}
          {{ (states['input_boolean'][select_id].state == 'on')}}
      - condition: state
        entity_id: 'input_boolean.allow_zwave_automation_execution'
        state: 'on' 
    action:
      - service: lock.set_usercode
        data_template:
          node_id: >-
            {{ states.lock.front_door.attributes.node_id }}
            
          code_slot: >-
            {% set object_id = trigger.to_state.object_id %}
            {% set code_slot = "_".join(object_id.split("_")[2:-2]) %}
            {{ code_slot }}

          usercode: >-
            {% set object_id = trigger.to_state.object_id %}
            {% set code_slot = "_".join(object_id.split("_")[2:-2]) %}
            {% set user_code_id = 'door_keypad_' ~ code_slot ~ '_code' %}
            {{ states['input_text'][user_code_id].state }}
            
      - service: notify.pushover
        data_template:
          message: >-
            {% set object_id = trigger.to_state.object_id %}
            {% set code_slot = object_id[7:-18] %}
            {% set usercode_input = 'door_keypad_' ~ code_slot ~ '_code' %}
            {% set usercode = states['input_text'][usercode_input].state %}
            {% set name_input = 'door_keypad_' ~ code_slot ~ '_name' %}
            {% set name = states['input_text'][name_input].state %}
            The user code is now enabled for {{ name }}.

          title: >-
            Code enabled on Front Door
          target:
          - Paul

Of course like mentioned above the 30 second delay really does not work, so I’ll be removing that.
The input boolean turning on or the schedule changing trigger loading the code into my lock. Works great just runs too much if you are messing around.

Might have been too quick to ask, but for others in the future I think I got it using a “cool down” timer. Still testing, but the concept is when the state changes away from the trigger state to start a short timer. Then set the timer being idle as a condition in the automation. Once I have it down, I’ll post for reference.