Otherwise, of course I would aim to implement something that closes the position a few seconds before 00:00UTC to narrowly avoid the funding fee.
I am curious how well that would work. All traders have the same incentive as you (close position to avoid paying funding fees), so what usually happens is the price premium (or discount) "prices in" this phenomenon.
For example, longs are about to pay shorts 0.01% at funding time. Since longs want to avoid paying, they close their longs, forcing price down. This forces the funding rate down as mark price drops vs. the index and it makes it unattractive for longs to keep closing.
With really high funding rates it may be worth looking into, although when funding rates are really high that usually implies a strong trend and high volatility which is probably more important to focus on.