Window Controller Software-New to programming

Hello
I might be in a little over my head here by making this my first programming project on the Arduino but I want to try to make it work.

First of all, what I am doing is automating my window in my dorm. I am using a DC motor and gearbox system that I am in the progress of installing. The Arduino will be contorolling this with two outputs, one to turn on the transistor to active the motor and one that will turn on a relay to switch the motor polarity to open the window. (Ex: Transistor+Relay=Window Open, Just transistor=Window Close)

I will be mounting the Arduino in a box with 2 switches, a thermostat, and two buttons with LEDs. The switches allow me to manually override the motor. These are not going to be wired to the Arduino and will instead act as a way to override the Arduino output in case of a failure. The thermostat will just provide an input when I want the window to be open. I found that this would be simpler since I wont need to use a thermocouple and instead just use the thermostat cooling output. I was planning on adding a relay as well to control a heater. Finally, the two buttons will be labeled Open/Close and will tell the Arduino to run the motor open or closed manually if I just want to quickly adjust the window yet let the Arduino still control it. Also, the LEDs in the buttons will give supposed status. When the Window is closed, the LED on the closed button will be lit, and when the window is open, the open LED will be lit.

Overall this is what I want to get to but for now I at least want to get the Arduino working to just open/close the window. A quick note is that while I have a switch on the window to tell the Arduino when the window is closed, I dont think I need it since on this setup stalling the motor for a few seconds to guarantee the window is open/closed wont really hurt anything.

Here is the code I was working on based off some of the examples. Once again, I am new to code so its kind of messy and I am open to comments on how to fix it. Anyway, I was writing it and I realized that every time the code loops it will keep opening or closing the window continuously. I then realized that I needed to make the Ardunio remember what state it currently is in. I was looking at other example codes to do this such as the LED code to toggle states but I am having trouble understanding this. My code is below

int motor = 3;                // choose the pin for the LED
int relay = 4;                //Reverse Relay for motor to open window
int openlt = 5;               //Light on open button
int closelt = 6;              //Light on close button
int thermo = 2;               //Thermostat input
int valthermo = 0;            // Thermostat Variable
int valopen = 0;              //Value for Open LED
int valclose = 0;             //Value for Close LED
int status = 0;

void setup() {
  pinMode(motor, OUTPUT);      // declare LED as output
  pinMode(relay, OUTPUT);      // declare LED as output
  pinMode(openlt, OUTPUT);      // declare LED as output
  pinMode(closelt, OUTPUT);      // declare LED as output
  pinMode(thermo, INPUT);     // declare pushbutton as input
}

void loop(){
  valthermo = digitalRead(inputPin);  // read the thermo value
  if (valthermo == HIGH and status == 0) {   // check if the input is HIGH
    digitalWrite(relay, HIGH);  // Sets motor relay to open
    digitalWrite(motor, HIGH);  // turns on motor
    delay(1000);
    digitalWrite(motor, LOW);  // turn motor off
    digitalWrite(relay, LOW);  // turns relay back to close mode
  } else {
    digitalWrite(relay, LOW);  // Makes sure motor relay is closed
    digitalWrite(motor, HIGH);  // turns on motor
    delay(1000);
    digitalWrite(motor, LOW);  // turn motor off
    digitalWrite(relay, LOW);  // turns relay is still closed. 
  }
}

Overall any help would be great. Currently I am building the hardware so I cannot actually test the system besides hooking LEDs to the Arduino. Also, as I said, I am new to the Arduino and while I could have done this project with analog equipment rather easily, I wanted to give the Arduino a try.