Switching between power sources- when getting to current threshold
You need a charging controller, not something that turns of the solar panel if it's not significantly higher in output voltage than your 5V battery¹.
So, buy one of these. Texas Instruments has plenty, and they're not the only one. They typically include a step-up converter so that you can charge your battery and supply voltage to your output even if the sun isn't brightest right now, and control circuitry to keep the output voltage stable, no matter whether fed from the battery or the solar panel.
This is what a TI bq25505 circuit would look like:

Notice how there's a boost converter on the solar cell input, so that the battery can always be charged until it's full, and power is drawn either from battery or solar cell (or combination) depending on load, light and charge situation.

If you don't want to charge your battery, then your approach based on current still doesn't work: your Pi defines how much current is drawn, not the sun.
So, you'd want to use a voltage-based switchover (there's really many answers if you search for &quot;switch 5V power source&quot;, I promise), and you still want to add protection to your battery.

¹ there's no chemistry of batteries that does 5V. You're probably confusing &quot;battery&quot; with &quot;USB power bank, which is battery plus charge controller plus step-up converter plus protection circuitry&quot;.