You can check the next
epoch once the current epoch is 70+% (3.5 days) through, eg:
cardano-cli query leadership-schedule --mainnet ...... --next
You can then:
- Use cron and date checking to run this query every 5 days to coincide with being say 75% through the current epoch, or
- Check chain/epoch details to determine % through the current epoch and then run the query.
Edit - Added details from comment:
Your calc looks ok.
Testnet started epoch 0 at 2019/07/24 20:20:16 UTC according to https://explorer.cardano-testnet.iohkdev.io/en/browse-epochs.html?page=0&perPage=10
Mainnet started at 2017/09/23 21:44:51 UTC