How to prevent automation triggering on timer cancel

I have a script that manages lights based on motion sensors and timers. Sometimes I want to fix the lights to a certain scene.

I have scenes including scene.hall_off, scene_hall_walk_in, scene.hall_on

There is a script to activate scene_on and cancel any active timer, but the automation triggers regardless of the timer finishing or being cancelled.

Script to turn lights full on

alias: Hall lights on
sequence:
  - action: scene.turn_on
    target:
      entity_id: scene.hall_on
    data: {}
  - action: input_text.set_value
    target:
      entity_id: input_text.hallway_last_scene
    data:
      value: scene.hall_on
  - action: timer.cancel
    target:
      entity_id: timer.hall_occupancy
description: Turn on all hall lights via call.
mode: restart

Automation to trigger lighting based on motion and a timer to turn them off again

alias: Hall presence lighting 2
description: ""
triggers:
  - type: motion
    device_id: 6297e13b7c90434514289507251c4256
    entity_id: bd6c24034bb0f2631a33034216f8d418
    domain: binary_sensor
    trigger: device
    id: Hall motion detected
  - type: motion
    device_id: bedc13d15aba46e3a526c9f47228ecb9
    entity_id: 8ef036aec7aa0d2541c53e46ab196614
    domain: binary_sensor
    trigger: device
    id: Landing motion detected
  - trigger: state
    entity_id:
      - input_boolean.hall_virtual_motion_trigger
    to: "on"
    id: Virtual Trigger On
  - trigger: state
    entity_id:
      - timer.hall_occupancy
    to: idle
    id: Timer ended
  - trigger: state
    entity_id:
      - input_button.hall_turn_off_lights
    id: Turn off requested
  - trigger: time_pattern
    minutes: /10
    id: Regular check
conditions: []
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - Timer ended
          - condition: state
            entity_id: timer.hall_occupancy
            state: active
        sequence:
          - action: input_text.set_value
            metadata: {}
            data:
              value: scene.hall_off
            target:
              entity_id: input_text.hall_last_scene
          - action: scene.turn_on
            metadata: {}
            target:
              entity_id: scene.hall_off
      - conditions:
          - condition: and
            conditions:
              - condition: trigger
                id:
                  - Virtual Trigger On
                  - Hall motion detected
                  - Landing motion detected
              - condition: time
                after: "22:50:00"
                before: "06:00:00"
        sequence:
          - action: scene.turn_on
            metadata: {}
            target:
              entity_id: scene.hall_walk_in_night
          - action: input_text.set_value
            metadata: {}
            data:
              value: scene.hall_walk_in_night
            target:
              entity_id: input_text.hall_last_scene
          - action: timer.start
            target:
              entity_id: timer.hall_occupancy
            data:
              duration: "00:07:30"
          - delay:
              hours: 0
              minutes: 0
              seconds: 2
              milliseconds: 0
          - action: input_boolean.turn_off
            metadata: {}
            data: {}
            target:
              entity_id: input_boolean.hall_virtual_motion_trigger
        alias: Motion at night
      - conditions:
          - condition: and
            conditions:
              - condition: trigger
                id:
                  - Virtual Trigger On
                  - Hall motion detected
                  - Landing motion detected
              - condition: or
                conditions:
                  - condition: state
                    entity_id: input_text.hall_last_scene
                    state: scene.hall_off
                  - condition: state
                    entity_id: input_text.hall_last_scene
                    state: scene.hall_walk_in
                  - condition: state
                    entity_id: input_text.hall_last_scene
                    state: scene.hall_walk_in_night
        sequence:
          - action: scene.turn_on
            metadata: {}
            target:
              entity_id: scene.hall_walk_in
          - action: input_text.set_value
            metadata: {}
            data:
              value: scene.hall_walk_in
            target:
              entity_id: input_text.hall_last_scene
          - action: timer.start
            target:
              entity_id: timer.hall_occupancy
            data:
              duration: "00:07:30"
          - delay:
              hours: 0
              minutes: 0
              seconds: 2
              milliseconds: 0
          - action: input_boolean.turn_off
            metadata: {}
            data: {}
            target:
              entity_id: input_boolean.hall_virtual_motion_trigger
        alias: Motion
      - conditions:
          - condition: trigger
            id:
              - Turn off requested
        sequence:
          - action: timer.finish
            metadata: {}
            data: {}
            target:
              entity_id: timer.hall_occupancy
      - conditions:
          - condition: trigger
            id:
              - Regular check
        sequence:
          - if:
              - condition: and
                conditions:
                  - condition: template
                    value_template: >-
                      {{ states('input_text.hall_last_scene') ==
                      'scene.hall_off' }}
              - condition: device
                type: is_on
                device_id: 3671228319ab05e9415cec4d0fce55d6
                entity_id: 2e30c9aaccae41493c28da8df46ce6b0
                domain: light
                alias: but a light is still on
            then:
              - action: scene.turn_on
                metadata: {}
                target:
                  entity_id: scene.hall_off
