Ventilation Robot Servo

I agree with PaulS, is more easy if you create a functions to open and close the window, and replace the "while for a "if", i did a similar project but instead of temperature it was light

Here the code i that i used, i guess it can be easy modified to work with temperature, and controlling a servo

// Pins
int sensorPin = 0;
int lightPin = 3;

// Variables
int lightState = 0;
int lowThreshold = 250;
int highTreshold = 35;

void setup() {
  
  // Start Serial & set pin to output  
  Serial.begin(9600);
  pinMode(lightPin,OUTPUT);
  
}

void loop() {

  // Read the sensor pin
  int sensorValue = analogRead(sensorPin);

  // If light level is low is detected, switch light on
  if (sensorValue < lowThreshold){
    digitalWrite(lightPin, HIGH);
  }
  
  // If light level goes up again, switch the lights off
  if (sensorValue > highTreshold){ 
    digitalWrite(lightPin, LOW);
  }
}