Sonoff mini not always turning on in automation

Hi all. Im using the frontend automation and have an automation that fires when the rear door is opened.

I then have a condition that the sun is below the horizon

then a trigger to turn the entity ON followed by a 5 minute delay then turn entity off.

The automation triggers fine but the light doesnt always turn on.
I havnt flashed the device to esphome.

Im wondering if
a) im using this correctly
and
b) can i check the state of the device and reissue the command in a loop?

Many thanks

Nobody will be able to tell you unless you show the code of your automation.