I have a 1.14 automatic wheat farm that involves a hopper minecart picking up wheat under a field of villagers. However, I only want to collect the wheat and leave the seeds so that the villagers can collect and replant them. In order to do this, I have one wheat in each slot in the minecart. This system works perfectly and only picks up wheat.
However, now I want to create an automatic unloader. The unloader cannot unload all the items though, as I need all 5 slots filled with some wheat. My plan was to use a detector rail with a comparator and a redstone hopper. This would unload all items down to 22, and then send the minecart on its way. The comparator detection works, but the problem is the detector rail is sending a redstone high to the hopper underneath it, preventing any unloading.
Any suggestions for getting the hopper to unload despite the detector rail above it? Or any alternate design suggestions? Image of a partially working system attached: