Template with Trigger.entity_id and Wait template

Hello, I am trying to do the following automation. I know is possible with the Alert componenet but in my real use case I have many entity_ids I will be monitoring.

What I would like to do is have a message sent when the state is on for more than five minutes. This all works. What does not work is when after it has been on for 5 minutes and set to off I want another message saying it was turned off.

It does not appear that the trigger.entity_id works correctly in the wait: is_state command.

- alias: Test - Send Message when input boolean change
  initial_state: 'on'
  trigger:
    - platform: state
      entity_id: input_boolean.test
      from: 'off'
      to: 'on'
      for:
        minutes: 5
  action:
    -  service: persistent_notification.create
       data_template:
         title: "Before"
         message: >
          "the switch has been on for over 5 minutes"
    - wait_template: "{{is_state(trigger.entity_id,'off')}}"
    -  service: persistent_notification.create
       data_template:
         title: "Input is no off."
         message: >
          "you can sleep now that the switch is off"

I figured out this works.

- wait_template: >
   {% set new = trigger.entity_id %}
   {{ is_state(new, 'off') }}