mode: restart

When I manually run the script, the timer ended trigger is fired.
In the docs: Timer - Home Assistant

I think I want to use timer.finished but can’t see how to do that.

I finally got it working

alias: Hall presence lighting 2
description: ""
triggers:
  - type: motion
    device_id: 6297e13b7c90434514289507251c4256
    entity_id: bd6c24034bb0f2631a33034216f8d418
    domain: binary_sensor
    trigger: device
    id: Hall motion detected
  - type: motion
    device_id: bedc13d15aba46e3a526c9f47228ecb9
    entity_id: 8ef036aec7aa0d2541c53e46ab196614
    domain: binary_sensor
    trigger: device
    id: Landing motion detected
  - trigger: state
    entity_id:
      - input_boolean.hall_virtual_motion_trigger
    to: "on"
    id: Virtual Trigger On
  - trigger: event
    event_type: timer.cancelled
    event_data:
      entity_id: timer.hallway_occupancy
    id: Timer Cancelled
  - trigger: event
    event_type: timer.finished
    event_data:
      entity_id: timer.hallway_occupancy
    id: Timer Finished
  - trigger: state
    entity_id:
      - input_button.hall_turn_off_lights
    id: Turn off requested
  - trigger: time_pattern
    minutes: /10
    id: Regular check
conditions: []
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - Timer finished
          - condition: state
            entity_id: timer.hall_occupancy
            state: active
        sequence:
          - action: input_text.set_value
            metadata: {}
            data:
              value: scene.hall_off
            target:
              entity_id: input_text.hall_last_scene
          - action: scene.turn_on
            metadata: {}
            target:
              entity_id: scene.hall_off
      - conditions:
          - condition: and
            conditions:
              - condition: trigger
                id:
                  - Virtual Trigger On
                  - Hall motion detected
                  - Landing motion detected
              - condition: time
                after: "22:50:00"
                before: "06:00:00"
        sequence:
          - action: scene.turn_on
            metadata: {}
            target:
              entity_id: scene.hall_walk_in_night
          - action: input_text.set_value
            metadata: {}
            data:
              value: scene.hall_walk_in_night
            target:
              entity_id: input_text.hall_last_scene
          - action: timer.start
            target:
              entity_id: timer.hall_occupancy
            data:
              duration: "00:07:30"
          - delay:
              hours: 0
              minutes: 0
              seconds: 2
              milliseconds: 0
          - action: input_boolean.turn_off
            metadata: {}
            data: {}
            target:
              entity_id: input_boolean.hall_virtual_motion_trigger
        alias: Motion at night
      - conditions:
          - condition: and
            conditions:
              - condition: trigger
                id:
                  - Virtual Trigger On
                  - Hall motion detected
                  - Landing motion detected
              - condition: or
                conditions:
                  - condition: state
                    entity_id: input_text.hall_last_scene
                    state: scene.hall_off
                  - condition: state
                    entity_id: input_text.hall_last_scene
                    state: scene.hall_walk_in
                  - condition: state
                    entity_id: input_text.hall_last_scene
                    state: scene.hall_walk_in_night
        sequence:
          - action: scene.turn_on
            metadata: {}
            target:
              entity_id: scene.hall_walk_in
          - action: input_text.set_value
            metadata: {}
            data:
              value: scene.hall_walk_in
            target:
              entity_id: input_text.hall_last_scene
          - action: timer.start
            target:
              entity_id: timer.hall_occupancy
            data:
              duration: "00:07:30"
          - delay:
              hours: 0
              minutes: 0
              seconds: 2
              milliseconds: 0
          - action: input_boolean.turn_off
            metadata: {}
            data: {}
            target:
              entity_id: input_boolean.hall_virtual_motion_trigger
        alias: Motion
      - conditions:
          - condition: trigger
            id:
              - Turn off requested
        sequence:
          - action: timer.finish
            metadata: {}
            data: {}
            target:
              entity_id: timer.hall_occupancy
      - conditions:
          - condition: trigger
            id:
              - Regular check
        sequence:
          - if:
              - condition: and
                conditions:
                  - condition: template
                    value_template: >-
                      {{ states('input_text.hall_last_scene') ==
                      'scene.hall_off' }}
              - condition: device
                type: is_on
                device_id: 3671228319ab05e9415cec4d0fce55d6
                entity_id: 2e30c9aaccae41493c28da8df46ce6b0
                domain: light
                alias: but a light is still on
            then:
              - action: scene.turn_on
                metadata: {}
                target:
                  entity_id: scene.hall_off
mode: restart

trigger:state needs to change to trigger:event. I could not see how do find a trigger event entry when using the UI though. I think some auto complete function is missing for this action.