Keep state if unavailable for less than x sec

Hi there. I have some issues with some Sonoff devices connected via cloud through a 4g modem: since this connection is a bit unstable (or, at least, I think this is the cause), my devices go unavailable for about 30seconds every 4/5 minutes. I would like to keep last state if the device is reported unavailable for less than x sec (such as 35). Is there a way to do so? Thank you!