Turn global switch off at a specific time

I have an Auto Off formula to turn a global switch off at midnight:

$if(df(hh:mma)="12:00AM", 1)$

It seems to work if I am on my phone at midnight, but not if it has been sitting untouched for a few hours. I have KLWP set at Unrestricted battery usage in the background without restrictions.

Any ideas?

For context, I have a daily task list that I want to reset (turn off) daily at midnight to the off positions, and check off (turn on) when tapped.