Retrying turn_off/on until executed

Before I go on to writing a blueprint - did anyone write a script yet that turns battery-operated switches on/off but keeps retrying if the devices is temporarily offline?