Modeling a state machine in a trigger-based select-like template helper, but how?

When I was putting together examples for the Template Select Cookbook entry I tried every way I could think of to get a trigger-based version to work, but none of them were fully functional… Since it requires a triggering event to update the state, they required multiple triggers. Each additional trigger made the template more complicated and added edge cases that made it less reliable.

I ended up with the same combination that you did; a trigger-based Template sensor (for its restart resistance) with a state-based Template select (for the frontend control).

  - trigger:
      - platform: event
        event_type: custom_set_selected_window
    sensor:
      - name: Selected Window
        state: "{{ trigger.event.data.window }}"
  - select:
      - name: Window Selector
        state: "{{ states('sensor.selected_window')}}"
        options: "{{ state_attr('binary_sensor.all_window_sensors', 'entity_id') }}"
        select_option:
          - event: custom_set_selected_window
            event_data:
              window: "{{ option }}"