PIN code with 4 buttons wireless switch

Hi !
I’m trying to create an automation wich recognize a pin code when I press buttons of my 4-button switch in a specific order.
The purpose is to be able ton stop my system alarm alert by pressing a combination of buttons on my switch.
My idea is to keep track of buttons I push in an input_text.
And to be able to know if it worked when I pushed a button, I want my Google Home to say something.
So, just for the beginning of my combination, with just button 1 (state 1_single) and button 2 (state 2_single), here is my conf :

- alias: "Button 1"
  trigger:
    - platform: state
      entity_id: sensor.switch_alert_action
      to: '1_single'
  action:
    - delay: "00:00:01"
    - service: input_text.set_value
      target:
        entity_id: input_text.alert_sequence
      data:
        value: "1"
    - service: tts.speak
      data:
        cache: true
        media_player_entity_id: media_player.musique_salon
        message: "Button one"
        language: fr
      target:
        entity_id: tts.google_en_com


- alias: "Button 2 after 1"
  trigger:
    - platform: state
      entity_id: sensor.switch_alert_action
      to: '2_single'
  condition:
    - condition: template
      value_template: "{{ states('input_text.alert_sequence') == '1' }}"
  action:
    - delay: "00:00:01"
    - service: input_text.set_value
      target:
        entity_id: input_text.alert_sequence
      data:
        value: "{{ states('input_text.alert_sequence') + '2' }}"
    - service: tts.speak
      data:
        cache: true
        media_player_entity_id: media_player.musique_salon
        message: "Button two after one"
        language: fr
      target:
        entity_id: tts.google_en_com

- alias: "Button 2 not after 1"
  trigger:
    - platform: state
      entity_id: sensor.switch_alert_action
      to: '2_single'
  condition:
    - condition: template
      value_template: "{{ states('input_text.alert_sequence') != '1' }}"
  action:
    - delay: "00:00:01"
    - service: input_text.set_value
      target:
        entity_id: input_text.alert_sequence
      data:
        value: ""
    - service: tts.speak
      data:
        cache: true
        media_player_entity_id: media_player.musique_salon
        message: "Button two not after one"
        language: fr
      target:
        entity_id: tts.google_en_com

It almost work… only problem is, when I push button 2 after button 1, I know it triggers the “Button 2 after 1” automation because input_text.alert_sequence get “12” as value, but my Google Home doesn’t say “Button two after one”.
Whereas when I push button 2 when I already pushed button 2, input_text.alert_sequence take “” as value and Google Home says “Button two not after one”.
I really don’t understand why the - service: tts.speak works for one automation and not for the other.

I can’t help you with why your speaker doesn’t speak but perhaps a simpler way to do the automation is to use wait for trigger.
With the wait for trigger you can do it all in one automation.

triggger:
  '1_single'
action
  wait_for_trigger:
    '2_single'
     wait_for_trigger:
       '3_single'

and so on.
This way you don’t even need the input text.
And as soon as the timeout time runs out the “memory” is cleared by itself.

Thanks for your reply. I tried with this but doesn’t work (I keep my input_text.set_value and tts.speak service to track If the 1, 2, 3 sequence works but Google Home doesn’t speak and input_text.alert_sequence value doesn’t change to “123” even if I can see that 1_single, 2_single and 3_single have been consecutively pushed in de logs) :

- alias: "Sequences 1, 2 and 3"
  trigger:
    - platform: state
      entity_id: sensor.switch_alert_action
      to: '1_single'
  action:
    - wait_for_trigger:
        - platform: state
          entity_id: sensor.switch_alert_action
          to: '2_single'
          timeout: '00:01:00'
      continue_on_timeout: false
    - wait_for_trigger:
        - platform: state
          entity_id: sensor.switch_alert_action
          to: '3_single'
          timeout: '00:01:00'
      continue_on_timeout: false
    - service: input_text.set_value
      target:
        entity_id: input_text.alert_sequence
      data:
        value: "123"
    - service: tts.speak
      data:
        cache: true
        media_player_entity_id: media_player.musique_salon
        message: "Button one two three"
        language: fr
      target:
        entity_id: tts.google_en_com

For the button 2 automation, I also try to replace the 2 automations by one, using “choose” like this :

- alias: "Button 2"
  trigger:
    - platform: state
      entity_id: sensor.switch_alert_action
      to: '2_single'
  action:
    - choose:
        - conditions:
            - condition: template
              value_template: "{{ states('input_text.alert_sequence') == '1' }}"
          sequence:
            - service: input_text.set_value
              target:
                entity_id: input_text.alert_sequence
              data:
                value: "{{ states('input_text.alert_sequence') + '2' }}"
            - service: tts.speak
              data:
                cache: true
                media_player_entity_id: media_player.musique_salon
                message: "Bouton deux apres un"
                language: fr
              target:
                entity_id: tts.google_en_com
        - conditions:
            - condition: template
              value_template: "{{ states('input_text.alert_sequence') != '1' }}"
          sequence:
            - service: input_text.set_value
              target:
                entity_id: input_text.alert_sequence
              data:
                value: ""
            - service: tts.speak
              data:
                cache: true
                media_player_entity_id: media_player.musique_salon
                message: "Bouton deux pas apres un"
                language: fr
              target:
                entity_id: tts.google_en_com

But I have exactly the same behavior as my first problem (Google Home doesn’t speak when “Button 2 after 1” automation triggers

You have one second timeout.
What happens if you set it to 5 or 10?

What does the traces show?

Hmmm, I think ‘00:01:00’ is 1 minute timeout, not 1 second ; am I wrong ?

What traces should I look at ?

You are right!
But what does the traces show? Why is the automation not following through?