Tasmota disconnects and unavailable devices

So I know this is a well discussed topic, but since adding more sonoffs and tuya smartplugs all flashed with Tasmota 8.5 I have been getting lots of device unavailable events, which then turns back to on or off, which depending on the device triggers an event. After reading lots and lots, I thought the solution was to switch to ESPHome, which I did (spent a day doing it) only to find that was worse, and after more reading the underlying cause is anything built after core 2.3 has this problem, but not everyone sees it, and speculation on wifi AP/routers etc can be the contributing factor. Either way, I then went back to all Tasmota 8.5, with less disconnects, I tried flashing down to Tasmota 6.3, but it wouldnt OTA flash and most of the units are sealed and I have already bricked one with all the flashing so dont want to do that. Hence the reason for the post, I am hoping a later version of Tasmota will fix this, in the mean time is there a way in an automation once triggered to have a condition to detect if it had an “unavailable” state say in the last two minutes, then I could safely ignore, I have tried a few things but cant seem to find anyway to get a “if state was X in the previous Y period” condition, anyone got any ideas?

Thanks in advance, Alastair