Scheduler/Helper in 2022.9 release - electricity failure problem

Here in South Africa we are experiencing an unprecedented frequency of “load shedding”, or “power cuts” as they call them in other countries. Power is off for 2 - 4.5 hours every 5 or 6 hours.

My issue - Using the schedule/helper in the latest release, I am finding that the pool pump which I have on the schedule via a Tuya switch via localtuya, is still running long after it was supposed to turn off. I have it scheduled to come on 2 hours 10, 2 and 4pm every day.

The Windows PC I have Home Assistant running virtually on is on an Inverter so runs 24/7 independent to any power cuts as is the network routers, access points etc.

The pool pump I have being switched via a Tuya switch running on localtuya. The pool pump and Tuya switch do not have any sort of back up so when the electricity goes out, they are dead to the world.

My guess is that when the electricity goes off, and the motor is in the ‘on’ cycle, when the electricity comes back on a while later, the switch has not been given the instruction to turn off so the pool pump runs for the duration until the next schedule change. This can mean the pump running for up to 17 hours.

Can anyone suggest a foolproof way that the Tuya switch is turned off when the electricity is restored and it is outside of the scheduled run time? Is there a way to do that?

I currently have the automation running the schedule using ‘toggle’ as having it only using ‘switch on’ the pump was not switching off at the end of the scheduled period.

Not finding any sort of information for the schedule I am not sure if I have it set up correctly or if I have missed the point. From what I read I should not need to have an on schedule and separate off schedule.

Can anyone give me a point in the right direction, or anyone who might have had a similar problem?