Need help with plugin creation for a timelapse

Hello everyone

Let me start by saying, i am not a programer ... so i am sorry in adv

i made this python script ( with the help of a LLM) and it works perfectly

The intent is to create a Timelaps option for SLA printers using a LDR.
In the terminal using ´´ python´´ it works perfectly and does what is intended.
The way it works is:

  • LDR is activated by the UV light of the printer
  • UV light turns off and the code waits 5 sec and snaps a pic from the raspberry pi cam and stores it in a specific folder.
  • the code will stop if the LDR is not turned back ON with in 25 sec.
  • When code ends, it ZIP's the folder content and deletes all jpgs and keeps a zip

All works great, however i am trying to implement this script into a octoprint plugin.
The 1st part of the plugin is done:

  • Plugin is creates and install's without any errors and i can see it installed in plugin manager and also my "settings" page (empty for now).

This is my atempt to merge the script into

Aldo i dont have any template gui done, i "think" the plugin should be working on the background. in the logs i have no errors regarding my plugin.

The thing is, when the cicle of the LDR is done it doesn't create any files in the directory and if i reboot the pi then the end of the code runs, it creates a zip but it's empty.

Files GitHub

can any kind soul with "time to spare" help me on this and colaburate ?

kind regards to all

You are invited to upload your files here.

You know how many file servers there are? And for supporters not an easy thing to create an account for all of them and keep track of them.

And in particular: Pastebin is a PITA to read on a large screen. Tiny letters with too much empty space between the lines.

sorry about that
just got home and uploaded all files to github


So it would be a huge help to change any of your print statements to self._logger.debug("this is my message") lines, then in OctoPrint's logging section set your plugin's logging level to debug.


print statements are more for running from the command line in general.

Thank you

i'll give it a try and post the results


Just activated as you sujested and this was the output of the log

2024-02-04 10:56:15,258 - py.warnings - WARNING - /home/pi/oprint/lib/python3.9/site-packages/gpiozero/ PinFactoryFallback: Falling back from lgpio: No module named 'lgpio'

2024-02-04 10:56:40,314 - octoprint.plugins.Sla_Timelapse - DEBUG - Inactive for too long. Ending the script...
2024-02-04 10:56:40,317 - octoprint.plugins.Sla_Timelapse - DEBUG - 
Zipped the contents of /home/pi/timelapse/timelapse_04-02-2024_Job2.
2024-02-04 10:56:40,319 - octoprint.plugins.Sla_Timelapse - DEBUG - The original folder /home/pi/timelapse/timelapse_04-02-2024_Job2 has been deleted.
2024-02-04 10:56:40,320 - octoprint.plugins.Sla_Timelapse - DEBUG - 
Exiting... The script ran for 24.99864387512207 seconds.

the plugin is working however it is not recognizing the GPIO for some reason

full log at github


Ok so when you first setup the script to run prior to converting it to a plugin in assuming there were some pip install commands for required dependencies? Those same friendships need to be installed into OctoPrint's venv.

source ~/oprint/bin/activate
pip install lgpio

The path listed above to activate is where a default OctoPi image has the venv. I'm normal circumstances with a plugin these dependencies would be listed in setup py which you haven't got to yet.

ooooh i see
i will give it a shot

btw - do you know of a "simple" way i can dispay the content of a folder with the zips for download ?
does octoprint allow php code in the template ?

no php support, not natively. there are some things I would change in where you are saving the files to begin with. Instead of self.home_dir = os.path.expanduser('~') you should use self.home_dir = self.get_plugin_data_folder(). this will allow for your timelapses to be backed up as well. The other option would be to just put them in OctoPrint's timelapse folder and use the default file listing available on the timelapse tab with self.home_dir = self._settings.getBaseFolder("timelapse").

If i use timelaspe folder i will have to change all teh code for the zipping and deleting don't i ?

I didn't read the code to actually understand what it's doing but the default timelapse plugin saves individual images into self._settings.getBaseFolder("timelapse_tmp") and then after print completion uses ffmpeg to stitch all the images together. Maybe you do the same with whatever process you are doing and only put the final output in the timelapse folder?

ok quick rundown

the base is

  • take a set of pics
  • when done zip them and delete the original to save space

but i like your idea better but is it possible to get a way of octoprint timelapse be activated by a gpio "short" ... we are talking about resin printers ... because once the uv light goes off it takes about +-5sec for the Z to reach peak before comming back down for the next layer.

because i am not python progremmer ( more like a n00b) there a things i don't get but i am trying to get there.

personally I would probably just make a single file plugin to monitor your "button" for taking a picture and use OctoLapse to do all the work utilizing @OCTOLAPSE TAKE-SNAPSHOT via self._printer.commands(["@OCTOLAPSE TAKE-SNAPSHOT"])

mmm that seems a better idea... let's see if i can pull if off

hello mate...
Sorry for the late reply but it has been a crazy week but i am back... again... with more dumb questions
i have try to make a new plugin but still ... nothing

can you please take a look to my git and seen what i am doing wrong?
Note: this is a mix of "home-made" code, bit's from other exemples and a dab of LLM's and.... lol... doen's work.
It install's, it does show in the plugin manager as Enabled and no error but in the octopring log i have issues with the gpio aldo i have lgpio installed.


Log error:
File "/home/pi/oprint/lib/python3.9/site-packages/octoprint_Sla_Timelapse/", line 10, in on_after_startup
File "/home/pi/oprint/lib/python3.9/site-packages/octoprint_Sla_Timelapse/", line 13, in _setup_gpio
gpio_pin = self._settings.get_int(["gpio_pin"])

Also i hate tryed in a lame way to create a config settings template but also it does not show.
would you give me a had ?

thank you

your plugin implementation doesn't have the settingsPlugin mixin defined, so those callbacks aren't available.



class SnapshotTriggerPlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.SettingsPlugin):

ty for the hint... no i get no errors on the logs however my settings jinga2 is not loading
by looking at the code do you think it could work with octolaps and repect the delay ?
when i activate the gpio i get in the log LDR Activated but that's it ....


you're not binding correctly.

<input type="number" id="gpio_pin" min="0" max="40" step="1" data-bind="value: settings.plugins.Sla_Timelapse.gpio_pin">

but the tab in plugins is not loading