n8thano:
I just cannot find the right route to take when writing the code.
Understand what you want the code to do.
Divide it up into simple tasks that are capable of being implemented independently. For example: for each external device you need to interact with, you need to know how to interface with it.
Have you figured out how to connect the temperature sensor? Can you get an accurate temperature reading from it? Have you figured out how to connect to the solenoid/valve? Can you switch the valve to each position that you need it to switch to?
Once you have all the parts working you can join them up by using the temperature to decide what position to switch the valve to. That part sounds as if it should be very simple, but there's no point trying to do that until you have the fundamental parts working.