Button to call python methods

I have created some python scripts for my octopi that control different things around my printer, but I wanted to add buttons to the control view to trigger those scripts. When I look at the custom control docs page for octoprint, it shows how to add the buttons but it looks like it's just for gcode commands.

I have created a custom plugin to test, but I can't find a way to add the button in the control page. Does anyone know what I may be missing?

Gcode System Commands plugin. Check this thread.

1 Like

Well I've created my functions and buttons, but for some reason my functions from my js file cannot be found when binding from my jinja2 file.

For some reason I can only run the functions when I place a jquery block directly in my jinja2 file.

If doing it from a plugin you can use getAdditionalControls() callback in the js side to add the buttons for you, or simply update the config.yaml file directly.

https://docs.octoprint.org/en/master/plugins/viewmodels.html#callbacks

The BLTouch plugin uses the callback.

Link to your code would help too.

Another way is sending customized messages back to Python. The common way in octoprint ist using REST. Octoprint itself do the same. Attached is my small pluging which switches my chamber led stripe with using the common mqtt plugin after the messages are back in python.OctoPrint-Chamberlight.zip (10,3 KB)

1 Like