int state = 0;
...
if (difference > deviation){ //only turn on if both the temp is too high AND there has been an appropriate delay between the last initiation of off cycle
digitalWrite(compressorRelay, HIGH);
int state = 1;
}
The two "state" variables here are different variables. Putting "int" there inside the "if" creates a local state variable, different from the global one. Lose the "int" there.