Water Level Control Using PID Function

The Top Water Tank is what the PLC is referring for level, the bottom tank is just a storage container for the water. The goal is to write a code to maintain a set level within the top tank. The code must react to changing conditions, for example, the drain valve being open more or extra water flowing in. You only have 1 input from the tank, the current level