I still don't really understand what you are trying to do.
Is the variable Y the upper limit for your temperature comparison and X is the lower limit??
So the sort of checks you want to do are... IF temperature > Y
and another check is IF temperature < X
This is a very similar question to what you posted in...
Are you trying to incorpoarte a hysteresis effect in your control system?