OnTriggerEnter/Exit are firing too quickly and changing my boolean?

I’m trying to make a switch so that when a player moves through a trigger it performs an action depending on whether a boolean is true or false, and then it sets that boolean to the opposite value to perform a DIFFERENT action upon reentering the trigger. Imagine a light switch that activates when the player runs by the switch, but then if the player leaves the trigger area and returns running through would deactivate the light because the boolean was now different.

When I try to do this it sets the value of lightIsOn (or whatever) to true if it is false, and then it quickly performs the false operation and results in nothing happening. So basically, I want to only call OnTriggerEnter when FIRST entering the trigger area.

You can try…

    bool canSwitch = true;
    bool lightsOn = false;
    
    void OnTriggerEnter()
    {
    if(canSwitch && !lightsOn)
    {
     //turn lights on
     canSwitch = false; //change boolean to false
    }
    else if(canSwitch && lightsOn)
    {
     //turn lights off
    }

    }
    
    void OnTriggerExit()
    {
    
       StartCoroutine("DelayTimer");
    }
    
    IEnumerator DelayTimer()
    {
      yield return new WaitForSeconds(1f); //or how many seconds you want it to be
    canSwitch = true; //change to true
    }

if correct pls mark as answer
Warning: It is different script for Java, this is C#