That is not very complicated, all you have to do is the following:
You must take into account if the output is on or off before doing your comparison which switches the output on or off.
Here are the two examples for switching on or off:
If your output is currently off, compare your analog value with a reference value slightly higher than you are currently using to switch the output on otherwise do not change the output.
If your output is currently on, compare your analog value with a reference value slightly lower than you are currently using to switch the output off otherwise do not change the output.
The difference in on and off reference value is called hysteresis ...
hope this helps, best regards