Electric device to prioritize electric input?

I want to charge my UPS (Uninterpreted Power Supply) from solar energy during day and during night i want to charge my ups from grid-power. Is there any device than prioritize one of two electric source? I am planning to connect my solar panels to inverter, this will become power source 1. Grid-power will become... show more I want to charge my UPS (Uninterpreted Power Supply) from solar energy during day and during night i want to charge my ups from grid-power. Is there any device than prioritize one of two electric source?
I am planning to connect my solar panels to inverter, this will become power source 1. Grid-power will become power source 2. I need to connect this to device X which will give priority to power source 1 and if source 1 isn't available, device X will switch on source 2. If both sources are missing my UPS (with battery) will come into action. So is there any device X in market?
2 answers 2