Problems Yaml file nested if statem

the keypad text made with matrix keypad does control 2 lights 1 red en one yellow if keypad is “1234” red light toggles and if keypad is “4567” yellow light(geellicht) supposed to toggle on or off. But code wont validate and i get this message:

ERROR Error while reading config: Invalid YAML syntax:

mapping values are not allowed here

and it refers to second if under first else. Can anyone help here im not that good in yaml

text_sensor:
  - platform: template
    name: Keypad
    id: keypad
    lambda: |-
      return {"------"};
      
    on_value:
      then:
         - if:
            condition:
                # pincode codes for buitenalarm
              - text_sensor.state:
                id: keypad
                state: '1234'
            then:
                - switch.turn_on: buzzer1
                - delay: 1s
                - switch.turn_off: buzzer1
                - delay: 1s
                - switch.turn_on: buzzer1
                - delay: 1s
                - switch.turn_off: buzzer1
                - light.toggle: roodlicht
              
            else:
              - if: 
                  condition
                    - text_sensor.state:
                      id: keypad
                      state: '45678'
                  then: 
                     - switch.turn_on: buzzer1
                     - delay: 1s
                     - switch.turn_off: buzzer1
                     - delay: 1s
                     - switch.turn_on: buzzer1
                     - delay: 1s
                     - switch.turn_off: buzzer1
                     - light.toggle: geellicht
                  else:  
                    - if:
                        condition:
                         - text_sensor.state:
                           id: keypad
                           state: '------' 
                  then:
        
                  else:
                    - repeat:
                       count: 3
                       then:
                          - switch.turn_on: buzzer1
                          - delay: 500ms
                          - switch.turn_off: buzzer1
                          - delay: 500ms
...

Only half your config is formatted correctly for the forum.

how come ? how i format config ?

It’s late at night here so brain is at half function - but is the indentation of this section correct? Remember with yaml indentation es everything when it comes to syntax.

…and everywhere on your code where you have

then:
    - dosomething

should be:

then:
  - dosomething