[Help] If/Else to turn lights on/off

Hi!
I wanted this trigger to do the following:

  • if light_lamp is off >> turn light_lamp on
  • else turn main_lights off

How can I do that?
The way I implemented sometimes it works and sometimes it does not, I think there is a race condition to check state of light_lamp.

    - conditions:
      - condition: template
        value_template: '{{ trigger.event.data.button_number == 3 }}'
      sequence:
      - service: light.turn_on
        data:
          kelvin: 2700
          brightness_pct: 40
        target:
          entity_id: light.master_bedroom_light_lamp
      - condition: state
        entity_id: light.master_bedroom_light_lamp
        state: 'on'
      - service: light.turn_off
        target:
          entity_id: light.master_bedroom_main_lights

Use a choose: