Have a look at my tutorial Tutorial - Advanced automatic light control with flows, it contains all the information you need