Tasmota Rules: how to turn off relay when mqtt broker not responding?

Hello! for some reason my Rpi3B+ takes couple times to boot correctly when shuts off from the main power (energy shortage for example). So i’m thinking to connect it to a sonoff basic with an internal rule so the Sonoff turn off the relay, wait 10s and turn it on again when the mqtt broker (my HA server) does not respond.

Is this possible?

Any other idea to try this?


The logic should be:

-If mqtt broker doesn't  respond for 10min
      Turn off relay
      Wait 10s
      Turn on the relay

Don’t you risk messing up your SDCard with possible repeated reboots?

Have you considered a UPS or simple USB battery power brick line with you PI controller. I used a power brick for over a year with great results. Would keep my pi up long enough (around 10mins) is there was a brown out.