Automation with action based on variable condition doesn't seem to work

The automation below sets a variable called actiontaken to yes if an action is actually taken and not stopped by a condition.

Later on, I use this variable to determine whether or not to send a notification that something has happened, but it never sends the notification. (I have tested the notification part separately and I know this works):-

alias: Hot Water 2
description: ""
triggers:
  - trigger: state
    entity_id:
      - sensor.hot_water_level
    to: full
    id: "off"
  - trigger: state
    entity_id:
      - sensor.hot_water_level
    to: medium
    id: auto
    from: high
  - trigger: state
    entity_id:
      - sensor.hot_water_level
    to:
      - low
      - none
    id: boost
conditions: []
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - "off"
        sequence:
          - action: water_heater.set_operation_mode
            metadata: {}
            data:
              operation_mode: "off"
            target:
              entity_id: water_heater.hot_water
          - variables:
              actiontaken: "yes"
      - conditions:
          - condition: trigger
            id:
              - auto
          - condition: not
            conditions:
              - condition: state
                entity_id: water_heater.hot_water
                state: auto
        sequence:
          - action: water_heater.set_operation_mode
            metadata: {}
            data:
              operation_mode: auto
            target:
              entity_id: water_heater.hot_water
          - variables:
              actiontaken: "yes"
      - conditions:
          - condition: trigger
            id:
              - boost
        sequence:
          - if:
              - condition: time
                after: "06:30:00"
                before: "22:30:00"
              - condition: or
                conditions:
                  - condition: state
                    entity_id: input_boolean.guest_mode_override_calendar
                    state: "on"
                  - condition: state
                    entity_id: input_boolean.guest_mode_ensuite
                    state: "on"
                  - condition: state
                    entity_id: input_boolean.guest_mode_green
                    state: "on"
                  - condition: state
                    entity_id: sensor.hot_water_level
                    state: none
            then:
              - action: tado.set_water_heater_timer
                metadata: {}
                data:
                  time_period: "01:00:00"
                target:
                  entity_id: water_heater.hot_water
              - variables:
                  actiontaken: "yes"
            else:
              - action: water_heater.set_operation_mode
                metadata: {}
                data:
                  operation_mode: auto
                target:
                  entity_id: water_heater.hot_water
              - variables:
                  actiontaken: "yes"
  - if:
      - condition: template
        value_template: "{{ actiontaken == 'yes' }}"
    then:
      - data:
          title: Hot Water Alert
          message: >-
            Hot Water mode is now {{trigger.id}}. Tank heat level is
            {{states('sensor.hot_water_level')}}.
        action: notify.mobile_app_my_phone
variables:
  actiontaken: "no"
mode: single

The trace always shows the evaluation of the template to be false.
Help!

https://www.home-assistant.io/docs/scripts#scope-of-variables

@tom_l

As I typed my message, some recollection of this came into the back of my mind.

So how would I restructure this to work ? Other than having three separate notification blocks (which I could do).

Or maybe a input boolean helper ?

That would be my choice.