Sonoff 31 defaults to off position

Read here. You don’t provide any info on what this Sonoff 31 is.

There are at least 2 versions: Wifi and Zigbee, based on a google search. Tell us which one you have and which integration you are using to get it in HA. There are power_on behaviour settings available in both ESPHome (wifi) and ZHA/Z2M (zigbee) which you could use.

Even without the power_on setting, you can write a simple automation when your plug goes from unavailable to off for eg. 5 minutes, then turn on plug.