Window opener opens window again and again due to Void loop

Arduino_Automation:
I am trying to whrite a sketch to open and close a greenhouse window based on temperature.

My problem is that when I upload the sketch to the arduino first everything seems to be working properly: If the temperature reading is above the threshold, the motor runs and opens the window and vise versa. But when the temperature stays above the threshold, the window "opens" again.

boolean window_is_open = false;

void loop() {
  if(window_is_open and it needs to be closed) {
    close it;
    window_is_open = false;
  }
  else
  if(!window_is_open and it needs to be open) {
    open it;
    window_is_open = true;
  }
}

Your next problem will be hysteresis, but hopefully this helps!