Best way to trigger a periodic action when a state is "on" and survive server restart?

Sorry if the title isn’t clear enough. Basically I want to build an automation that uses Gemini AI to detect if my 3D printer is printing spaghetti, like this.

The 3D printer integration (Moonraker) provides a state entity, on which I can create a trigger, and use wait_for_trigger with a timeout to perform a loop action that sends the image to Gemini and stop the print if necessary. However, the problem is that once HA restarts(which I sometimes do), the automation is interrupted.

May I ask for the best way to reliably run an action every 15 minutes regardless of HA restart. I guess it cannot be a loop in an automation.

Thanks!

My naive thought would be to create an automation with a trigger every 15mintues, but only enable it when the print starts. Not sure if there’s other better way.

1 Like

Are you sure the AI will be correct during the first minutes of the print?

You might need to use a time pattern trigger and have the printer state as a condition instead