Turning switch state at two different voltage
First let's fix your diagram.



Figure 1. Required schmitt trigger operation. Output turns high when green level exceeded. Output turns low when less than red level.

There are many Schmitt trigger calculators available online such as one by Random Science Tools.
Note that there are inverting and non-inverting versions. The inverting