Scheduler with entity not available

Hello everyone. I don’t know if the problem has already been proposed. I find myself with the scheduler that regulates the irrigation system which, if it finds the entity not available at the time of deactivation, leaves the switch on forever. How can I get around? Thank you